src/EventSubscriber/ShopIntegrationPlatform/InventorySubscriber.php line 37

  1. <?php
  2. namespace App\EventSubscriber\ShopIntegrationPlatform;
  3. use App\Entity\Product;
  4. use App\Entity\ShopIntegrationPlatform\SipRequestLogger;
  5. use App\Event\InventoryQuantityUpdatedEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use App\ShopIntegrationPlatform\Actions\Api\MassSentRequests\AddRequestAction;
  8. use App\Helper\Common;
  9. class InventorySubscriber implements EventSubscriberInterface
  10. {
  11.     /**
  12.      * @param AddRequestAction $addRequestAction
  13.      */
  14.     public function __construct(
  15.         private readonly AddRequestAction $addRequestAction,
  16.     )
  17.     {
  18.     }
  19.     /**
  20.      * @return array
  21.      */
  22.     public static function getSubscribedEvents(): array
  23.     {
  24.         return [
  25.             InventoryQuantityUpdatedEvent::class => 'inventoryQuantityUpdated'
  26.         ];
  27.     }
  28.     /**
  29.      * @param InventoryQuantityUpdatedEvent $event
  30.      * @return void
  31.      */
  32.     public function inventoryQuantityUpdated(InventoryQuantityUpdatedEvent $event): void
  33.     {
  34.         $this->addRequestAction->run(
  35.             shop$event->getInventory()->getShop(),
  36.             product$event->getInventory()->getProduct(),
  37.             entityNameCommon::getClassNameWithoutNamespace(Product::class),
  38.             entityId$event->getInventory()->getProduct()->getId(),
  39.             commandNameSipRequestLogger::COMMAND_UPDATE_INVENTORY
  40.         );
  41.     }
  42. }