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

Hi folks, 

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 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 

Addtocart with stackable=false

1 „Gefällt mir“

@oliverriske schrieb:

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: 

from here: https://github.com/shopware/platform/issues/151 => 

    • 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: referencedId is the true relationship <=> productId, we simple have to create a new and unique LineItem->key.

I will do so, and report back.

 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);
1 „Gefällt mir“

Sorry yes forhot that you have to generate a uuid

Hey guys,

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

        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.

it works. super. thanks