src/EventSubscriber/QuotationUpdatedEventSubscriber.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Event\QuotationUpdatedEvent;
  4. use App\Service\UserLog;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class QuotationUpdatedEventSubscriber implements EventSubscriberInterface
  8. {
  9.     protected $em;
  10.     protected $userLog;
  11.     public function __construct(
  12.         EntityManagerInterface $em,
  13.         UserLog             $userLog
  14.     )
  15.     {
  16.         $this->userLog $userLog;
  17.         $this->em $em;
  18.     }
  19.     public static function getSubscribedEvents(): array
  20.     {
  21.         return [
  22.             QuotationUpdatedEvent::REQUESTED_QUANTITIES => [
  23.                 ['updateTargetPrices'],
  24. //                ['logAction']
  25.             ]
  26.         ];
  27.     }
  28.     public function updateTargetPrices(QuotationUpdatedEvent $event)
  29.     {
  30.         $quotation $event->getQuotation();
  31.         foreach ($quotation->getCustomerTargetPrices() as $targetPrice) {
  32.             $prices $targetPrice->getPrice();
  33.             foreach ($quotation->getRequestedQuantities() as $quantity) {
  34.                 if (!isset($prices[$quantity['value']])) {
  35.                     $prices[$quantity['value']] = null;
  36.                 }
  37.             }
  38.             $targetPrice->setPrice($prices);
  39.         }
  40.         $this->em->flush();
  41.     }
  42. //    public function logAction(QuotationUpdatedEvent $event)
  43. //    {
  44. //        $quotation = $event->getQuotation();
  45. //
  46. //        $this->userLog->log(
  47. //            'quotation',
  48. //            QuotationUpdatedEvent::REQUESTED_QUANTITIES,
  49. //            $quotation->getId(),
  50. //            'Quotation updated.  #' . $quotation->getOrderNumber()
  51. //        );
  52. //    }
  53. }