|
- <?php
-
- namespace Lc\CaracoleBundle\EventSubscriber\Product;
-
- use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityUpdatedEvent;
- use Lc\CaracoleBundle\Builder\Order\OrderShopBuilder;
- use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
- use Lc\CaracoleBundle\Resolver\MerchantResolver;
- use Lc\CaracoleBundle\Resolver\OpeningResolver;
- use Lc\SovBundle\Translation\FlashBagTranslator;
- use Symfony\Component\EventDispatcher\EventSubscriberInterface;
-
- class UpdateProductfamilyAfterFlushEventSubscriber implements EventSubscriberInterface
- {
- protected OrderShopBuilder $orderShopBuilder;
- protected OpeningResolver $openingResolver;
- protected FlashBagTranslator $flashBagTranslator;
-
- public function __construct(
- OrderShopBuilder $orderShopBuilder,
- OpeningResolver $openingResolver,
- FlashBagTranslator $flashBagTranslator
- )
- {
- $this->orderShopBuilder = $orderShopBuilder;
- $this->openingResolver = $openingResolver;
- $this->flashBagTranslator = $flashBagTranslator;
- }
-
- public static function getSubscribedEvents()
- {
- return [
- AfterEntityUpdatedEvent::class => ['processAfterFlushProductFamily'],
- ];
- }
-
- public function processAfterFlushProductFamily(AfterEntityUpdatedEvent $event)
- {
- $productFamily = $event->getEntityInstance();
- if ($productFamily instanceof ProductFamilyInterface) {
-
-
- foreach ($productFamily->getProductFamilySectionProperties() as $productFamilySectionProperty) {
-
- $section = $productFamilySectionProperty->getSection();
-
- if (!$this->openingResolver->isOpenSale($section)) {
-
- $countOrderProductUpdated = $this->orderShopBuilder->updatePriceByProductFamily($productFamily, $section);
-
- if ($countOrderProductUpdated) {
- $this->flashBagTranslator->add(
- 'success',
- 'orderProductUpdated',
- 'OrderShop',
- array(
- '%count%' => $countOrderProductUpdated,
- '%section%' => $section->getTitle()
- )
- );
- }
-
- }
- }
-
- }
- }
- }
|