diff --git a/local/modules/TheliaSmarty/Events/PseByProductEvent.php b/local/modules/TheliaSmarty/Events/PseByProductEvent.php new file mode 100644 index 0000000000..ca89b7345b --- /dev/null +++ b/local/modules/TheliaSmarty/Events/PseByProductEvent.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace TheliaSmarty\Events; + +use Thelia\Core\Event\ActionEvent; +use Thelia\Model\ProductSaleElements; + +class PseByProductEvent extends ActionEvent +{ + protected ProductSaleElements $productSaleElements; + + public function __construct($productSaleElements) + { + $this->productSaleElements = $productSaleElements; + } + + public function getProductSaleElements(): ProductSaleElements + { + return $this->productSaleElements; + } +} diff --git a/local/modules/TheliaSmarty/Template/Plugins/FrontUtils.php b/local/modules/TheliaSmarty/Template/Plugins/FrontUtils.php index fadfd5b3d6..4b8691b7c4 100644 --- a/local/modules/TheliaSmarty/Template/Plugins/FrontUtils.php +++ b/local/modules/TheliaSmarty/Template/Plugins/FrontUtils.php @@ -13,6 +13,7 @@ namespace TheliaSmarty\Template\Plugins; use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; use Thelia\Core\HttpFoundation\Request; use Thelia\Core\Security\SecurityContext; use Thelia\Model\CategoryQuery; @@ -21,6 +22,7 @@ use Thelia\Model\ProductSaleElementsQuery; use Thelia\TaxEngine\TaxEngine; use Thelia\Tools\URL; +use TheliaSmarty\Events\PseByProductEvent; use TheliaSmarty\Template\AbstractSmartyPlugin; use TheliaSmarty\Template\SmartyPluginDescriptor; @@ -42,14 +44,19 @@ class FrontUtils extends AbstractSmartyPlugin /** @var string */ protected $assetsPublicPath; + /** @var EventDispatcherInterface */ + protected $eventDispatcher; + public function __construct( RequestStack $requestStack, TaxEngine $taxEngine, SecurityContext $securityContext, + EventDispatcherInterface $eventDispatcher ) { $this->request = $requestStack->getCurrentRequest(); $this->taxEngine = $taxEngine; $this->securityContext = $securityContext; + $this->eventDispatcher = $eventDispatcher; } public function getPluginDescriptors() @@ -151,6 +158,8 @@ public function psesByProduct($params) $attributes[$attribute->getAttributeId()] = $attribute->getAttributeAvId(); } + $this->eventDispatcher->dispatch(new PseByProductEvent($pse)); + $result[] = [ 'id' => $pse->getId(), 'isDefault' => $pse->isDefault(),