Shopware 6 Payload of order line item is not updated

Hello guys,

I try to update a cart line item’s payload in checkout which seems ok after setting the payload of the line item, I dump the payload value and see that it was set.
But when I create the order I can’t see that new payload key/value in related order item’s payload field.

Here is how I set the payload value in my controller:

$lineItemData->setPayloadValue('test_payload', "test value");

I have tried the lines below but no luck:

$lineItemData->markModified();
$cart->markModified();
$this->cartService->recalculate($cart, $context);

Am I missing something?
Did anyone encounter same/similar problem?
How can I make sure that the payload I set in cart line item is passed to order line item?

Regards

Tunçer

2 „Gefällt mir“

Same question here. Are there any updates or docs on this?

if i remember correctly recalculate creates a new cart. So you should do the following:

$cart = $this->cartService->recalculate($cart, $context);

What we did was setting the value in a hidden input field and then reading it via POST parameters in OrderController.

right. the main „problem“ is PHP.
when you fetch the lineItem you will a get copy and NOT a reference. So you need to replace the changed item (here you changed the payload) before doing the recalc. Anyway the same for the items you fetched from the cart.

$lineItems = $cart->getLineItems();
$productId = "abcd";
$item = $lineItems->get($productId);
// here manipulate the $item
// ...
// and then push back the item
$lineItems->set($productId, $item);
// ...
// and push the items to the cart
$cart->setLineItems($lineItems);
// ...
1 „Gefällt mir“

Hi,
unfortunately that doesnt work for me. I also tried to use

    $this->cartService->setCart($cart);

on top of your suggestion to make sure the updated is reflected. However inspite of doing that in my controller in the twig template that is then loaded i still get the old values.

Any other idea?

Thanks!
Tom

you might do something like:

$lineItem->markModified();
$lineItems->set($lineItem->getId(), $lineItem);
...
// 3rd parameter as the Cart
$toCalculate->setLineItems($lineItems);
$toCalculate->markModified();

Another thing what is important to find the right priority in the marking of the service. Here a prio which I mostly use :

<tag name="shopware.cart.processor" priority="4950"/>

(I think there is a list somewhere for the chain of core-processors)