您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

UpdateProductfamilyAfterFlushEventSubscriber.php 2.3KB

3 年前
2 年前
3 年前
2 年前
3 年前
2 年前
3 年前
2 年前
3 年前
2 年前
3 年前
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. }