<?php declare(strict_types=1);
namespace AcidSplitCartCheckout\Subscriber;
use AcidSplitCartCheckout\Service\SplitCartService;
use Shopware\Storefront\Page\Checkout\Finish\CheckoutFinishPageLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CheckoutFinishPageSubscriber implements EventSubscriberInterface
{
protected SplitCartService $splitCartService;
public function __construct(SplitCartService $splitCartService)
{
$this->splitCartService = $splitCartService;
}
public static function getSubscribedEvents()
{
return [
CheckoutFinishPageLoadedEvent::class => 'onCheckoutFinishPageLoaded'
];
}
public function onCheckoutFinishPageLoaded(CheckoutFinishPageLoadedEvent $event)
{
$order = $event->getPage()->getOrder();
$order->addExtension(
"acid_split_summary",
$this->splitCartService->calculateOrderSummary(
$event->getPage()->getOrder()->getLineItems(),
$event->getPage()->getOrder()->getDeliveries(),
$event->getSalesChannelContext()
)
);
$order->addExtension(
"acid_split_items",
$this->splitCartService->collectSplitItems(
$event->getPage()->getOrder()->getLineItems(),
$event->getSalesChannelContext()
)
);
if($splittedOrder = $this->splitCartService->getSplittedStoreOrder($order->getId())) {
$order->addExtension(
"acid_splitted_store_order",
$splittedOrder
);
}
}
}