custom/plugins/b2bsellerscore/src/Components/Category/SalesChannel/CategoryRouteDecorator.php line 40

Open in your IDE?
  1. <?php
  2. namespace B2bSellersCore\Components\Category\SalesChannel;
  3. use Shopware\Core\Content\Category\SalesChannel\AbstractCategoryRoute;
  4. use Shopware\Core\Content\Category\SalesChannel\CategoryRouteResponse;
  5. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  7. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. /**
  11.  * @Route(defaults={"_routeScope"={"store-api"}})
  12.  */
  13. class CategoryRouteDecorator extends AbstractCategoryRoute
  14. {
  15.     public const LISTING_PROPERTY_GROUPS_FIELD 'b2b_table_listing_property_group_ids';
  16.     private AbstractCategoryRoute $decorated;
  17.     private EntityRepositoryInterface $propertyGroupRepository;
  18.     public function __construct(
  19.         AbstractCategoryRoute     $decorated,
  20.         EntityRepositoryInterface $propertyGroupRepository
  21.     )
  22.     {
  23.         $this->decorated $decorated;
  24.         $this->propertyGroupRepository $propertyGroupRepository;
  25.     }
  26.     public function getDecorated(): AbstractCategoryRoute
  27.     {
  28.         return $this->decorated;
  29.     }
  30.     /**
  31.      * @Route("/store-api/category/{navigationId}", name="store-api.category.detail", methods={"GET","POST"})
  32.      */
  33.     public function load(string $navigationIdRequest $requestSalesChannelContext $context): CategoryRouteResponse
  34.     {
  35.         $result $this->decorated->load($navigationId$request$context);
  36.         $category $result->getCategory();
  37.         $customFields $category->getCustomFields();
  38.         if (!$category->getCmsPage()) {
  39.             return $result;
  40.         }
  41.         $category->getCmsPage()->addExtension('category', clone $category);
  42.         if (!isset($customFields[self::LISTING_PROPERTY_GROUPS_FIELD]) || empty($customFields[self::LISTING_PROPERTY_GROUPS_FIELD])) {
  43.             return $result;
  44.         }
  45.         $ids $customFields[self::LISTING_PROPERTY_GROUPS_FIELD];
  46.         $propertyGroups $this->propertyGroupRepository->search(new Criteria($ids), $context->getContext());
  47.         $category->getCmsPage()->addExtension('listingTablePropertyGroups'$propertyGroups->getEntities());
  48.         return $result;
  49.     }
  50. }