<?php
declare(strict_types=1);
namespace WbfkExtensions\CmsElementResolver;
use Shopware\Core\Content\Cms\Aggregate\CmsSlot\CmsSlotEntity;
use Shopware\Core\Content\Cms\DataResolver\CriteriaCollection;
use Shopware\Core\Content\Cms\DataResolver\Element\ElementDataCollection;
use Shopware\Core\Content\Cms\DataResolver\ResolverContext\ResolverContext;
use Shopware\Core\Content\Product\Aggregate\ProductVisibility\ProductVisibilityDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\RangeFilter;
class ProductSliderCmsElementResolver extends \Shopware\Core\Content\Product\Cms\ProductSliderCmsElementResolver
{
use SliderElementResolverTrait;
public function collect(CmsSlotEntity $slot, ResolverContext $resolverContext): ?CriteriaCollection
{
$collection = parent::collect($slot, $resolverContext);
if ($collection) {
/** @var Criteria[] $criteriaCollection */
foreach ($collection as $criteriaCollection) {
foreach ($criteriaCollection as $criteria) {
$criteria
->addAssociation('options.variant')
->addAssociation('featureSet')
->addAssociation('deliveryTime')
->addAssociation('properties')
->addAssociation('properties.group')
->addAssociation('tags');
$criteria->addFilter(new RangeFilter('product.visibilities.visibility', [RangeFilter::GTE => ProductVisibilityDefinition::VISIBILITY_ALL]));
}
}
}
return ($collection && $collection->all()) ? $collection : null;
}
public function enrich(CmsSlotEntity $slot, ResolverContext $resolverContext, ElementDataCollection $result): void
{
parent::enrich($slot, $resolverContext, $result);
$responsive = ['xs' => 1, 'sm' => 2, 'md' => 2, 'lg' => 3, 'xl' => 4];
$fieldConfig = $slot->getFieldConfig();
$additionalDate = [];
$this->getSliderConfig($additionalDate, $fieldConfig, $responsive);;
$slot->assign($additionalDate);
}
}