vendor/store.shopware.com/cbaxmodulmanufacturers/src/Components/ManufacturersHelper.php line 594

Open in your IDE?
  1. <?php declare(strict_types 1);
  2. namespace Cbax\ModulManufacturers\Components;
  3. use Shopware\Core\Framework\Context;
  4. use Shopware\Core\Defaults;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Core\Content\Product\SalesChannel\ProductAvailableFilter;
  7. use Shopware\Core\Content\Product\SalesChannel\ProductCloseoutFilter;
  8. use Shopware\Core\Content\Product\Aggregate\ProductVisibility\ProductVisibilityDefinition;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  10. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  11. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\MultiFilter;
  12. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\NotFilter;
  13. use Shopware\Core\Framework\DataAbstractionLayer\Search\Aggregation\Bucket\FilterAggregation;
  14. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\RangeFilter;
  15. use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface;
  16. use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
  17. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  18. use Shopware\Core\Content\Product\SalesChannel\Listing\ProductListingLoader;
  19. use Shopware\Core\System\SystemConfig\SystemConfigService;
  20. use Shopware\Core\Framework\DataAbstractionLayer\Search\EntitySearchResult;
  21. use Shopware\Core\Framework\DataAbstractionLayer\Search\AggregationResult\Bucket\TermsResult;
  22. use Shopware\Core\Framework\DataAbstractionLayer\Search\Aggregation\Bucket\TermsAggregation;
  23. use Shopware\Core\Content\Cms\CmsPageEntity;
  24. use Shopware\Core\Content\Cms\DataResolver\CmsSlotsDataResolver;
  25. use Shopware\Core\Content\Cms\DataResolver\ResolverContext\ResolverContext;
  26. use Shopware\Core\Content\Cms\Aggregate\CmsSection\CmsSectionCollection;
  27. use Shopware\Core\System\SalesChannel\Context\AbstractSalesChannelContextFactory;
  28. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  29. use Cbax\ModulManufacturers\Core\Content\Events\CbaxManufacturersProductListingCriteriaEvent;
  30. class ManufacturersHelper
  31. {
  32.     /**
  33.      * @var SystemConfigService
  34.      */
  35.     private $systemConfigService;
  36.     /**
  37.      * @var SalesChannelRepositoryInterface
  38.      */
  39.     private $productRepository;
  40.     /**
  41.      * @var EntityRepositoryInterface
  42.      */
  43.     private $manufacturerRepository;
  44.     /**
  45.      * @var EntityRepositoryInterface
  46.      */
  47.     private $salesChannelRepository;
  48.     /**
  49.      * @var EntityRepositoryInterface
  50.      */
  51.     private $cmsPageRepository;
  52.     /**
  53.      * @var AbstractSalesChannelContextFactory
  54.      */
  55.     private $salesChannelContextFactory;
  56.     /**
  57.      * @var CmsSlotsDataResolver
  58.      */
  59.     private $slotDataResolver;
  60.     /**
  61.      * @var ProductListingLoader
  62.      */
  63.     private $listingLoader;
  64.     /**
  65.      * @var EventDispatcherInterface
  66.      */
  67.     private $eventDispatcher;
  68.     public function __construct(
  69.             SystemConfigService $systemConfigService,
  70.             SalesChannelRepositoryInterface $productRepository,
  71.             EntityRepositoryInterface $manufacturerRepository,
  72.             EntityRepositoryInterface $salesChannelRepository,
  73.             EntityRepositoryInterface $cmsPageRepository,
  74.             CmsSlotsDataResolver $slotDataResolver,
  75.             ProductListingLoader $listingLoader,
  76.             EventDispatcherInterface $eventDispatcher,
  77.             AbstractSalesChannelContextFactory $salesChannelContextFactory
  78.     ) {
  79.         $this->systemConfigService $systemConfigService;
  80.         $this->productRepository $productRepository;
  81.         $this->manufacturerRepository $manufacturerRepository;
  82.         $this->cmsPageRepository $cmsPageRepository;
  83.         $this->slotDataResolver $slotDataResolver;
  84.         $this->listingLoader $listingLoader;
  85.         $this->eventDispatcher $eventDispatcher;
  86.         $this->salesChannelRepository $salesChannelRepository;
  87.         $this->salesChannelContextFactory $salesChannelContextFactory;
  88.     }
  89.     /**
  90.      * weitere allgemeine Templatedaten ermitteln, aktuell Top Hersteller
  91.      * @param $unsortedData array Liste von Herstellern
  92.      * @param $config array
  93.      * @return array Top Hersteller
  94.      */
  95.     public function getTemplateData($unsortedData$config)
  96.     {
  97.         $result['premiums'] = array();
  98.         foreach ($unsortedData as $manufacturer) {
  99.             if (!empty($manufacturer->countArticle) ||
  100.                 $config['displayFilter'] === 'showAll'
  101.             ) {
  102.                 $customFields $manufacturer->get('translated')['customFields'];
  103.                 if (!empty($customFields['cbaxManufacturerPremium']) &&
  104.                     empty($customFields['cbaxManufacturerIsHidden'])
  105.                 ) {
  106.                     array_push($result['premiums'], $manufacturer);
  107.                 }
  108.             }
  109.         }
  110.         return $result;
  111.     }
  112.     /** Daten für Slider in Product Detail Page
  113.      * @param $manufacturerId string
  114.      * @param $categoryId string|null
  115.      * @param $salesChannelContext SalesChannelContext
  116.      * @param $currentProductId string|null
  117.      * @return mixed
  118.      * @throws \Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException
  119.      */
  120.     public function getProductsByManufacturer($manufacturerId$categoryId$salesChannelContext$sorting$limit$currentProductId null)
  121.     {
  122.         $salesChannelId $salesChannelContext->getSalesChannel()->get('id');
  123.         $hide $this->systemConfigService->getBool("core.listing.hideCloseoutProductsWhenOutOfStock"$salesChannelId);
  124.         $criteria = new Criteria();
  125.         $criteria->addFilter(new EqualsFilter('manufacturerId'$manufacturerId));
  126.         $criteria->addFilter(new EqualsFilter('parentId'null));
  127.         if (!empty($currentProductId)) {
  128.             $criteria->addFilter(new NotFilter(
  129.                 NotFilter::CONNECTION_OR,
  130.                 [
  131.                     new EqualsFilter('id'$currentProductId)
  132.                 ]
  133.             ));
  134.         }
  135.         $criteria->addFilter(
  136.             new ProductAvailableFilter($salesChannelIdProductVisibilityDefinition::VISIBILITY_ALL)
  137.         );
  138.         if ($hide) {
  139.             $criteria->addFilter(new ProductCloseoutFilter());
  140.         }
  141.         if (!empty($categoryId)) {
  142.             $criteria->addAssociation('categories');
  143.             $criteria->addFilter(new EqualsFilter('categories.id'$categoryId));
  144.         }
  145.         if ($sorting == 'name_asc')
  146.         {
  147.             $criteria->addSorting(new FieldSorting('name'FieldSorting::ASCENDING));
  148.         }
  149.         elseif ($sorting == 'name_desc')
  150.         {
  151.             $criteria->addSorting(new FieldSorting('name'FieldSorting::DESCENDING));
  152.         }
  153.         elseif ($sorting == 'date_asc')
  154.         {
  155.             $criteria->addSorting(new FieldSorting('releaseDate'FieldSorting::ASCENDING));
  156.         }
  157.         elseif ($sorting == 'date_desc')
  158.         {
  159.             $criteria->addSorting(new FieldSorting('releaseDate'FieldSorting::DESCENDING));
  160.         }
  161.         elseif ($sorting == 'price_asc')
  162.         {
  163.             $criteria->addSorting(new FieldSorting('cheapestPrice'FieldSorting::ASCENDING));
  164.         }
  165.         elseif ($sorting == 'price_desc')
  166.         {
  167.             $criteria->addSorting(new FieldSorting('cheapestPrice'FieldSorting::DESCENDING));
  168.         }
  169.         if ($limit >= 0) {
  170.             $criteria->setLimit($limit);
  171.         }
  172.         $searchResult $this->productRepository->search($criteria$salesChannelContext)->getElements();
  173.         return $searchResult;
  174.     }
  175.     /** Daten für Slider in Product Detail Page
  176.      * @param $manufacturerId string
  177.      * @param $salesChannelContext SalesChannelContext
  178.      * @return mixed
  179.      * @throws \Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException
  180.      */
  181.     public function getManufacturerById($manufacturerId$salesChannelContext)
  182.     {
  183.         $criteria = new Criteria();
  184.         $criteria->addFilter(new EqualsFilter('id'$manufacturerId));
  185.         $criteria->addAssociation('media');
  186.         $searchResult $this->manufacturerRepository->search($criteria$salesChannelContext->getContext())->getElements();
  187.         return $searchResult;
  188.     }
  189.     /** Produkte pro Hersteller saleschannelabhängig zählen und speichern
  190.      * @param $context Context
  191.      * @return mixed
  192.      */
  193.     public function runProductCount($context) {
  194.         $criteria = new Criteria();
  195.         $criteria->setTitle('runProductCount salesChannels');
  196.         $criteria->addFilter(new EqualsFilter('typeId'Defaults::SALES_CHANNEL_TYPE_STOREFRONT));
  197.         $criteria->addFilter(new EqualsFilter('active'1));
  198.         $salesChannelIds $this->salesChannelRepository->searchIds($criteria$context)->getIds();
  199.         $manufacturers = [];
  200.         $criteria = new Criteria();
  201.         $criteria->setTitle('runProductCount manufacturer');
  202.         $manufacturerIds $this->manufacturerRepository->searchIds($criteria$context)->getIds();
  203.         if (count($manufacturerIds) === 0) return 0;
  204.         foreach ($manufacturerIds as $manufacturerId) {
  205.             foreach ($salesChannelIds as $salesChannelId) {
  206.                 $manufacturers[$manufacturerId][$salesChannelId] = 0;
  207.             }
  208.         }
  209.         foreach ($salesChannelIds as $salesChannelId) {
  210.             $hide $this->systemConfigService->getBool("core.listing.hideCloseoutProductsWhenOutOfStock"$salesChannelId);
  211.             $salesChannelContext $this->salesChannelContextFactory->create(''$salesChannelId);
  212.             //nur Nicht-Varianten Artikel, getrennt wegen ProductCloseoutFilter
  213.             $productCriteria = new Criteria();
  214.             $productCriteria->setTitle('product count main');
  215.             $productCriteria->addFilter(new EqualsFilter('parentId'null));
  216.             $productCriteria->addFilter(new EqualsFilter('childCount'0));
  217.             $productCriteria->setLimit(1);
  218.             $productCriteria->addFilter(
  219.                 new ProductAvailableFilter($salesChannelIdProductVisibilityDefinition::VISIBILITY_ALL)
  220.             );
  221.             if ($hide) {
  222.                 $productCriteria->addFilter(new ProductCloseoutFilter());
  223.             }
  224.             $productCriteria->addAggregation(new TermsAggregation(
  225.                 'products-counts',
  226.                 'manufacturerId'
  227.             ));
  228.             $productResult $this->productRepository->search($productCriteria$salesChannelContext);
  229.             /** @var $productCounts TermsResult|null **/
  230.             $productCounts $productResult->getAggregations()->get('products-counts');
  231.             foreach ($productCounts->getBuckets() as $bucket) {
  232.                 if (isset($manufacturers[$bucket->getKey()])) {
  233.                     $manufacturers[$bucket->getKey()][$salesChannelId] += $bucket->getCount();
  234.                 }
  235.             }
  236.             // Varianten, so ProductCloseoutFilter angewandt auf Varianten, nicht auf den Hauptartikel
  237.             // und Varianten eines Artikels werden nicht einzeln gezählt sondern als ein Produkt
  238.             $variantCriteria = new Criteria();
  239.             $variantCriteria->setTitle('runProductCount variant');
  240.             $variantCriteria->addFilter(new MultiFilter(
  241.                 Multifilter::CONNECTION_OR,
  242.                 [
  243.                     new NotFilter(
  244.                         NotFilter::CONNECTION_OR,
  245.                         [
  246.                             new EqualsFilter('parentId'null)
  247.                         ]
  248.                     ),
  249.                     new MultiFilter(
  250.                         Multifilter::CONNECTION_AND,
  251.                         [
  252.                             new EqualsFilter('parentId'null),
  253.                             new RangeFilter('childCount', [RangeFilter::GT => 0])
  254.                         ]
  255.                     )
  256.                 ]
  257.             ));
  258.             $variantCriteria->setLimit(1);
  259.             $variantCriteria->addFilter(
  260.                 new ProductAvailableFilter($salesChannelIdProductVisibilityDefinition::VISIBILITY_ALL)
  261.             );
  262.             if ($hide) {
  263.                 $variantCriteria->addFilter(new ProductCloseoutFilter());
  264.             }
  265.             $variantCriteria->addAggregation(
  266.                 new FilterAggregation(
  267.                     'filter-products-counts',
  268.                     new TermsAggregation(
  269.                         'products-counts',
  270.                         'manufacturerId',
  271.                         null,
  272.                         null,
  273.                         new TermsAggregation(
  274.                             'variants-counts',
  275.                             'parentId'
  276.                         )
  277.                     ),
  278.                     [
  279.                         new NotFilter(
  280.                             NotFilter::CONNECTION_OR,
  281.                             [
  282.                                 new EqualsFilter('parentId'null)
  283.                             ]
  284.                         )
  285.                     ]
  286.                 )
  287.             );
  288.             $variantResult $this->productRepository->search($variantCriteria$salesChannelContext);
  289.             /** @var $variantCounts TermsResult|null **/
  290.             $variantCounts $variantResult->getAggregations()->get('products-counts');
  291.             foreach ($variantCounts->getBuckets() as $bucket) {
  292.                 if (!empty($manufacturers[$bucket->getKey()]) &&
  293.                     !empty($bucket->getResult()->getBuckets())
  294.                 ) {
  295.                     if (isset($manufacturers[$bucket->getKey()])) {
  296.                         $manufacturers[$bucket->getKey()][$salesChannelId] += count($bucket->getResult()->getBuckets());
  297.                     }
  298.                 }
  299.             }
  300.         }
  301.         $updates = [];
  302.         foreach ($manufacturers as $id => $manufacturer) {
  303.             $updates[] = [
  304.                 'id' => $id,
  305.                 'customFields' => ['cbaxProductCount' => $manufacturer]
  306.             ];
  307.         }
  308.         $this->manufacturerRepository->update($updates$context);
  309.         return $updates;
  310.     }
  311.     /** Daten für Hersteller detail und index pages
  312.      * @param $config array
  313.      * @param $salesChannelContext SalesChannelContext
  314.      * @param $context Context
  315.      * @return array sorted manufacturers
  316.      * @throws \Exception
  317.      */
  318.     public function getManufacturerByChar($config$salesChannelContext$context$overviewPage false)
  319.     {
  320.         $salesChannelId $salesChannelContext->getSalesChannelId();
  321.         $criteria = new Criteria();
  322.         $criteria->setTitle('product getManufacturerByChar manufacturer');
  323.         $criteria->addSorting(new FieldSorting('name'));
  324.         if ($overviewPage) {
  325.             $criteria->addAssociation('media');
  326.         }
  327.         $manufacturers $this->manufacturerRepository->search($criteria$context)->getElements();
  328.         $productCountLive = (!empty($config['productCount']) && $config['productCount'] === 'notLive') ? false true;
  329.         foreach ($manufacturers as &$item) {
  330.             $item->countArticle $productCountLive : ($item->getTranslated()['customFields']['cbaxProductCount'][$salesChannelId] ?? null);
  331.         }
  332.         unset($item);
  333.         if ($productCountLive) {
  334.             $hide $this->systemConfigService->getBool("core.listing.hideCloseoutProductsWhenOutOfStock"$salesChannelId);
  335.             //nur Nicht-Varianten Artikel, getrennt wegen ProductCloseoutFilter
  336.             $productCriteria = new Criteria();
  337.             $productCriteria->setTitle('product getManufacturerByChar main');
  338.             $productCriteria->addFilter(new EqualsFilter('parentId'null));
  339.             $productCriteria->addFilter(new EqualsFilter('childCount'0));
  340.             $productCriteria->setLimit(1);
  341.             $productCriteria->addFilter(
  342.                 new ProductAvailableFilter($salesChannelIdProductVisibilityDefinition::VISIBILITY_ALL)
  343.             );
  344.             if ($hide) {
  345.                 $productCriteria->addFilter(new ProductCloseoutFilter());
  346.             }
  347.             $productCriteria->addAggregation(new TermsAggregation(
  348.                 'products-counts',
  349.                 'manufacturerId'
  350.             ));
  351.             $productResult $this->productRepository->search($productCriteria$salesChannelContext);
  352.             /** @var $productCounts TermsResult|null **/
  353.             $productCounts $productResult->getAggregations()->get('products-counts');
  354.             foreach ($productCounts->getBuckets() as $bucket) {
  355.                 if (!empty($manufacturers[$bucket->getKey()])) {
  356.                     $manufacturers[$bucket->getKey()]->countArticle $bucket->getCount();
  357.                 }
  358.             }
  359.             // Varianten, so ProductCloseoutFilter angewandt auf Varianten, nicht auf den Hauptartikel
  360.             $variantCriteria = new Criteria();
  361.             $variantCriteria->setTitle('product getManufacturerByChar variant');
  362.             $variantCriteria->addFilter(new NotFilter(
  363.                 NotFilter::CONNECTION_OR,
  364.                 [
  365.                     new EqualsFilter('parentId'null)
  366.                 ]
  367.             ));
  368.             $variantCriteria->setLimit(1);
  369.             $variantCriteria->addFilter(
  370.                 new ProductAvailableFilter($salesChannelIdProductVisibilityDefinition::VISIBILITY_ALL)
  371.             );
  372.             if ($hide) {
  373.                 $variantCriteria->addFilter(new ProductCloseoutFilter());
  374.             }
  375.             $variantCriteria->addAggregation(new TermsAggregation(
  376.                 'products-counts',
  377.                 'manufacturerId',
  378.                 null,
  379.                 null,
  380.                 new TermsAggregation(
  381.                     'variants-counts',
  382.                     'parentId'
  383.                 )
  384.             ));
  385.             $variantResult $this->productRepository->search($variantCriteria$salesChannelContext);
  386.             /** @var $variantCounts TermsResult|null **/
  387.             $variantCounts $variantResult->getAggregations()->get('products-counts');
  388.             foreach ($variantCounts->getBuckets() as $bucket) {
  389.                 if (!empty($manufacturers[$bucket->getKey()]) &&
  390.                     !empty($bucket->getResult()->getBuckets())
  391.                 ) {
  392.                     $manufacturers[$bucket->getKey()]->countArticle += count($bucket->getResult()->getBuckets());
  393.                 }
  394.             }
  395.         }
  396.         $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');
  397.         $sortedManufacturers = array('letters' => array());
  398.         foreach ($manufacturers as $manufacturer) {
  399.             // Hersteller, die ausgeblendet werden sollen überspringen
  400.             if (!empty($manufacturer->getTranslated()['customFields']['cbaxManufacturerIsHidden'])) {
  401.                 continue;
  402.             }
  403.             if (!($config['displayFilter'] === 'showAll') && empty($manufacturer->countArticle)) {
  404.                 continue;
  405.             }
  406.             //alte Version, Umlaute in #
  407.             //$letter = ucfirst(substr($manufacturer->getTranslated()['name'], 0, 1));
  408.             //neue Version, Ä->A, ...
  409.             //zuerst Umlaute umwandeln, sonst Probleme
  410.             $changedName strtr($manufacturer->getTranslated()['name'],['Ä'=>'A','ä'=>'a','Ü'=>'u','ü'=>'u','Ö'=>'o','ö'=>'o']);
  411.             $letter ucfirst(substr($changedName01));
  412.             // prüfen ob das erste Zeichen bereits in der Liste existiert und ggf. initiales leeres Array anlegen
  413.             if (empty($sortedManufacturers['letters'][$letter]) &&
  414.                 in_array($letter$letters)
  415.             ) {
  416.                 $sortedManufacturers['letters'][$letter] = array();
  417.             } elseif (!in_array($letter$letters)) {
  418.                 // Zeichen, die nicht in $letters enthalten sind unter '#' zusammenfassen
  419.                 if (!isset($sortedManufacturers['letters']['#'])) {
  420.                     $sortedManufacturers['letters']['#'] = array();
  421.                 }
  422.                 $letter '#';
  423.             }
  424.             array_push($sortedManufacturers['letters'][$letter], $manufacturer);
  425.         }
  426.         ksort($sortedManufacturers['letters']);
  427.         $result = array ();
  428.         // Eintrag für Sonderzeichen anlegen
  429.         if (!empty($sortedManufacturers['letters']['#'])) {
  430.             $res0 $sortedManufacturers['letters']['#'];
  431.         } else {
  432.             $res0 = array();
  433.         }
  434.         $countRes0 0;
  435.         foreach ($res0 as $manuf) {
  436.             // alle Produkte des Buchstaben
  437.             $countRes0 += $manuf->countArticle;
  438.         }
  439.         $result[0] = array(
  440.             'char' => '#',
  441.             'active' => (count($res0) > 0),
  442.             'countManufacturer' => count($res0),
  443.             'countArticle' => $countRes0,
  444.             'items' => $res0
  445.         );
  446.         // Einträge für $letters anlegen
  447.         foreach ($letters as $letter) {
  448.             if (!empty($sortedManufacturers['letters'][$letter])) {
  449.                 $res $sortedManufacturers['letters'][$letter];
  450.                 $count 0;
  451.                 foreach ($res as $manuf) {
  452.                     $count += $manuf->countArticle;
  453.                 }
  454.                 array_push($result, array(
  455.                     'char'          => $letter,
  456.                     'active'        => (count($res) > 0),
  457.                     'countManufacturer' => count($res),
  458.                     'countArticle'  => $count,
  459.                     'items'         => $res,
  460.                 ));
  461.             } else {
  462.                 array_push($result, array(
  463.                     'char' => $letter,
  464.                     'active' => false,
  465.                     'countManufacturer' => 0,
  466.                     'countArticle'  => 0,
  467.                     'items'         => array()
  468.                 ));
  469.             }
  470.         }
  471.         if ($overviewPage) {
  472.             //overview page
  473.             return [
  474.                 'sortedData' => $result,
  475.                 'unsortedData' => $manufacturers
  476.             ];
  477.         }
  478.         //detail page
  479.         return $result;
  480.     }
  481.     /**
  482.      * @param $id string|null
  483.      * @param $context Context
  484.      * @return CmsPageEntity|null
  485.      */
  486.     public function getCmsPage($id$context)
  487.     {
  488.         $criteria = new Criteria();
  489.         $criteria->addFilter(new EqualsFilter('id'$id));
  490.         $criteria->addAssociation('sections');
  491.         $criteria->addAssociation('sections.blocks');
  492.         $criteria
  493.             ->getAssociation('sections')
  494.             ->addAssociation('backgroundMedia');
  495.         $criteria
  496.             ->getAssociation('sections.blocks')
  497.             ->addAssociation('backgroundMedia')
  498.             ->addAssociation('slots');
  499.         $searchResult $this->cmsPageRepository->search($criteria$context);
  500.         $cmsPage $searchResult->first();
  501.         return $cmsPage;
  502.     }
  503.     public function loadSlotData(CmsPageEntity $pageResolverContext $resolverContext): void
  504.     {
  505.         $slots $this->slotDataResolver->resolve($page->getSections()->getBlocks()->getSlots(), $resolverContext);
  506.         $page->getSections()->getBlocks()->setSlots($slots);
  507.     }
  508.     public function filterEmptyCmsBlocksDetail($page$cbaxModulManufacturers)
  509.     {
  510.         $cmsPage $page->getCmsPage();
  511.         if (empty($cmsPage)) {
  512.             return $page;
  513.         }
  514.         $cmsSectionCollection = new CmsSectionCollection();
  515.         foreach ($cmsPage->getSections() as $section) {
  516.             $newBlocksCollection $section->getBlocks();
  517.             foreach ($section->getBlocks() as $block) {
  518.                 //Banner Block
  519.                 if ($block->getType() === 'cbax-manufacturers-banner') {
  520.                     $slot $block->getSlots()->first();
  521.                     if ($slot->getType() === 'cbax-manufacturers-banner' &&
  522.                         empty($cbaxModulManufacturers['bannerMedia']) &&
  523.                         (empty($slot->getConfig()) ||
  524.                             (!empty($slot->getConfig()) &&
  525.                                 empty($slot->getConfig()['altUrl']['value'])
  526.                             )
  527.                         )
  528.                     ) {
  529.                         $newBlocksCollection->filterAndReduceByProperty('id'$block->getId());
  530.                     }
  531.                 } //Cbax Image-Text Block
  532.                 elseif ($block->getType() === 'cbax-manufacturers-image-text') {
  533.                     $imageIsEmpty false;
  534.                     $textIsEmpty false;
  535.                     foreach ($block->getSlots() as $slot) {
  536.                         if ($slot->getType() === 'image' &&
  537.                             empty($cbaxModulManufacturers['manufacturer']->getMedia()) &&
  538.                             (empty($slot->getConfig()) ||
  539.                                 (!empty($slot->getConfig()) &&
  540.                                     $slot->getConfig()['media']['source'] === 'mapped' &&
  541.                                     $slot->getConfig()['media']['value'] === 'product_manufacturer.media'
  542.                                 )
  543.                             )
  544.                         ) {
  545.                             $imageIsEmpty true;
  546.                         }
  547.                         if ($slot->getType() === 'text' && empty($slot->getConfig())) {
  548.                             $textIsEmpty true;
  549.                         }
  550.                         if ($slot->getType() === 'text' &&
  551.                             !empty($slot->getConfig()) &&
  552.                             !empty($slot->getConfig()['content']) &&
  553.                             $slot->getConfig()['content']['source'] === 'mapped'
  554.                         ) {
  555.                             $propertyArray explode('.'$slot->getConfig()['content']['value']);
  556.                             if (!empty($propertyArray)) {
  557.                                 $property end($propertyArray);
  558.                                 if ($property && !in_array('customFields'$propertyArray) &&
  559.                                     empty($cbaxModulManufacturers['manufacturer']->getTranslated()[$property])
  560.                                 ) {
  561.                                     $textIsEmpty true;
  562.                                 } elseif ($property &&
  563.                                     in_array('customFields'$propertyArray) &&
  564.                                     (empty($cbaxModulManufacturers['manufacturer']->getTranslated()['customFields']) ||
  565.                                         (!empty($cbaxModulManufacturers['manufacturer']->getTranslated()['customFields']) &&
  566.                                             empty($cbaxModulManufacturers['manufacturer']->getTranslated()['customFields'][$property])
  567.                                         )
  568.                                     )
  569.                                 ) {
  570.                                     $textIsEmpty true;
  571.                                 }
  572.                             }
  573.                         }
  574.                     }
  575.                     $blockIsEmpty $imageIsEmpty && $textIsEmpty;
  576.                     if ($blockIsEmpty) {
  577.                         $newBlocksCollection->filterAndReduceByProperty('id'$block->getId());
  578.                     }
  579.                 }
  580.             }
  581.             $section->setBlocks($newBlocksCollection);
  582.             $cmsSectionCollection->add($section);
  583.         }
  584.         $cmsPage->setSections($cmsSectionCollection);
  585.         $page->setCmsPage($cmsPage);
  586.         return $page;
  587.     }
  588.     public function filterEmptyCmsBlocksIndex($page$cbaxModulManufacturers)
  589.     {
  590.         $cmsPage $page->getCmsPage();
  591.         if (empty($cmsPage)) {
  592.             return $page;
  593.         }
  594.         $cmsSectionCollection = new CmsSectionCollection();
  595.         foreach ($cmsPage->getSections() as $section) {
  596.             $newBlocksCollection $section->getBlocks();
  597.             foreach ($section->getBlocks() as $block) {
  598.                 //Image Banner Block
  599.                 if ($block->getType() === 'image-cover' ||
  600.                     $block->getType() === 'image'
  601.                 ) {
  602.                     $slot $block->getSlots()->first();
  603.                     if ($slot->getType() === 'image' &&
  604.                         (empty($slot->getConfig()) ||
  605.                             (!empty($slot->getConfig()) &&
  606.                                 !empty($slot->getConfig()['media']) &&
  607.                                 empty($slot->getConfig()['media']['value'])
  608.                             )
  609.                         )
  610.                     ) {
  611.                         $newBlocksCollection->filterAndReduceByProperty('id'$block->getId());
  612.                     }
  613.                 } //Text Block
  614.                 elseif ($block->getType() === 'text') {
  615.                     $slot $block->getSlots()->first();
  616.                     if ($slot->getType() === 'text' &&
  617.                         (empty($slot->getConfig()) ||
  618.                             (!empty($slot->getConfig()) &&
  619.                                 !empty($slot->getConfig()['content']) &&
  620.                                 empty($slot->getConfig()['content']['value'])
  621.                             )
  622.                         )
  623.                     ) {
  624.                         $newBlocksCollection->filterAndReduceByProperty('id'$block->getId());
  625.                     }
  626.                 } // Top Slider
  627.                 elseif ($block->getType() === 'cbax-manufacturers-topslider') {
  628.                     $slot $block->getSlots()->first();
  629.                     if ($slot->getType() === 'cbax-manufacturers-topslider' &&
  630.                         empty($cbaxModulManufacturers['templateData']['premiums'])
  631.                     ) {
  632.                         $newBlocksCollection->filterAndReduceByProperty('id'$block->getId());
  633.                     }
  634.                 }
  635.             }
  636.             $section->setBlocks($newBlocksCollection);
  637.             $cmsSectionCollection->add($section);
  638.         }
  639.         $cmsPage->setSections($cmsSectionCollection);
  640.         $page->setCmsPage($cmsPage);
  641.         return $page;
  642.     }
  643.     // daten für Hersteller Detail page
  644.     public function getProductsListing($manufacturerId$pageNumberSalesChannelContext $salesChannelContext): EntitySearchResult
  645.     {
  646.         $criteria = new Criteria();
  647.         $criteria->addAssociation('cover');
  648.         $criteria->addAssociation('prices');
  649.         $criteria->addAssociation('unit');
  650.         $criteria->addAssociation('deliveryTime');
  651.         $criteria->addAssociation('visibilities');
  652.         $criteria->addFilter(new EqualsFilter('manufacturerId'$manufacturerId));
  653.         $saleschannelId $salesChannelContext->getSalesChannelId();
  654.         $criteria->addFilter(
  655.             new ProductAvailableFilter($saleschannelIdProductVisibilityDefinition::VISIBILITY_ALL)
  656.         );
  657.         // Sortierung der Produkte nach Namen
  658.         $criteria->addSorting(new FieldSorting('name'));
  659.         // Pagenierung
  660.         $limit $this->systemConfigService->get("core.listing.productsPerPage"$saleschannelId);
  661.         $limit = !empty($limit) ? (int)$limit 20;
  662.         $criteria->setLimit($limit);
  663.         // Offset für Pagenierung ermitteln
  664.         if ($pageNumber 0) {
  665.             $offset $limit * ($pageNumber -1);
  666.             $criteria->setOffset($offset);
  667.         }
  668.         // Pagenierung aktivieren
  669.         $criteria->setTotalCountMode(1);
  670.         $event $this->eventDispatcher->dispatch(new CbaxManufacturersProductListingCriteriaEvent($criteria$manufacturerId));
  671.         $criteria $event->getCriteria();
  672.         $result $this->listingLoader->load($criteria$salesChannelContext);
  673.         return $result;
  674.     }
  675. }