custom/plugins/NetiNextEasyCoupon/src/Decorator/ProductCmsElementResolverDecorator.php line 63

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace NetInventors\NetiNextEasyCoupon\Decorator;
  4. use NetInventors\NetiNextEasyCoupon\Struct\PluginConfigStruct;
  5. use Shopware\Core\Content\Cms\Aggregate\CmsSlot\CmsSlotEntity;
  6. use Shopware\Core\Content\Cms\DataResolver\CriteriaCollection;
  7. use Shopware\Core\Content\Cms\DataResolver\Element\CmsElementResolverInterface;
  8. use Shopware\Core\Content\Cms\DataResolver\Element\ElementDataCollection;
  9. use Shopware\Core\Content\Cms\DataResolver\ResolverContext\ResolverContext;
  10. use Shopware\Core\Content\Product\ProductDefinition;
  11. use Shopware\Core\Content\Product\SalesChannel\SalesChannelProductDefinition;
  12. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  13. class ProductCmsElementResolverDecorator implements CmsElementResolverInterface
  14. {
  15.     protected CmsElementResolverInterface $decoratedService;
  16.     protected PluginConfigStruct          $pluginConfig;
  17.     public function __construct(
  18.         CmsElementResolverInterface $decoratedService,
  19.         PluginConfigStruct          $pluginConfig
  20.     ) {
  21.         $this->decoratedService $decoratedService;
  22.         $this->pluginConfig     $pluginConfig;
  23.     }
  24.     public function getType(): string
  25.     {
  26.         return $this->decoratedService->getType();
  27.     }
  28.     public function collect(CmsSlotEntity $slotResolverContext $resolverContext): ?CriteriaCollection
  29.     {
  30.         $newCriteriaCollection = new CriteriaCollection();
  31.         $criteriaCollection    $this->decoratedService->collect($slot$resolverContext);
  32.         if (!$criteriaCollection) {
  33.             return $criteriaCollection;
  34.         }
  35.         /** @var array<string, array<string, Criteria>> $allCriteria */
  36.         $allCriteria $criteriaCollection->all();
  37.         foreach ($allCriteria as $definition => $criteria) {
  38.             foreach ($criteria as $key => $criterion) {
  39.                 if (ProductDefinition::class === $definition || SalesChannelProductDefinition::class === $definition) {
  40.                     $criterion->addAssociation('netiEasyCouponProduct.extraOptions');
  41.                 }
  42.                 $newCriteriaCollection->add($key$definition$criterion);
  43.             }
  44.         }
  45.         return $newCriteriaCollection;
  46.     }
  47.     public function enrich(CmsSlotEntity $slotResolverContext $resolverContextElementDataCollection $result): void
  48.     {
  49.         $this->decoratedService->enrich($slot$resolverContext$result);
  50.     }
  51. }