PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 12, 2022

[FIXED] Shopware6: How to add Products with variation as childrens to Parent Products in LineItems

 March 12, 2022     shopware, symfony, symfony5     No comments   

Issue

I'm trying to build this Page in shopware 6:

Product with Variation in Warencorb

but since in shopware 6 Products with Variation are sperated (picture below) i couldn't do that.

Symfony Shopware6 LineItems

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:

  1. decorate AbstractCartItemAddRoute
  2. get parent product of the product which will be added, and ad it instead
  3. add the actually variant as a child
  4. 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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing