custom/plugins/shopware6-sapoci/src/Subscriber/CheckoutCartSubscriber.php line 30

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Orcamultimedia\OciPunchout\Subscriber;
  4. use Orcamultimedia\OciPunchout\Service\OciService;
  5. use Orcamultimedia\OciPunchout\Struct\OciPunchoutData;
  6. use Shopware\Storefront\Page\Checkout\Cart\CheckoutCartPageLoadedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class CheckoutCartSubscriber implements EventSubscriberInterface
  9. {
  10.     private OciService $ociService;
  11.     public function __construct(
  12.         OciService $ociService
  13.     )
  14.     {
  15.         $this->ociService $ociService;
  16.     }
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             CheckoutCartPageLoadedEvent::class => 'addOciPunchoutPageData',
  21.         ];
  22.     }
  23.     public function addOciPunchoutPageData(CheckoutCartPageLoadedEvent $event): void
  24.     {
  25.         if (!$this->ociService->isPunchout()) {
  26.             return;
  27.         }
  28.         $page $event->getPage();
  29.         $request $event->getRequest();
  30.         $punchoutData = new OciPunchoutData();
  31.         $oci $request->getSession()->get('oci');
  32.         $punchoutData->assign([
  33.             'hookUrl' => $oci['hookUrl'],
  34.             'returnTarget' => $oci['returnTarget'],
  35.             'currencyIsoCode' => $page->getHeader()->getActiveCurrency()->getIsoCode(),
  36.             'lineItems' => $page->getCart()->getLineItems()
  37.         ]);
  38.         $page->addExtension(OciPunchoutData::EXTENSION_NAME$punchoutData);
  39.     }
  40. }