# How to group Products with variation under parent product on Storefront

**URL:** <https://forum.shopware.com/t/how-to-group-products-with-variation-under-parent-product-on-storefront/88606>\
**Category:** Programmierung\
**Tags:** general, programming, other, themes--design, offizielle-shopware-, plugin-wünsche\
**Created:** [25. Juni 2021 um 07:11 UTC](https://forum.shopware.com/t/how-to-group-products-with-variation-under-parent-product-on-storefront/88606 "2021-06-25T07:11:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arash.yazdani59](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/arash.yazdani59/32/13954_2.png) [@arash.yazdani59](https://forum.shopware.com/u/arash.yazdani59)\
**Post date:** [25. Juni 2021 um 07:11 UTC](https://forum.shopware.com/t/how-to-group-products-with-variation-under-parent-product-on-storefront/88606/1 "2021-06-25T07:11:57Z")

</div>

Hi,  
I’m trying to build this page :  
 ![Unbenannt](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/2X/e/e0c485aec9bdf07142e0674554751c8d641579c3.png)  
But i have no idea how to do that, because LineItems with variation are seperated and they not children.  
in Twig i have tried but since LineItems are seperated and there is no id or somthnig i couldn’t do that.  
i tried to add Enitity to LineItems using :

> **[Add cart items](https://developer.shopware.com/docs/guides/plugins/plugins/checkout/cart/add-cart-items)**

but it seems documents are not correct.  
please if anyone had an idea or somthnig please share your code with details  
Thank you.

---

<div class="post-metadata">

**Author:** ![Moritz\_Naczenski](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/moritz_naczenski/32/7792_2.png) [@Moritz\_Naczenski](https://forum.shopware.com/u/Moritz_Naczenski)\
**Post date:** [25. Juni 2021 um 11:19 UTC](https://forum.shopware.com/t/how-to-group-products-with-variation-under-parent-product-on-storefront/88606/2 "2021-06-25T11:19:18Z")

</div>

Custom Products does something similar. With the next version the documents should support nested line items. So if you try out the current development version, it might work.

---

<div class="post-metadata">

**Author:** ![arash.yazdani59](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/arash.yazdani59/32/13954_2.png) [@arash.yazdani59](https://forum.shopware.com/u/arash.yazdani59)\
**Post date:** [30. Juni 2021 um 11:18 UTC](https://forum.shopware.com/t/how-to-group-products-with-variation-under-parent-product-on-storefront/88606/3 "2021-06-30T11:18:03Z")

</div>

unfortunately i can’t use Custom Products because we have a lots of Products that already are placed in the Website.  
I’m trying to do this: 1. if products have a variation and first seven productNumber are the same add a customfield to payload 2. in twig file use that customfield and using for loops and other twig functions to create my custom page

so far i tryed to create a Service :

```auto

use Shopware\Core\Checkout\Cart\Event\CartChangedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class AddDataToPage implements EventSubscriberInterface
{

    public static function getSubscribedEvents()
    {
        return [CartChangedEvent::class => 'onLineItemAdded'];
    }

    /**
     * @param onLineItemAdded $event
     * @throws \Shopware\Core\Checkout\Cart\Exception\InvalidPayloadException
     */
    public function onLineItemAdded(CartChangedEvent $event)
    {
        $myCart = $event->getCart();
        $myLineItems = $myCart->getLineItems();
        $mypayload = $myLineItems->getPayload();
        
       
        foreach ($myLineItems as $lineitem) {
                $lineitem->setPayloadValue("test", array(["aaah"]));
                var_dump($lineitem);

        } 
    }
}

```

there is a problem here that i don’t understand.  
when i use var\_dump($lineitem); i see my $lineitem-\>setPayloadValue(„test“, array([„aaah“])); but in twig when i use dump i don’t see test in payload array.  
any idea why?
