No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

69 líneas
2.3KB

  1. <?php
  2. namespace Lc\CaracoleBundle\EventSubscriber\Product;
  3. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityUpdatedEvent;
  4. use Lc\CaracoleBundle\Builder\Order\OrderShopBuilder;
  5. use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
  6. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  7. use Lc\CaracoleBundle\Resolver\OpeningResolver;
  8. use Lc\SovBundle\Translation\FlashBagTranslator;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. class UpdateProductfamilyAfterFlushEventSubscriber implements EventSubscriberInterface
  11. {
  12. protected OrderShopBuilder $orderShopBuilder;
  13. protected OpeningResolver $openingResolver;
  14. protected FlashBagTranslator $flashBagTranslator;
  15. public function __construct(
  16. OrderShopBuilder $orderShopBuilder,
  17. OpeningResolver $openingResolver,
  18. FlashBagTranslator $flashBagTranslator
  19. )
  20. {
  21. $this->orderShopBuilder = $orderShopBuilder;
  22. $this->openingResolver = $openingResolver;
  23. $this->flashBagTranslator = $flashBagTranslator;
  24. }
  25. public static function getSubscribedEvents()
  26. {
  27. return [
  28. AfterEntityUpdatedEvent::class => ['processAfterFlushProductFamily'],
  29. ];
  30. }
  31. public function processAfterFlushProductFamily(AfterEntityUpdatedEvent $event)
  32. {
  33. $productFamily = $event->getEntityInstance();
  34. if ($productFamily instanceof ProductFamilyInterface) {
  35. foreach ($productFamily->getProductFamilySectionProperties() as $productFamilySectionProperty) {
  36. $section = $productFamilySectionProperty->getSection();
  37. if (!$this->openingResolver->isOpenSale($section)) {
  38. $countOrderProductUpdated = $this->orderShopBuilder->updatePriceByProductFamily($productFamily, $section);
  39. if ($countOrderProductUpdated) {
  40. $this->flashBagTranslator->add(
  41. 'success',
  42. 'orderProductUpdated',
  43. 'OrderShop',
  44. array(
  45. '%count%' => $countOrderProductUpdated,
  46. '%section%' => $section->getTitle()
  47. )
  48. );
  49. }
  50. }
  51. }
  52. }
  53. }
  54. }