Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to modify pse from psesByProduct plugin by event #3179

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions local/modules/TheliaSmarty/Events/PseByProductEvent.php
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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