custom/plugins/SwagB2bPlatform/components/Offer/BridgePlatform/OrderFinishSubscriberDecorator.php line 38

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\B2B\Offer\BridgePlatform;
  3. use Shopware\B2B\Cart\BridgePlatform\CartFinishSubscriber;
  4. use Shopware\B2B\Cart\BridgePlatform\OfferDestination;
  5. use Shopware\B2B\Offer\Framework\OfferRepository;
  6. use Shopware\B2B\Order\Framework\OrderContext;
  7. use Shopware\Core\Checkout\Cart\Cart;
  8. use Shopware\Core\Checkout\Cart\Order\CartConvertedEvent;
  9. use Shopware\Core\Checkout\Order\OrderEntity;
  10. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  11. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  12. class OrderFinishSubscriberDecorator extends CartFinishSubscriber
  13. {
  14.     /**
  15.      * @var CartFinishSubscriber
  16.      */
  17.     private $inner;
  18.     /**
  19.      * @var OfferRepository
  20.      */
  21.     private $offerRepository;
  22.     public function __construct(
  23.         CartFinishSubscriber $inner,
  24.         OfferRepository $offerRepository,
  25.         EventDispatcherInterface $eventDispatcher
  26.     ) {
  27.         $this->inner $inner;
  28.         $this->offerRepository $offerRepository;
  29.         parent::__construct($eventDispatcher);
  30.     }
  31.     public function initializeState(CartConvertedEvent $event): void
  32.     {
  33.         $this->cartConvertedEvent $event;
  34.         $this->inner->initializeState($event);
  35.     }
  36.     /**
  37.      * @internal
  38.      */
  39.     protected function onCartFinish(
  40.         Cart $cart,
  41.         OrderEntity $orderEntity,
  42.         SalesChannelContext $salesChannelContext
  43.     ): ?OrderContext {
  44.         $orderContext $this->inner->onCartFinish($cart$orderEntity$salesChannelContext);
  45.         if ($orderContext === null) {
  46.             return null;
  47.         }
  48.         /** @var OfferDestination $offerDestination */
  49.         $offerDestination $this->getCartState()->getDestination();
  50.         if (!$offerDestination instanceof OfferDestination) {
  51.             return null;
  52.         }
  53.         $offer $offerDestination->getOfferEntity();
  54.         $offer->updateDates(['convertedAt']);
  55.         $this->offerRepository->updateOfferDates($offer);
  56.         return $orderContext;
  57.     }
  58. }