Issue
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");
}
}
Solution
I suggest the following steps:
- decorate AbstractCartItemAddRoute
- get parent product of the product which will be added, and ad it instead
- add the actually variant as a child
- add a CartProcessor or decorate the ProductProcessor to calculate the price of the first level item, with the parent product. Which should be the sum of all variant positions
Of course you should check in step 2. if the parent or variant child line item exists and update it instead.
Answered By - Skoenig
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.