vendor/shopware/storefront/Page/Product/ProductLoader.php line 58

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Page\Product;
  3. use Shopware\Core\Content\Product\SalesChannel\Detail\AbstractProductDetailRoute;
  4. use Shopware\Core\Content\Product\SalesChannel\SalesChannelProductEntity;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
  7. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  8. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  9. use Symfony\Component\HttpFoundation\Request;
  10. /**
  11.  * @deprecated tag:v6.4.0 - Use \Shopware\Core\Content\Product\SalesChannel\Detail\ProductDetailRoute instead
  12.  */
  13. class ProductLoader
  14. {
  15.     /**
  16.      * @var EventDispatcherInterface
  17.      */
  18.     private $eventDispatcher;
  19.     /**
  20.      * @var AbstractProductDetailRoute
  21.      */
  22.     private $productRoute;
  23.     public function __construct(
  24.         AbstractProductDetailRoute $productRoute,
  25.         EventDispatcherInterface $eventDispatcher
  26.     ) {
  27.         $this->eventDispatcher $eventDispatcher;
  28.         $this->productRoute $productRoute;
  29.     }
  30.     public function load(string $productIdSalesChannelContext $salesChannelContext, ?string $event null): SalesChannelProductEntity
  31.     {
  32.         $criteria = (new Criteria())
  33.             ->addAssociation('manufacturer.media')
  34.             ->addAssociation('options.group')
  35.             ->addAssociation('properties.group')
  36.             ->addAssociation('mainCategories.category');
  37.         $criteria
  38.             ->getAssociation('media')
  39.             ->addSorting(new FieldSorting('position'));
  40.         $this->eventDispatcher->dispatch(
  41.             new ProductLoaderCriteriaEvent($criteria$salesChannelContext)
  42.         );
  43.         if ($event) {
  44.             // @deprecated tag:v6.4.0 - `ProductPageCriteriaEvent` or `MinimalQuickViewPageCriteriaEvent` will be dispatched in corresponding page loader classes
  45.             $instance = new $event($productId$criteria$salesChannelContext);
  46.             $this->eventDispatcher->dispatch($instance);
  47.         }
  48.         $result $this->productRoute->load($productId, new Request(), $salesChannelContext$criteria);
  49.         $result->getProduct()->setConfigurator(
  50.             $result->getConfigurator()
  51.         );
  52.         return $result->getProduct();
  53.     }
  54. }