<?php declare(strict_types = 1);
namespace Cbax\ModulManufacturers\Components;
use Shopware\Core\Framework\Context;
use Shopware\Core\Defaults;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Content\Product\SalesChannel\ProductAvailableFilter;
use Shopware\Core\Content\Product\SalesChannel\ProductCloseoutFilter;
use Shopware\Core\Content\Product\Aggregate\ProductVisibility\ProductVisibilityDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\MultiFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\NotFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Aggregation\Bucket\FilterAggregation;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\RangeFilter;
use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Core\Content\Product\SalesChannel\Listing\ProductListingLoader;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Shopware\Core\Framework\DataAbstractionLayer\Search\EntitySearchResult;
use Shopware\Core\Framework\DataAbstractionLayer\Search\AggregationResult\Bucket\TermsResult;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Aggregation\Bucket\TermsAggregation;
use Shopware\Core\Content\Cms\CmsPageEntity;
use Shopware\Core\Content\Cms\DataResolver\CmsSlotsDataResolver;
use Shopware\Core\Content\Cms\DataResolver\ResolverContext\ResolverContext;
use Shopware\Core\Content\Cms\Aggregate\CmsSection\CmsSectionCollection;
use Shopware\Core\System\SalesChannel\Context\AbstractSalesChannelContextFactory;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Cbax\ModulManufacturers\Core\Content\Events\CbaxManufacturersProductListingCriteriaEvent;
class ManufacturersHelper
{
/**
* @var SystemConfigService
*/
private $systemConfigService;
/**
* @var SalesChannelRepositoryInterface
*/
private $productRepository;
/**
* @var EntityRepositoryInterface
*/
private $manufacturerRepository;
/**
* @var EntityRepositoryInterface
*/
private $salesChannelRepository;
/**
* @var EntityRepositoryInterface
*/
private $cmsPageRepository;
/**
* @var AbstractSalesChannelContextFactory
*/
private $salesChannelContextFactory;
/**
* @var CmsSlotsDataResolver
*/
private $slotDataResolver;
/**
* @var ProductListingLoader
*/
private $listingLoader;
/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;
public function __construct(
SystemConfigService $systemConfigService,
SalesChannelRepositoryInterface $productRepository,
EntityRepositoryInterface $manufacturerRepository,
EntityRepositoryInterface $salesChannelRepository,
EntityRepositoryInterface $cmsPageRepository,
CmsSlotsDataResolver $slotDataResolver,
ProductListingLoader $listingLoader,
EventDispatcherInterface $eventDispatcher,
AbstractSalesChannelContextFactory $salesChannelContextFactory
) {
$this->systemConfigService = $systemConfigService;
$this->productRepository = $productRepository;
$this->manufacturerRepository = $manufacturerRepository;
$this->cmsPageRepository = $cmsPageRepository;
$this->slotDataResolver = $slotDataResolver;
$this->listingLoader = $listingLoader;
$this->eventDispatcher = $eventDispatcher;
$this->salesChannelRepository = $salesChannelRepository;
$this->salesChannelContextFactory = $salesChannelContextFactory;
}
/**
* weitere allgemeine Templatedaten ermitteln, aktuell Top Hersteller
* @param $unsortedData array Liste von Herstellern
* @param $config array
* @return array Top Hersteller
*/
public function getTemplateData($unsortedData, $config)
{
$result['premiums'] = array();
foreach ($unsortedData as $manufacturer) {
if (!empty($manufacturer->countArticle) ||
$config['displayFilter'] === 'showAll'
) {
$customFields = $manufacturer->get('translated')['customFields'];
if (!empty($customFields['cbaxManufacturerPremium']) &&
empty($customFields['cbaxManufacturerIsHidden'])
) {
array_push($result['premiums'], $manufacturer);
}
}
}
return $result;
}
/** Daten für Slider in Product Detail Page
* @param $manufacturerId string
* @param $categoryId string|null
* @param $salesChannelContext SalesChannelContext
* @param $currentProductId string|null
* @return mixed
* @throws \Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException
*/
public function getProductsByManufacturer($manufacturerId, $categoryId, $salesChannelContext, $sorting, $limit, $currentProductId = null)
{
$salesChannelId = $salesChannelContext->getSalesChannel()->get('id');
$hide = $this->systemConfigService->getBool("core.listing.hideCloseoutProductsWhenOutOfStock", $salesChannelId);
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('manufacturerId', $manufacturerId));
$criteria->addFilter(new EqualsFilter('parentId', null));
if (!empty($currentProductId)) {
$criteria->addFilter(new NotFilter(
NotFilter::CONNECTION_OR,
[
new EqualsFilter('id', $currentProductId)
]
));
}
$criteria->addFilter(
new ProductAvailableFilter($salesChannelId, ProductVisibilityDefinition::VISIBILITY_ALL)
);
if ($hide) {
$criteria->addFilter(new ProductCloseoutFilter());
}
if (!empty($categoryId)) {
$criteria->addAssociation('categories');
$criteria->addFilter(new EqualsFilter('categories.id', $categoryId));
}
if ($sorting == 'name_asc')
{
$criteria->addSorting(new FieldSorting('name', FieldSorting::ASCENDING));
}
elseif ($sorting == 'name_desc')
{
$criteria->addSorting(new FieldSorting('name', FieldSorting::DESCENDING));
}
elseif ($sorting == 'date_asc')
{
$criteria->addSorting(new FieldSorting('releaseDate', FieldSorting::ASCENDING));
}
elseif ($sorting == 'date_desc')
{
$criteria->addSorting(new FieldSorting('releaseDate', FieldSorting::DESCENDING));
}
elseif ($sorting == 'price_asc')
{
$criteria->addSorting(new FieldSorting('cheapestPrice', FieldSorting::ASCENDING));
}
elseif ($sorting == 'price_desc')
{
$criteria->addSorting(new FieldSorting('cheapestPrice', FieldSorting::DESCENDING));
}
if ($limit >= 0) {
$criteria->setLimit($limit);
}
$searchResult = $this->productRepository->search($criteria, $salesChannelContext)->getElements();
return $searchResult;
}
/** Daten für Slider in Product Detail Page
* @param $manufacturerId string
* @param $salesChannelContext SalesChannelContext
* @return mixed
* @throws \Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException
*/
public function getManufacturerById($manufacturerId, $salesChannelContext)
{
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('id', $manufacturerId));
$criteria->addAssociation('media');
$searchResult = $this->manufacturerRepository->search($criteria, $salesChannelContext->getContext())->getElements();
return $searchResult;
}
/** Produkte pro Hersteller saleschannelabhängig zählen und speichern
* @param $context Context
* @return mixed
*/
public function runProductCount($context) {
$criteria = new Criteria();
$criteria->setTitle('runProductCount salesChannels');
$criteria->addFilter(new EqualsFilter('typeId', Defaults::SALES_CHANNEL_TYPE_STOREFRONT));
$criteria->addFilter(new EqualsFilter('active', 1));
$salesChannelIds = $this->salesChannelRepository->searchIds($criteria, $context)->getIds();
$manufacturers = [];
$criteria = new Criteria();
$criteria->setTitle('runProductCount manufacturer');
$manufacturerIds = $this->manufacturerRepository->searchIds($criteria, $context)->getIds();
if (count($manufacturerIds) === 0) return 0;
foreach ($manufacturerIds as $manufacturerId) {
foreach ($salesChannelIds as $salesChannelId) {
$manufacturers[$manufacturerId][$salesChannelId] = 0;
}
}
foreach ($salesChannelIds as $salesChannelId) {
$hide = $this->systemConfigService->getBool("core.listing.hideCloseoutProductsWhenOutOfStock", $salesChannelId);
$salesChannelContext = $this->salesChannelContextFactory->create('', $salesChannelId);
//nur Nicht-Varianten Artikel, getrennt wegen ProductCloseoutFilter
$productCriteria = new Criteria();
$productCriteria->setTitle('product count main');
$productCriteria->addFilter(new EqualsFilter('parentId', null));
$productCriteria->addFilter(new EqualsFilter('childCount', 0));
$productCriteria->setLimit(1);
$productCriteria->addFilter(
new ProductAvailableFilter($salesChannelId, ProductVisibilityDefinition::VISIBILITY_ALL)
);
if ($hide) {
$productCriteria->addFilter(new ProductCloseoutFilter());
}
$productCriteria->addAggregation(new TermsAggregation(
'products-counts',
'manufacturerId'
));
$productResult = $this->productRepository->search($productCriteria, $salesChannelContext);
/** @var $productCounts TermsResult|null **/
$productCounts = $productResult->getAggregations()->get('products-counts');
foreach ($productCounts->getBuckets() as $bucket) {
if (isset($manufacturers[$bucket->getKey()])) {
$manufacturers[$bucket->getKey()][$salesChannelId] += $bucket->getCount();
}
}
// Varianten, so ProductCloseoutFilter angewandt auf Varianten, nicht auf den Hauptartikel
// und Varianten eines Artikels werden nicht einzeln gezählt sondern als ein Produkt
$variantCriteria = new Criteria();
$variantCriteria->setTitle('runProductCount variant');
$variantCriteria->addFilter(new MultiFilter(
Multifilter::CONNECTION_OR,
[
new NotFilter(
NotFilter::CONNECTION_OR,
[
new EqualsFilter('parentId', null)
]
),
new MultiFilter(
Multifilter::CONNECTION_AND,
[
new EqualsFilter('parentId', null),
new RangeFilter('childCount', [RangeFilter::GT => 0])
]
)
]
));
$variantCriteria->setLimit(1);
$variantCriteria->addFilter(
new ProductAvailableFilter($salesChannelId, ProductVisibilityDefinition::VISIBILITY_ALL)
);
if ($hide) {
$variantCriteria->addFilter(new ProductCloseoutFilter());
}
$variantCriteria->addAggregation(
new FilterAggregation(
'filter-products-counts',
new TermsAggregation(
'products-counts',
'manufacturerId',
null,
null,
new TermsAggregation(
'variants-counts',
'parentId'
)
),
[
new NotFilter(
NotFilter::CONNECTION_OR,
[
new EqualsFilter('parentId', null)
]
)
]
)
);
$variantResult = $this->productRepository->search($variantCriteria, $salesChannelContext);
/** @var $variantCounts TermsResult|null **/
$variantCounts = $variantResult->getAggregations()->get('products-counts');
foreach ($variantCounts->getBuckets() as $bucket) {
if (!empty($manufacturers[$bucket->getKey()]) &&
!empty($bucket->getResult()->getBuckets())
) {
if (isset($manufacturers[$bucket->getKey()])) {
$manufacturers[$bucket->getKey()][$salesChannelId] += count($bucket->getResult()->getBuckets());
}
}
}
}
$updates = [];
foreach ($manufacturers as $id => $manufacturer) {
$updates[] = [
'id' => $id,
'customFields' => ['cbaxProductCount' => $manufacturer]
];
}
$this->manufacturerRepository->update($updates, $context);
return $updates;
}
/** Daten für Hersteller detail und index pages
* @param $config array
* @param $salesChannelContext SalesChannelContext
* @param $context Context
* @return array sorted manufacturers
* @throws \Exception
*/
public function getManufacturerByChar($config, $salesChannelContext, $context, $overviewPage = false)
{
$salesChannelId = $salesChannelContext->getSalesChannelId();
$criteria = new Criteria();
$criteria->setTitle('product getManufacturerByChar manufacturer');
$criteria->addSorting(new FieldSorting('name'));
if ($overviewPage) {
$criteria->addAssociation('media');
}
$manufacturers = $this->manufacturerRepository->search($criteria, $context)->getElements();
$productCountLive = (!empty($config['productCount']) && $config['productCount'] === 'notLive') ? false : true;
foreach ($manufacturers as &$item) {
$item->countArticle = $productCountLive ? 0 : ($item->getTranslated()['customFields']['cbaxProductCount'][$salesChannelId] ?? null);
}
unset($item);
if ($productCountLive) {
$hide = $this->systemConfigService->getBool("core.listing.hideCloseoutProductsWhenOutOfStock", $salesChannelId);
//nur Nicht-Varianten Artikel, getrennt wegen ProductCloseoutFilter
$productCriteria = new Criteria();
$productCriteria->setTitle('product getManufacturerByChar main');
$productCriteria->addFilter(new EqualsFilter('parentId', null));
$productCriteria->addFilter(new EqualsFilter('childCount', 0));
$productCriteria->setLimit(1);
$productCriteria->addFilter(
new ProductAvailableFilter($salesChannelId, ProductVisibilityDefinition::VISIBILITY_ALL)
);
if ($hide) {
$productCriteria->addFilter(new ProductCloseoutFilter());
}
$productCriteria->addAggregation(new TermsAggregation(
'products-counts',
'manufacturerId'
));
$productResult = $this->productRepository->search($productCriteria, $salesChannelContext);
/** @var $productCounts TermsResult|null **/
$productCounts = $productResult->getAggregations()->get('products-counts');
foreach ($productCounts->getBuckets() as $bucket) {
if (!empty($manufacturers[$bucket->getKey()])) {
$manufacturers[$bucket->getKey()]->countArticle = $bucket->getCount();
}
}
// Varianten, so ProductCloseoutFilter angewandt auf Varianten, nicht auf den Hauptartikel
$variantCriteria = new Criteria();
$variantCriteria->setTitle('product getManufacturerByChar variant');
$variantCriteria->addFilter(new NotFilter(
NotFilter::CONNECTION_OR,
[
new EqualsFilter('parentId', null)
]
));
$variantCriteria->setLimit(1);
$variantCriteria->addFilter(
new ProductAvailableFilter($salesChannelId, ProductVisibilityDefinition::VISIBILITY_ALL)
);
if ($hide) {
$variantCriteria->addFilter(new ProductCloseoutFilter());
}
$variantCriteria->addAggregation(new TermsAggregation(
'products-counts',
'manufacturerId',
null,
null,
new TermsAggregation(
'variants-counts',
'parentId'
)
));
$variantResult = $this->productRepository->search($variantCriteria, $salesChannelContext);
/** @var $variantCounts TermsResult|null **/
$variantCounts = $variantResult->getAggregations()->get('products-counts');
foreach ($variantCounts->getBuckets() as $bucket) {
if (!empty($manufacturers[$bucket->getKey()]) &&
!empty($bucket->getResult()->getBuckets())
) {
$manufacturers[$bucket->getKey()]->countArticle += count($bucket->getResult()->getBuckets());
}
}
}
$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');
$sortedManufacturers = array('letters' => array());
foreach ($manufacturers as $manufacturer) {
// Hersteller, die ausgeblendet werden sollen überspringen
if (!empty($manufacturer->getTranslated()['customFields']['cbaxManufacturerIsHidden'])) {
continue;
}
if (!($config['displayFilter'] === 'showAll') && empty($manufacturer->countArticle)) {
continue;
}
//alte Version, Umlaute in #
//$letter = ucfirst(substr($manufacturer->getTranslated()['name'], 0, 1));
//neue Version, Ä->A, ...
//zuerst Umlaute umwandeln, sonst Probleme
$changedName = strtr($manufacturer->getTranslated()['name'],['Ä'=>'A','ä'=>'a','Ü'=>'u','ü'=>'u','Ö'=>'o','ö'=>'o']);
$letter = ucfirst(substr($changedName, 0, 1));
// prüfen ob das erste Zeichen bereits in der Liste existiert und ggf. initiales leeres Array anlegen
if (empty($sortedManufacturers['letters'][$letter]) &&
in_array($letter, $letters)
) {
$sortedManufacturers['letters'][$letter] = array();
} elseif (!in_array($letter, $letters)) {
// Zeichen, die nicht in $letters enthalten sind unter '#' zusammenfassen
if (!isset($sortedManufacturers['letters']['#'])) {
$sortedManufacturers['letters']['#'] = array();
}
$letter = '#';
}
array_push($sortedManufacturers['letters'][$letter], $manufacturer);
}
ksort($sortedManufacturers['letters']);
$result = array ();
// Eintrag für Sonderzeichen anlegen
if (!empty($sortedManufacturers['letters']['#'])) {
$res0 = $sortedManufacturers['letters']['#'];
} else {
$res0 = array();
}
$countRes0 = 0;
foreach ($res0 as $manuf) {
// alle Produkte des Buchstaben
$countRes0 += $manuf->countArticle;
}
$result[0] = array(
'char' => '#',
'active' => (count($res0) > 0),
'countManufacturer' => count($res0),
'countArticle' => $countRes0,
'items' => $res0
);
// Einträge für $letters anlegen
foreach ($letters as $letter) {
if (!empty($sortedManufacturers['letters'][$letter])) {
$res = $sortedManufacturers['letters'][$letter];
$count = 0;
foreach ($res as $manuf) {
$count += $manuf->countArticle;
}
array_push($result, array(
'char' => $letter,
'active' => (count($res) > 0),
'countManufacturer' => count($res),
'countArticle' => $count,
'items' => $res,
));
} else {
array_push($result, array(
'char' => $letter,
'active' => false,
'countManufacturer' => 0,
'countArticle' => 0,
'items' => array()
));
}
}
if ($overviewPage) {
//overview page
return [
'sortedData' => $result,
'unsortedData' => $manufacturers
];
}
//detail page
return $result;
}
/**
* @param $id string|null
* @param $context Context
* @return CmsPageEntity|null
*/
public function getCmsPage($id, $context)
{
$criteria = new Criteria();
$criteria->addFilter(new EqualsFilter('id', $id));
$criteria->addAssociation('sections');
$criteria->addAssociation('sections.blocks');
$criteria
->getAssociation('sections')
->addAssociation('backgroundMedia');
$criteria
->getAssociation('sections.blocks')
->addAssociation('backgroundMedia')
->addAssociation('slots');
$searchResult = $this->cmsPageRepository->search($criteria, $context);
$cmsPage = $searchResult->first();
return $cmsPage;
}
public function loadSlotData(CmsPageEntity $page, ResolverContext $resolverContext): void
{
$slots = $this->slotDataResolver->resolve($page->getSections()->getBlocks()->getSlots(), $resolverContext);
$page->getSections()->getBlocks()->setSlots($slots);
}
public function filterEmptyCmsBlocksDetail($page, $cbaxModulManufacturers)
{
$cmsPage = $page->getCmsPage();
if (empty($cmsPage)) {
return $page;
}
$cmsSectionCollection = new CmsSectionCollection();
foreach ($cmsPage->getSections() as $section) {
$newBlocksCollection = $section->getBlocks();
foreach ($section->getBlocks() as $block) {
//Banner Block
if ($block->getType() === 'cbax-manufacturers-banner') {
$slot = $block->getSlots()->first();
if ($slot->getType() === 'cbax-manufacturers-banner' &&
empty($cbaxModulManufacturers['bannerMedia']) &&
(empty($slot->getConfig()) ||
(!empty($slot->getConfig()) &&
empty($slot->getConfig()['altUrl']['value'])
)
)
) {
$newBlocksCollection->filterAndReduceByProperty('id', $block->getId());
}
} //Cbax Image-Text Block
elseif ($block->getType() === 'cbax-manufacturers-image-text') {
$imageIsEmpty = false;
$textIsEmpty = false;
foreach ($block->getSlots() as $slot) {
if ($slot->getType() === 'image' &&
empty($cbaxModulManufacturers['manufacturer']->getMedia()) &&
(empty($slot->getConfig()) ||
(!empty($slot->getConfig()) &&
$slot->getConfig()['media']['source'] === 'mapped' &&
$slot->getConfig()['media']['value'] === 'product_manufacturer.media'
)
)
) {
$imageIsEmpty = true;
}
if ($slot->getType() === 'text' && empty($slot->getConfig())) {
$textIsEmpty = true;
}
if ($slot->getType() === 'text' &&
!empty($slot->getConfig()) &&
!empty($slot->getConfig()['content']) &&
$slot->getConfig()['content']['source'] === 'mapped'
) {
$propertyArray = explode('.', $slot->getConfig()['content']['value']);
if (!empty($propertyArray)) {
$property = end($propertyArray);
if ($property && !in_array('customFields', $propertyArray) &&
empty($cbaxModulManufacturers['manufacturer']->getTranslated()[$property])
) {
$textIsEmpty = true;
} elseif ($property &&
in_array('customFields', $propertyArray) &&
(empty($cbaxModulManufacturers['manufacturer']->getTranslated()['customFields']) ||
(!empty($cbaxModulManufacturers['manufacturer']->getTranslated()['customFields']) &&
empty($cbaxModulManufacturers['manufacturer']->getTranslated()['customFields'][$property])
)
)
) {
$textIsEmpty = true;
}
}
}
}
$blockIsEmpty = $imageIsEmpty && $textIsEmpty;
if ($blockIsEmpty) {
$newBlocksCollection->filterAndReduceByProperty('id', $block->getId());
}
}
}
$section->setBlocks($newBlocksCollection);
$cmsSectionCollection->add($section);
}
$cmsPage->setSections($cmsSectionCollection);
$page->setCmsPage($cmsPage);
return $page;
}
public function filterEmptyCmsBlocksIndex($page, $cbaxModulManufacturers)
{
$cmsPage = $page->getCmsPage();
if (empty($cmsPage)) {
return $page;
}
$cmsSectionCollection = new CmsSectionCollection();
foreach ($cmsPage->getSections() as $section) {
$newBlocksCollection = $section->getBlocks();
foreach ($section->getBlocks() as $block) {
//Image Banner Block
if ($block->getType() === 'image-cover' ||
$block->getType() === 'image'
) {
$slot = $block->getSlots()->first();
if ($slot->getType() === 'image' &&
(empty($slot->getConfig()) ||
(!empty($slot->getConfig()) &&
!empty($slot->getConfig()['media']) &&
empty($slot->getConfig()['media']['value'])
)
)
) {
$newBlocksCollection->filterAndReduceByProperty('id', $block->getId());
}
} //Text Block
elseif ($block->getType() === 'text') {
$slot = $block->getSlots()->first();
if ($slot->getType() === 'text' &&
(empty($slot->getConfig()) ||
(!empty($slot->getConfig()) &&
!empty($slot->getConfig()['content']) &&
empty($slot->getConfig()['content']['value'])
)
)
) {
$newBlocksCollection->filterAndReduceByProperty('id', $block->getId());
}
} // Top Slider
elseif ($block->getType() === 'cbax-manufacturers-topslider') {
$slot = $block->getSlots()->first();
if ($slot->getType() === 'cbax-manufacturers-topslider' &&
empty($cbaxModulManufacturers['templateData']['premiums'])
) {
$newBlocksCollection->filterAndReduceByProperty('id', $block->getId());
}
}
}
$section->setBlocks($newBlocksCollection);
$cmsSectionCollection->add($section);
}
$cmsPage->setSections($cmsSectionCollection);
$page->setCmsPage($cmsPage);
return $page;
}
// daten für Hersteller Detail page
public function getProductsListing($manufacturerId, $pageNumber, SalesChannelContext $salesChannelContext): EntitySearchResult
{
$criteria = new Criteria();
$criteria->addAssociation('cover');
$criteria->addAssociation('prices');
$criteria->addAssociation('unit');
$criteria->addAssociation('deliveryTime');
$criteria->addAssociation('visibilities');
$criteria->addFilter(new EqualsFilter('manufacturerId', $manufacturerId));
$saleschannelId = $salesChannelContext->getSalesChannelId();
$criteria->addFilter(
new ProductAvailableFilter($saleschannelId, ProductVisibilityDefinition::VISIBILITY_ALL)
);
// Sortierung der Produkte nach Namen
$criteria->addSorting(new FieldSorting('name'));
// Pagenierung
$limit = $this->systemConfigService->get("core.listing.productsPerPage", $saleschannelId);
$limit = !empty($limit) ? (int)$limit : 20;
$criteria->setLimit($limit);
// Offset für Pagenierung ermitteln
if ($pageNumber > 0) {
$offset = $limit * ($pageNumber -1);
$criteria->setOffset($offset);
}
// Pagenierung aktivieren
$criteria->setTotalCountMode(1);
$event = $this->eventDispatcher->dispatch(new CbaxManufacturersProductListingCriteriaEvent($criteria, $manufacturerId));
$criteria = $event->getCriteria();
$result = $this->listingLoader->load($criteria, $salesChannelContext);
return $result;
}
}