<?php
namespace WbfkExtensions\Documents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Wbfk\DigitalInvoice\Event\DigitalInvoiceShopwareLineItemEvent;
use WbfkExtensions\Core\Checkout\WbfkOrderLineItemExtension\WbfkOrderLineItemExtensionEntity;
class DigitalInvoiceLineItemSubscriber implements EventSubscriberInterface
{
public function __construct()
{
}
public static function getSubscribedEvents(): array
{
return [
DigitalInvoiceShopwareLineItemEvent::class => 'generatedDigitalInvoiceLineItem',
];
}
public function generatedDigitalInvoiceLineItem(DigitalInvoiceShopwareLineItemEvent $event): void
{
$event->orderLineItem->getExtension('wbfkOrderLineItemExtension');
/** @var WbfkOrderLineItemExtensionEntity $wbfkOrderLineItemExtension */
$wbfkOrderLineItemExtension = $event->orderLineItem->getExtension('wbfkOrderLineItemExtension');
if ($wbfkOrderLineItemExtension) {
// Serial Number
$serialNumbers = $wbfkOrderLineItemExtension->getSerialNumbers();
if ($serialNumbers && count($serialNumbers) > 0) {
foreach ($event->documentLineItems as $documentLineItem) {
$documentLineItem->specifiedTradeProduct->sellerAssignedID = join(', ', $serialNumbers);
}
}
}
}
}