custom/plugins/CbaxModulManufacturers/src/Components/ManufacturersHelper.php line 643

Open in your IDE?
  1. <?php declare(strict_types 1);
  2. namespace Cbax\ModulManufacturers\Components;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\Defaults;
  5. use Shopware\Core\Framework\Context;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\MultiFilter;
  10. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  11. use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface;
  12. use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
  13. use Shopware\Core\Content\Product\SalesChannel\Listing\ProductListingLoader;
  14. use Shopware\Core\System\SystemConfig\SystemConfigService;
  15. use Shopware\Core\Framework\DataAbstractionLayer\Search\EntitySearchResult;
  16. use Shopware\Core\Content\Cms\CmsPageEntity;
  17. use Shopware\Core\Content\Cms\DataResolver\CmsSlotsDataResolver;
  18. use Shopware\Core\Content\Cms\DataResolver\ResolverContext\ResolverContext;
  19. use Shopware\Core\Content\Cms\Aggregate\CmsSection\CmsSectionCollection;
  20. use Shopware\Core\Framework\Uuid\Uuid;
  21. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  22. use Cbax\ModulManufacturers\Core\Content\Events\CbaxManufacturersProductListingCriteriaEvent;
  23. class ManufacturersHelper
  24. {
  25.     /**
  26.      * @var SystemConfigService
  27.      */
  28.     private $systemConfigService;
  29.     /**
  30.      * @var Connection
  31.      */
  32.     private $connection;
  33.     /**
  34.      * @var SalesChannelRepositoryInterface
  35.      */
  36.     private $productRepository;
  37.     /**
  38.      * @var EntityRepositoryInterface
  39.      */
  40.     private $manufacturerRepository;
  41.     /**
  42.      * @var EntityRepositoryInterface
  43.      */
  44.     private $cmsPageRepository;
  45.     /**
  46.      * @var CmsSlotsDataResolver
  47.      */
  48.     private $slotDataResolver;
  49.     /**
  50.      * @var ProductListingLoader
  51.      */
  52.     private $listingLoader;
  53.     /**
  54.      * @var EventDispatcherInterface
  55.      */
  56.     private $eventDispatcher;
  57.     public function __construct(
  58.             SystemConfigService $systemConfigService,
  59.             Connection $connection,
  60.             SalesChannelRepositoryInterface $productRepository,
  61.             EntityRepositoryInterface $manufacturerRepository,
  62.             EntityRepositoryInterface $cmsPageRepository,
  63.             CmsSlotsDataResolver $slotDataResolver,
  64.             ProductListingLoader $listingLoader,
  65.             EventDispatcherInterface $eventDispatcher
  66.             )
  67.     {
  68.         $this->connection $connection;
  69.         $this->systemConfigService $systemConfigService;
  70.         $this->productRepository $productRepository;
  71.         $this->manufacturerRepository $manufacturerRepository;
  72.         $this->cmsPageRepository $cmsPageRepository;
  73.         $this->slotDataResolver $slotDataResolver;
  74.         $this->listingLoader $listingLoader;
  75.         $this->eventDispatcher $eventDispatcher;
  76.     }
  77.     /**
  78.      * weitere allgemeine Templatedaten ermitteln, aktuell Top Hersteller
  79.      * @param $unsortedData array Liste von Herstellern
  80.      * @param $config array
  81.      * @return array Top Hersteller
  82.      */
  83.     public function getTemplateData($unsortedData$config)
  84.     {
  85.         $result['premiums'] = array();
  86.         foreach ($unsortedData as $manufacturer)
  87.         {
  88.             if (!empty($manufacturer->countArticle) || $config['displayFilter'] === 'showAll')
  89.             {
  90.                 $customFields $manufacturer->get('translated')['customFields'];
  91.                 if (!empty($customFields['cbaxManufacturerPremium']) && empty($customFields['cbaxManufacturerIsHidden']))
  92.                 {
  93.                     array_push($result['premiums'], $manufacturer);
  94.                 }
  95.             }
  96.         }
  97.         return $result;
  98.     }
  99.     /** Daten für Slider in Product Detail Page
  100.      * @param $manufacturerId
  101.      * @param $categoryId
  102.      * @param $salesChannelContext
  103.      * @return mixed
  104.      * @throws \Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException
  105.      */
  106.     public function getProductsByManufacturer($manufacturerId$categoryId$salesChannelContext$sorting$limit$currentProductId null)
  107.     {
  108.         $salesChannelId $salesChannelContext->getSalesChannel()->get('id');
  109.         $hideCloseoutProductsWhenOutOfStock $this->systemConfigService->get("core.listing.hideCloseoutProductsWhenOutOfStock"$salesChannelId);
  110.         $qb $this->connection->createQueryBuilder();
  111.         $query $qb
  112.             ->select([
  113.                 '`product`.id as id'
  114.             ])
  115.             ->from('`product`''`product`')
  116.             ->innerJoin('`product`''product_visibility''visibilities',
  117.                 'product.visibilities = visibilities.product_id AND
  118.                 visibilities.sales_channel_id = UNHEX(:salesChannelId) AND
  119.                 visibilities.product_version_id = :versionId')
  120.             ->andWhere('visibilities.visibility = 30')
  121.             ->andWhere('`product`.version_id = :versionId')
  122.             ->andWhere('`product`.active = 1')
  123.             ->andWhere('`product`.parent_id IS NULL')
  124.             ->andWhere('`product`.product_manufacturer_id = UNHEX(:manufacturerId)')
  125.             ->setParameter('manufacturerId'$manufacturerId)
  126.             ->setParameter('salesChannelId'$salesChannelId)
  127.             ->setParameter('versionId'Uuid::fromHexToBytes(Defaults::LIVE_VERSION));
  128.         if ($hideCloseoutProductsWhenOutOfStock == true)
  129.         {
  130.             $query->andWhere('(
  131.                                 (`product`.is_closeout != 1 OR `product`.available = 1)
  132.                                 OR (
  133.                                     `product`.child_count > 0
  134.                                     AND
  135.                                     EXISTS
  136.                                         (SELECT prod2.id FROM `product` AS prod2 WHERE prod2.parent_id=`product`.id
  137.                                             AND prod2.version_id = :versionId
  138.                                             AND (IFNULL(prod2.is_closeout,`product`.is_closeout) != 1 OR prod2.available = 1)
  139.                                         )
  140.                                     )
  141.                                 )');
  142.         }
  143.         $productsResult $query->execute()->fetchAll();
  144.         $productsIds = [];
  145.         if (!empty($productsResult))
  146.         {
  147.             foreach ($productsResult as $product)
  148.             {
  149.                 if ($this->convertId($product['id']) == $currentProductId) {
  150.                     continue;
  151.                 }
  152.                 $productsIds[] = $this->convertId($product['id']);
  153.             }
  154.         } else {
  155.             return $productsIds;
  156.         }
  157.         $criteria = new Criteria();
  158.         $criteria->addFilter(new EqualsAnyFilter('id'$productsIds));
  159.         if ($categoryId)
  160.         {
  161.             $criteria->addAssociation('categories');
  162.             $criteria->addFilter(new EqualsFilter('categories.id'$categoryId));
  163.         }
  164.         if ($sorting == 'name_asc')
  165.         {
  166.             $criteria->addSorting(new FieldSorting('name'FieldSorting::ASCENDING));
  167.         }
  168.         elseif ($sorting == 'name_desc')
  169.         {
  170.                 $criteria->addSorting(new FieldSorting('name'FieldSorting::DESCENDING));
  171.         }
  172.         elseif ($sorting == 'date_asc')
  173.         {
  174.                 $criteria->addSorting(new FieldSorting('releaseDate'FieldSorting::ASCENDING));
  175.         }
  176.         elseif ($sorting == 'date_desc')
  177.         {
  178.                 $criteria->addSorting(new FieldSorting('releaseDate'FieldSorting::DESCENDING));
  179.         }
  180.         elseif ($sorting == 'price_asc')
  181.         {
  182.                 $criteria->addSorting(new FieldSorting('cheapestPrice'FieldSorting::ASCENDING));
  183.         }
  184.         elseif ($sorting == 'price_desc')
  185.         {
  186.                 $criteria->addSorting(new FieldSorting('cheapestPrice'FieldSorting::DESCENDING));
  187.         }
  188.         if ($limit >= 0)
  189.         {
  190.                 $criteria->setLimit($limit);
  191.         }
  192.         $searchResult $this->productRepository->search($criteria$salesChannelContext);
  193.         $products $searchResult->getElements();
  194.         return $products;
  195.     }
  196.     /** Daten für Slider in Product Detail Page
  197.      * @param $manufacturerId
  198.      * @param $salesChannelContext
  199.      * @return mixed
  200.      * @throws \Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException
  201.      */
  202.     public function getManufacturerById($manufacturerId$salesChannelContext)
  203.     {
  204.         $criteria = new Criteria();
  205.         $criteria->addFilter(new EqualsFilter('id'$manufacturerId));
  206.         $criteria->addAssociation('media');
  207.         $searchResult $this->manufacturerRepository->search($criteria$salesChannelContext->getContext());
  208.         $manufacturer $searchResult->getElements();
  209.         return $manufacturer;
  210.     }
  211.     /** Daten für Hersteller detail und index pages
  212.      * @param $showProductCount bool
  213.      * @param $config array
  214.      * @param $salesChannelId string
  215.      * @param $context Context
  216.      * @return array sorted manufacturers
  217.      * @throws \Exception
  218.      */
  219.     public function getManufacturerByChar($showProductCount$config$salesChannelId$context$overviewPage false)
  220.     {
  221.         $criteria = new Criteria();
  222.         $criteria->addSorting(new FieldSorting('name'));
  223.         if ($overviewPage) {
  224.             $criteria->addAssociation('media');
  225.         }
  226.         $manufacturers $this->manufacturerRepository->search($criteria$context)->getElements();
  227.         foreach ($manufacturers as &$item)
  228.         {
  229.             $item->countArticle 0;
  230.         }
  231.         unset($item);
  232.         $hideCloseoutProductsWhenOutOfStock $this->systemConfigService->get("core.listing.hideCloseoutProductsWhenOutOfStock"$salesChannelId);
  233.         $qb $this->connection->createQueryBuilder();
  234.         $query $qb
  235.             ->select([
  236.                 'COUNT(`product`.id) as count',
  237.                 'LOWER(HEX(`product`.product_manufacturer_id)) as manufacturerId'
  238.             ])
  239.             ->from('`product`''`product`')
  240.             ->innerJoin('`product`''product_visibility''visibilities',
  241.                 'product.visibilities = visibilities.product_id AND
  242.                 visibilities.sales_channel_id = :salesChannelId AND
  243.                 visibilities.product_version_id = :versionId')
  244.             ->andWhere('`product`.version_id = :versionId')
  245.             ->andWhere('visibilities.visibility = 30')
  246.             ->andWhere('`product`.active = 1')
  247.             ->andWhere('`product`.parent_id IS NULL')
  248.             ->andWhere('`product`.product_manufacturer_id IS NOT NULL')
  249.             ->setParameter('versionId'Uuid::fromHexToBytes(Defaults::LIVE_VERSION))
  250.             ->setParameter('salesChannelId'Uuid::fromHexToBytes($salesChannelId))
  251.             ->groupBy('manufacturerId');
  252.         if ($hideCloseoutProductsWhenOutOfStock == true)
  253.         {
  254.             $query->andWhere('(
  255.                                 (`product`.is_closeout != 1 OR `product`.available = 1)
  256.                                 OR (
  257.                                     `product`.child_count > 0
  258.                                     AND
  259.                                     EXISTS
  260.                                         (SELECT prod2.id FROM `product` AS prod2 WHERE prod2.parent_id=`product`.id
  261.                                             AND prod2.version_id = :versionId
  262.                                             AND (IFNULL(prod2.is_closeout,`product`.is_closeout) != 1 OR prod2.available = 1)
  263.                                         )
  264.                                     )
  265.                                 )');
  266.         }
  267.         $productsResult $query->execute()->fetchAll();
  268.         foreach ($productsResult as $item)
  269.         {
  270.             if (!empty($manufacturers[$item['manufacturerId']]))
  271.             {
  272.                 $manufacturers[$item['manufacturerId']]->countArticle $item['count'];
  273.             }
  274.         }
  275.         $letters = array('A''B''C''D''E''F''G''H''I''J''K''L''M''N''O''P''Q''R''S''T''U''V''W''X''Y''Z');
  276.         $sortedManufacturers = array('letters' => array());
  277.         foreach ($manufacturers as $manufacturer) {
  278.             // Hersteller, die ausgeblendet werden sollen überspringen
  279.             if (!empty($manufacturer->getTranslated()['customFields']['cbaxManufacturerIsHidden'])) {
  280.                 continue;
  281.             }
  282.             if (!($config['displayFilter'] === 'showAll') && empty($manufacturer->countArticle)) {
  283.                 continue;
  284.             }
  285.             //alte Version, Umlaute in #
  286.             //$letter = ucfirst(substr($manufacturer->getTranslated()['name'], 0, 1));
  287.             //neue Version, Ä->A, ...
  288.             //zuerst Umlaute umwandeln, sonst Probleme
  289.             $changedName strtr($manufacturer->getTranslated()['name'],['Ä'=>'A','ä'=>'a','Ü'=>'u','ü'=>'u','Ö'=>'o','ö'=>'o']);
  290.             $letter ucfirst(substr($changedName01));
  291.             // prüfen ob das erste Zeichen bereits in der Liste existiert und ggf. initiales leeres Array anlegen
  292.             if (empty($sortedManufacturers['letters'][$letter]) && in_array($letter$letters)) {
  293.                 $sortedManufacturers['letters'][$letter] = array();
  294.             } elseif (!in_array($letter$letters)) {
  295.                 // Zeichen, die nicht in $letters enthalten sind unter '#' zusammenfassen
  296.                 if (!isset($sortedManufacturers['letters']['#'])) {
  297.                     $sortedManufacturers['letters']['#'] = array();
  298.                 }
  299.                 $letter '#';
  300.             }
  301.             array_push($sortedManufacturers['letters'][$letter], $manufacturer);
  302.         }
  303.         ksort($sortedManufacturers['letters']);
  304.         $result = array ();
  305.         // Eintrag für Sonderzeichen anlegen
  306.         if (!empty($sortedManufacturers['letters']['#'])) {
  307.             $res0 $sortedManufacturers['letters']['#'];
  308.         } else {
  309.             $res0 = array();
  310.         }
  311.         $countRes0 0;
  312.         foreach ($res0 as $manuf) {
  313.             // alle Produkte des Buchstaben
  314.             $countRes0 += $manuf->countArticle;
  315.         }
  316.         $result[0] = array(
  317.             'char' => '#',
  318.             'active' => (count($res0) > 0),
  319.             'countManufacturer' => count($res0),
  320.             'countArticle' => $countRes0,
  321.             'items' => $res0
  322.         );
  323.         // Einträge für $letters anlegen
  324.         foreach ($letters as $letter) {
  325.             if (!empty($sortedManufacturers['letters'][$letter])) {
  326.                 $res $sortedManufacturers['letters'][$letter];
  327.                 $count 0;
  328.                 foreach ($res as $manuf) {
  329.                     $count += $manuf->countArticle;
  330.                 }
  331.                 array_push($result, array(
  332.                     'char'          => $letter,
  333.                     'active'        => (count($res) > 0),
  334.                     'countManufacturer' => count($res),
  335.                     'countArticle'  => $count,
  336.                     'items'         => $res,
  337.                 ));
  338.             } else {
  339.                 array_push($result, array(
  340.                     'char' => $letter,
  341.                     'active' => false,
  342.                     'countManufacturer' => 0,
  343.                     'countArticle'  => 0,
  344.                     'items'         => array()
  345.                 ));
  346.             }
  347.         }
  348.         if ($overviewPage) {
  349.             //overview page
  350.             return [
  351.                 'sortedData' => $result,
  352.                 'unsortedData' => $manufacturers
  353.             ];
  354.         }
  355.         //detail page
  356.         return $result;
  357.     }
  358.     public function convertId($value)
  359.     {
  360.         $newValue null;
  361.         try {
  362.             $newValue Uuid::fromBytesToHex($value);
  363.         } catch (\Exception $e) {
  364.             // use if needed
  365.         }
  366.         return $newValue;
  367.     }
  368.     public function getCmsPage($id$context)
  369.     {
  370.         $criteria = new Criteria();
  371.         $criteria->addFilter(new EqualsFilter('id'$id));
  372.         $criteria->addAssociation('sections');
  373.         $criteria->addAssociation('sections.blocks');
  374.         $criteria
  375.             ->getAssociation('sections')
  376.             ->addAssociation('backgroundMedia');
  377.         $criteria
  378.             ->getAssociation('sections.blocks')
  379.             ->addAssociation('backgroundMedia')
  380.             ->addAssociation('slots');
  381.         $searchResult $this->cmsPageRepository->search($criteria$context);
  382.         $cmsPage $searchResult->first();
  383.         return $cmsPage;
  384.     }
  385.     public function loadSlotData(CmsPageEntity $pageResolverContext $resolverContext): void
  386.     {
  387.         $slots $this->slotDataResolver->resolve($page->getSections()->getBlocks()->getSlots(), $resolverContext);
  388.         $page->getSections()->getBlocks()->setSlots($slots);
  389.     }
  390.     public function filterEmptyCmsBlocksDetail($page$cbaxModulManufacturers)
  391.     {
  392.         $cmsPage $page->getCmsPage();
  393.         if (empty($cmsPage)) {
  394.             return $page;
  395.         }
  396.         $cmsSectionCollection = new CmsSectionCollection();
  397.         foreach ($cmsPage->getSections() as $section) {
  398.             $newBlocksCollection $section->getBlocks();
  399.             foreach ($section->getBlocks() as $block) {
  400.                 //Banner Block
  401.                 if ($block->getType() === 'cbax-manufacturers-banner') {
  402.                     $slot $block->getSlots()->first();
  403.                     if ($slot->getType() === 'cbax-manufacturers-banner' &&
  404.                         empty($cbaxModulManufacturers['bannerMedia']) &&
  405.                         (empty($slot->getConfig()) ||
  406.                             (!empty($slot->getConfig()) &&
  407.                                 empty($slot->getConfig()['altUrl']['value'])
  408.                             )
  409.                         )
  410.                     )
  411.                     {
  412.                         $newBlocksCollection->filterAndReduceByProperty('id'$block->getId());
  413.                     }
  414.                 } //Cbax Image-Text Block
  415.                 elseif ($block->getType() === 'cbax-manufacturers-image-text') {
  416.                     $imageIsEmpty false;
  417.                     $textIsEmpty false;
  418.                     foreach ($block->getSlots() as $slot) {
  419.                         if ($slot->getType() === 'image' &&
  420.                             empty($cbaxModulManufacturers['manufacturer']->getMedia()) &&
  421.                             (empty($slot->getConfig()) ||
  422.                                 (!empty($slot->getConfig()) &&
  423.                                     $slot->getConfig()['media']['source'] === 'mapped' &&
  424.                                     $slot->getConfig()['media']['value'] === 'product_manufacturer.media'
  425.                                 )
  426.                             )
  427.                         )
  428.                         {
  429.                             $imageIsEmpty true;
  430.                         }
  431.                         if ($slot->getType() === 'text' && empty($slot->getConfig()))
  432.                         {
  433.                             $textIsEmpty true;
  434.                         }
  435.                         if ($slot->getType() === 'text' &&
  436.                             !empty($slot->getConfig()) &&
  437.                             !empty($slot->getConfig()['content']) &&
  438.                             $slot->getConfig()['content']['source'] === 'mapped'
  439.                         )
  440.                         {
  441.                             $propertyArray explode('.'$slot->getConfig()['content']['value']);
  442.                             if (!empty($propertyArray)) {
  443.                                 $property end($propertyArray);
  444.                                 if ($property && !in_array('customFields'$propertyArray) &&
  445.                                     empty($cbaxModulManufacturers['manufacturer']->getTranslated()[$property])
  446.                                 )
  447.                                 {
  448.                                     $textIsEmpty true;
  449.                                 } elseif ($property &&
  450.                                     in_array('customFields'$propertyArray) &&
  451.                                     (empty($cbaxModulManufacturers['manufacturer']->getTranslated()['customFields']) ||
  452.                                         (!empty($cbaxModulManufacturers['manufacturer']->getTranslated()['customFields']) &&
  453.                                             empty($cbaxModulManufacturers['manufacturer']->getTranslated()['customFields'][$property])
  454.                                         )
  455.                                     )
  456.                                 )
  457.                                 {
  458.                                     $textIsEmpty true;
  459.                                 }
  460.                             }
  461.                         }
  462.                     }
  463.                     $blockIsEmpty $imageIsEmpty && $textIsEmpty;
  464.                     if ($blockIsEmpty) {
  465.                         $newBlocksCollection->filterAndReduceByProperty('id'$block->getId());
  466.                     }
  467.                 }
  468.             }
  469.             $section->setBlocks($newBlocksCollection);
  470.             $cmsSectionCollection->add($section);
  471.         }
  472.         $cmsPage->setSections($cmsSectionCollection);
  473.         $page->setCmsPage($cmsPage);
  474.         return $page;
  475.     }
  476.     public function filterEmptyCmsBlocksIndex($page$cbaxModulManufacturers)
  477.     {
  478.         $cmsPage $page->getCmsPage();
  479.         if (empty($cmsPage)) {
  480.             return $page;
  481.         }
  482.         $cmsSectionCollection = new CmsSectionCollection();
  483.         foreach ($cmsPage->getSections() as $section) {
  484.             $newBlocksCollection $section->getBlocks();
  485.             foreach ($section->getBlocks() as $block) {
  486.                 //Image Banner Block
  487.                 if ($block->getType() === 'image-cover' || $block->getType() === 'image') {
  488.                     $slot $block->getSlots()->first();
  489.                     if ($slot->getType() === 'image' &&
  490.                         (empty($slot->getConfig()) ||
  491.                             (!empty($slot->getConfig()) &&
  492.                                 !empty($slot->getConfig()['media']) &&
  493.                                 empty($slot->getConfig()['media']['value'])
  494.                             )
  495.                         )
  496.                     )
  497.                     {
  498.                         $newBlocksCollection->filterAndReduceByProperty('id'$block->getId());
  499.                     }
  500.                 } //Text Block
  501.                 elseif ($block->getType() === 'text') {
  502.                     $slot $block->getSlots()->first();
  503.                     if ($slot->getType() === 'text' &&
  504.                         (empty($slot->getConfig()) ||
  505.                             (!empty($slot->getConfig()) &&
  506.                                 !empty($slot->getConfig()['content']) &&
  507.                                 empty($slot->getConfig()['content']['value'])
  508.                             )
  509.                         )
  510.                     )
  511.                     {
  512.                         $newBlocksCollection->filterAndReduceByProperty('id'$block->getId());
  513.                     }
  514.                 } // Top Slider
  515.                 elseif ($block->getType() === 'cbax-manufacturers-topslider') {
  516.                     $slot $block->getSlots()->first();
  517.                     if ($slot->getType() === 'cbax-manufacturers-topslider' &&
  518.                         empty($cbaxModulManufacturers['templateData']['premiums']))
  519.                     {
  520.                         $newBlocksCollection->filterAndReduceByProperty('id'$block->getId());
  521.                     }
  522.                 }
  523.             }
  524.             $section->setBlocks($newBlocksCollection);
  525.             $cmsSectionCollection->add($section);
  526.         }
  527.         $cmsPage->setSections($cmsSectionCollection);
  528.         $page->setCmsPage($cmsPage);
  529.         return $page;
  530.     }
  531.     // daten für Hersteller Detail page
  532.     public function getProductsListing($manufacturerId$pageNumber$salesChannelContext): EntitySearchResult
  533.     {
  534.         $criteria = new Criteria();
  535.         $criteria->addAssociation('cover');
  536.         $criteria->addAssociation('prices');
  537.         $criteria->addAssociation('unit');
  538.         $criteria->addAssociation('deliveryTime');
  539.         $criteria->addAssociation('visibilities');
  540.         $criteria->addFilter(new EqualsFilter('manufacturerId'$manufacturerId));
  541.         $saleschannelId $salesChannelContext->getSalesChannel()->getId();
  542.         $criteria->addFilter(new MultiFilter(
  543.             MultiFilter::CONNECTION_AND,
  544.             [
  545.                 new EqualsFilter('visibilities.visibility'30),
  546.                 new EqualsFilter('visibilities.salesChannelId'$saleschannelId)
  547.             ]
  548.         ));
  549.         // Sortierung der Produkte nach Namen
  550.         $criteria->addSorting(new FieldSorting('name'));
  551.         // Pagenierung
  552.         $limit $this->systemConfigService->get("core.listing.productsPerPage"$saleschannelId);
  553.         $limit = !empty($limit) ? (int)$limit 20;
  554.         $criteria->setLimit($limit);
  555.         // Offset für Pagenierung ermitteln
  556.         if ($pageNumber 0) {
  557.             $offset $limit * ($pageNumber -1);
  558.             $criteria->setOffset($offset);
  559.         }
  560.         // Pagenierung aktivieren
  561.         $criteria->setTotalCountMode(1);
  562.         $event $this->eventDispatcher->dispatch(new CbaxManufacturersProductListingCriteriaEvent($criteria$manufacturerId));
  563.         $criteria $event->getCriteria();
  564.         $result $this->listingLoader->load($criteria$salesChannelContext);
  565.         return $result;
  566.     }
  567. }