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

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