<?php declare(strict_types=1);
namespace Atl\ProductConfigurator\Subscriber;
use Atl\ProductConfigurator\Core\Content\ProductConfigurator\ProductConfiguratorEntity;
use Atl\ProductConfigurator\Core\Content\ProductConfigurator\SalesChannel\Price\PriceService;
use Atl\ProductConfigurator\Migration\Migration1628124328ProductExtension;
use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ProductPageLoadedSubscriber implements EventSubscriberInterface
{
/**
* @var PriceService
*/
private $priceService;
public function __construct(PriceService $priceService)
{
$this->priceService = $priceService;
}
/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
ProductPageLoadedEvent::class => 'enrichPrice'
];
}
/**
* @param ProductPageLoadedEvent $event
* @return void
*/
public function enrichPrice(ProductPageLoadedEvent $event): void
{
/** @var ProductConfiguratorEntity $productConfigurator */
$productConfigurator = $event->getPage()->getProduct()->getExtension(Migration1628124328ProductExtension::PRODUCT_EXTENSION);
if (empty($productConfigurator)) {
return;
}
$this->priceService->calculatePrice($productConfigurator, $event->getSalesChannelContext());
}
}