I'm trying to build this Page in shopware 6:
but since in shopware 6 Products with Variation are sperated (picture below) i couldn't do that.
I need to group Products with variation under Parent Product. Does anyone have an idea?
The Subscriber that I'm working on now:
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();
// I need a [IF] here: if product has a variation and parent product id is the same add the code below
$lineitems->setPayloadValue("myVar", "test2");
}
}
I suggest the following steps:
Of course you should check in step 2. if the parent or variant child line item exists and update it instead.