custom/static-plugins/CioFormBuilder/src/Subscriber/CartDebugSubscriber.php line 27

Open in your IDE?
  1. <?php
  2. namespace CioFormBuilder\Subscriber;
  3. use Psr\Log\LoggerInterface;
  4. use Shopware\Core\Checkout\Cart\Event\CartProcessedEvent;
  5. use Shopware\Core\Checkout\Cart\LineItem\LineItem;
  6. use Shopware\Core\Framework\Event\FlowEventAware;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class CartDebugSubscriber implements EventSubscriberInterface
  9. {
  10.     private LoggerInterface $logger;
  11.     public function __construct(LoggerInterface $logger)
  12.     {
  13.         $this->logger $logger;
  14.     }
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             CartProcessedEvent::class => 'onCartProcessed',
  19.         ];
  20.     }
  21.     public function onCartProcessed(CartProcessedEvent $event): void
  22.     {
  23.         $cart $event->getCart();
  24.         foreach ($cart->getLineItems() as $item) {
  25.             if (!$item instanceof LineItem) {
  26.                 continue;
  27.             }
  28.             $payload $item->getPayload() ?? [];
  29.             $cf $payload['customFields'] ?? [];
  30.             $isPod $cf['custom_pod_products_isPodProduct'] ?? null;
  31.             $hasSurcharges = !empty($cf['cioFormSurcharges']);
  32.             $price $item->getPrice();
  33.             $priceDef $item->getPriceDefinition();
  34.             $this->logger->info('[CIO-AI-Driven] CartProcessed.debug', [
  35.                 'lineItemId' => $item->getId(),
  36.                 'referencedId' => $item->getReferencedId(),
  37.                 'isPod' => $isPod,
  38.                 'hasSurcharges' => $hasSurcharges,
  39.                 'priceDefinitionClass' => $priceDef get_class($priceDef) : null,
  40.                 'priceDefinition' => $priceDef ? [
  41.                     'price' => method_exists($priceDef'getPrice') ? $priceDef->getPrice() : null,
  42.                     'qty' => method_exists($priceDef'getQuantity') ? $priceDef->getQuantity() : null,
  43.                 ] : null,
  44.                 'calculatedPrice' => $price ? [
  45.                     'unitPrice' => $price->getUnitPrice(),
  46.                     'totalPrice' => $price->getTotalPrice(),
  47.                     'taxes' => $price->getCalculatedTaxes(),
  48.                     'taxRules' => $price->getTaxRules(),
  49.                     'quantity' => $price->getQuantity(),
  50.                 ] : null,
  51.             ]);
  52.         }
  53.     }
  54. }