custom/plugins/NxsDeliveryPriceSorting/src/Communication/Subscriber/CartSubscriber.php line 57

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace  Nxs\NxsDeliveryPriceSorting\Communication\Subscriber;
  3. use Nxs\NxsDeliveryPriceSorting\Business\BusinessFacadeInterface;
  4. use Shopware\Core\Checkout\Cart\Exception\InvalidQuantityException;
  5. use Shopware\Core\Checkout\Cart\Order\CartConvertedEvent;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
  7. use Shopware\Storefront\Page\Checkout\Cart\CheckoutCartPageLoadedEvent;
  8. use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
  9. use Shopware\Storefront\Page\Checkout\Offcanvas\OffcanvasCartPageLoadedEvent;
  10. use Shopware\Storefront\Page\Checkout\Register\CheckoutRegisterPageLoadedEvent;
  11. use Shopware\Storefront\Page\PageLoadedEvent;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  14. class CartSubscriber implements EventSubscriberInterface
  15. {
  16.     /**
  17.      * @var BusinessFacadeInterface
  18.      */
  19.     private $businessFacade;
  20.     public function __construct(BusinessFacadeInterface $businessFacade)
  21.     {
  22.         $this->businessFacade $businessFacade;
  23.     }
  24.     /**
  25.      * @return array
  26.      */
  27.     public static function getSubscribedEvents(): array
  28.     {
  29.         return [
  30.             CheckoutCartPageLoadedEvent::class => 'onCartAccess',
  31.             CheckoutConfirmPageLoadedEvent::class => 'onCartAccess',
  32.             OffcanvasCartPageLoadedEvent::class => 'onCartAccess',
  33.             CheckoutRegisterPageLoadedEvent::class => 'onCartAccess',
  34.             CartConvertedEvent::class => 'onCartCreationInsideOrderProcess',
  35.         ];
  36.     }
  37.     /**
  38.      * @param PageLoadedEvent $event
  39.      */
  40.     public function onCartAccess(PageLoadedEvent $event): void
  41.     {
  42.         try {
  43.             $this->businessFacade->modifyDeliveryPrices($event);
  44.         } catch (InvalidQuantityException NotFoundHttpException InconsistentCriteriaIdsException $e) {
  45.         }
  46.     }
  47.     /**
  48.      * @param CartConvertedEvent $event
  49.      */
  50.     public function onCartCreationInsideOrderProcess(CartConvertedEvent $event): void
  51.     {
  52.         try{
  53.             $this->businessFacade->modifyDeliveryPricesOrderProcess($event);
  54.         } catch (InvalidQuantityException NotFoundHttpException InconsistentCriteriaIdsException $e) {
  55.         }
  56.     }
  57. }