vendor/store.shopware.com/swagb2bplatform/components/Offer/BridgePlatform/OrderFinishSubscriberDecorator.php line 32

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.     private CartFinishSubscriber $inner;
  15.     private OfferRepository $offerRepository;
  16.     public function __construct(
  17.         CartFinishSubscriber $inner,
  18.         OfferRepository $offerRepository,
  19.         EventDispatcherInterface $eventDispatcher
  20.     ) {
  21.         $this->inner $inner;
  22.         $this->offerRepository $offerRepository;
  23.         parent::__construct($eventDispatcher);
  24.     }
  25.     public function initializeState(CartConvertedEvent $event): void
  26.     {
  27.         $this->cartConvertedEvent $event;
  28.         $this->inner->initializeState($event);
  29.     }
  30.     /**
  31.      * @internal
  32.      */
  33.     protected function onCartFinish(
  34.         Cart $cart,
  35.         OrderEntity $orderEntity,
  36.         SalesChannelContext $salesChannelContext
  37.     ): ?OrderContext {
  38.         $orderContext $this->inner->onCartFinish($cart$orderEntity$salesChannelContext);
  39.         if ($orderContext === null) {
  40.             return null;
  41.         }
  42.         /** @var OfferDestination $offerDestination */
  43.         $offerDestination $this->getCartState()->getDestination();
  44.         if (!$offerDestination instanceof OfferDestination) {
  45.             return null;
  46.         }
  47.         $offer $offerDestination->getOfferEntity();
  48.         $offer->updateDates(['convertedAt']);
  49.         $this->offerRepository->updateOfferDates($offer);
  50.         return $orderContext;
  51.     }
  52. }