Hi,
I need to add a Custom Id to LineItem(s) that are variations (color, size) of a Parent Line item.
Since Now i tryed this:
use Shopware\Core\Checkout\Cart\Event\BeforeLineItemAddedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AddDataToPage implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [BeforeLineItemAddedEvent::class => 'onLineItemAdded'];
}
/**
* @param onLineItemAdded $event
* @throws \Shopware\Core\Checkout\Cart\Exception\InvalidPayloadException
*/
public function onLineItemAdded(BeforeLineItemAddedEvent $event)
{
$lineitems = $event->getLineItem();
$event->isMerged() == true;
$payloaditem = $lineitems->getPayload();
// I'm stuck here i want to do this: if lineitem is a variation add customfield to lineitem with variation and his parent
if($lineitems->getReferencedId() == "df50709c534e499488c6fe02312ca526"){
$lineitems->setPayloadValue("myChilds", true);
}
else{
$lineitems->setPayloadValue("myChilds", false);
}
}
}
Unfortunately there is nothing Common between Line Item(s) with variations.
Does anyone have an Idea?