<?php
namespace Klikensteen\ThemeCustomChanges\Subscriber;
use Shopware\Core\Content\Product\ProductEvents;
use Shopware\Core\Framework\Struct\ArrayStruct;
use Shopware\Core\System\SalesChannel\Entity\SalesChannelEntityLoadedEvent;
use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepository;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Storefront\Page\Product\ProductPageCriteriaEvent;
use Shopware\Core\Content\Product\Events\ProductListingCriteriaEvent;
use Symfony\Component\HttpFoundation\RequestStack;
use Shopware\Core\Content\Product\SalesChannel\Detail\ProductConfiguratorLoader;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class AllVariantDetailPage
*
* Used to collect the information of the variants
*/
class ProductSubscriber implements EventSubscriberInterface
{
/**
* @var ContainerInterface
*/
protected $container;
protected $configuratorLoader;
public function __construct(
ContainerInterface $container,
RequestStack $requestStack,
ProductConfiguratorLoader $configuratorLoader
)
{
$this->container = $container;
$this->currentRequestAttributes = $requestStack->getCurrentRequest()->attributes;
$this->configuratorLoader = $configuratorLoader;
}
/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
'sales_channel.' . ProductEvents::PRODUCT_LOADED_EVENT => 'onProductsLoadedEvents'
];
}
public function onProductsLoadedEvents(SalesChannelEntityLoadedEvent $event)
{
$salesChannelContext = $event->getSalesChannelContext();
if ($salesChannelContext) {
foreach ($event->getEntities() as $productEntity) {
$parentId = $productEntity->getParentId();
if($parentId){
$productEntity->addExtension('kilkHasParent', new ArrayStruct(['value' => 1 ]));
}
}
}
}
}