Skip to content

Commit

Permalink
Allow to modify pse from psesByProduct plugin by event (#3179)
Browse files Browse the repository at this point in the history
  • Loading branch information
lopes-vincent committed Feb 29, 2024
1 parent 2b6f5dc commit e4b2cf4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
31 changes: 31 additions & 0 deletions local/modules/TheliaSmarty/Events/PseByProductEvent.php
@@ -0,0 +1,31 @@
<?php

/*
* This file is part of the Thelia package.
* http://www.thelia.net
*
* (c) OpenStudio <info@thelia.net>
*
* 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;
}
}
9 changes: 9 additions & 0 deletions local/modules/TheliaSmarty/Template/Plugins/FrontUtils.php
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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()
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit e4b2cf4

Please sign in to comment.