# having single row per LineItem with quantity \> 1 in cart view

**URL:** <https://forum.shopware.com/t/having-single-row-per-lineitem-with-quantity-1-in-cart-view/68977>\
**Category:** Programming (EN)\
**Created:** [16. August 2020 um 08:41 UTC](https://forum.shopware.com/t/having-single-row-per-lineitem-with-quantity-1-in-cart-view/68977 "2020-08-16T08:41:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![develissimo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/develissimo/32/12974_2.png) [@develissimo](https://forum.shopware.com/u/develissimo)\
**Post date:** [16. August 2020 um 08:41 UTC](https://forum.shopware.com/t/having-single-row-per-lineitem-with-quantity-1-in-cart-view/68977/1 "2020-08-16T08:41:41Z")

</div>

Hi folks,&nbsp;

please advice best practice to achieve to have a single row per LineItem(s) in cart view if the quantity of LineItem is \> 1.

Right now the cart is showing only one row per LineItem-\>id, which usually is good practice!

Due to the reason as we do enrich LineItems with specific custom payload information (customized&nbsp;product-design), we want the customer to be able to view, update, remove, edit, etc… each LineItem even if the LineItem-\>id is the same.

Please give advice.

Thx in advance and kind regards,

Raphael&nbsp;

---

<div class="post-metadata">

**Author:** ![oliverriske](https://avatars.discourse-cdn.com/v4/letter/o/ebca7d/32.png) [@oliverriske](https://forum.shopware.com/u/oliverriske)\
**Post date:** [16. August 2020 um 08:45 UTC](https://forum.shopware.com/t/having-single-row-per-lineitem-with-quantity-1-in-cart-view/68977/2 "2020-08-16T08:45:18Z")

</div>

Addtocart with stackable=false

---

<div class="post-metadata">

**Author:** ![develissimo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/develissimo/32/12974_2.png) [@develissimo](https://forum.shopware.com/u/develissimo)\
**Post date:** [16. August 2020 um 09:06 UTC](https://forum.shopware.com/t/having-single-row-per-lineitem-with-quantity-1-in-cart-view/68977/3 "2020-08-16T09:06:07Z")

</div>

> [@oliverriske schrieb:](https://forum.shopware.com/profile/33218/oliverriske "oliverriske")
> 
> Addtocart with stackable=false

thanks for your reply, but this will NOT work. will result in „LineItemNotStackableException“.

The way i try to proceed now is as follows:&nbsp;

from here:&nbsp;[https://github.com/shopware/platform/issues/151](https://github.com/shopware/platform/issues/151) =\>&nbsp;

- 
  - If you want to add a product as a single row, simply add generate a unqiue key and provide it as line item key.

if as i understand correct than:&nbsp;referencedId is the true relationship \<=\>&nbsp;productId, we simple have to create a new and unique LineItem-\>key.

I will do so, and report back.

---

<div class="post-metadata">

**Author:** ![develissimo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/develissimo/32/12974_2.png) [@develissimo](https://forum.shopware.com/u/develissimo)\
**Post date:** [16. August 2020 um 09:29 UTC](https://forum.shopware.com/t/having-single-row-per-lineitem-with-quantity-1-in-cart-view/68977/4 "2020-08-16T09:29:27Z")

</div>

```
 Did not expect it to be that easy: id of LineItem has to be a random Uuid to appear as single row. The only important thing is that the referenceId references the correct product. 

 $lineItem = new LineItem(Uuid::randomHex(), "product", NULL, 1);
        $lineItem->setLabel("TEST");
        $lineItem->setGood(false);
        $lineItem->setStackable(true);
        $lineItem->setRemovable(true);
        $lineItem->setReferencedId($productId);
```

---

<div class="post-metadata">

**Author:** ![oliverriske](https://avatars.discourse-cdn.com/v4/letter/o/ebca7d/32.png) [@oliverriske](https://forum.shopware.com/u/oliverriske)\
**Post date:** [16. August 2020 um 10:12 UTC](https://forum.shopware.com/t/having-single-row-per-lineitem-with-quantity-1-in-cart-view/68977/5 "2020-08-16T10:12:42Z")

</div>

Sorry yes forhot that you have to generate a uuid

---

<div class="post-metadata">

**Author:** ![lucamario](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/lucamario/32/15269_2.png) [@lucamario](https://forum.shopware.com/u/lucamario)\
**Post date:** [30. Juli 2021 um 15:35 UTC](https://forum.shopware.com/t/having-single-row-per-lineitem-with-quantity-1-in-cart-view/68977/6 "2021-07-30T15:35:57Z")

</div>

Hey guys,

it can be even easier. Just subscribe to the BeforeLineItemAddedEvent and:

```auto
        if (!$event->getLineItem()->isStackable()) {
            $event->getLineItem()->setId(Uuid::randomHex());
        }

```

Does the exact same as @develissimo stated. However, I think @develissimo wrote a entire new controller. Subscribing to the event is a little more elegant I think.

---

<div class="post-metadata">

**Author:** ![radiy](https://avatars.discourse-cdn.com/v4/letter/r/49beb7/32.png) [@radiy](https://forum.shopware.com/u/radiy)\
**Post date:** [12. November 2021 um 08:34 UTC](https://forum.shopware.com/t/having-single-row-per-lineitem-with-quantity-1-in-cart-view/68977/7 "2021-11-12T08:34:44Z")

</div>

it works. super. thanks
