# How can we set custom fields per cart line item?

**URL:** <https://forum.shopware.com/t/how-can-we-set-custom-fields-per-cart-line-item/62122>\
**Category:** Shopware 6 (English)\
**Created:** [3. Oktober 2019 um 07:58 UTC](https://forum.shopware.com/t/how-can-we-set-custom-fields-per-cart-line-item/62122 "2019-10-03T07:58:08Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![mowlwurf](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@mowlwurf](https://forum.shopware.com/u/mowlwurf)\
**Post date:** [10. Februar 2020 um 06:45 UTC](https://forum.shopware.com/t/how-can-we-set-custom-fields-per-cart-line-item/62122/5 "2020-02-10T06:45:03Z")

</div>

The CartLineItems have a property named payload where product custom fields and such things are stored within. In my case I used the&nbsp;LineItemAddedEvent to modify this payload.

e.g.

```
    /**
     * @param LineItemAddedEvent $event
     * @throws \Shopware\Core\Checkout\Cart\Exception\InvalidPayloadException
     */
    public function onLineItemAdded(LineItemAddedEvent $event): void
    {
        $lineItem = $event->getLineItem();
        foreach ($this->requestStack->getCurrentRequest()->get('lineItems') as $key => $item) {
            if ($lineItem->getId() == $key && isset($item['anotherCartFormValue'])) {
                $lineItem->setPayloadValue('anotherCartFormValue', $item['anotherCartFormValue']);
            }
        }

        // or do some other stuff with the payload
    }

```

This payload will be used in any step of the checkout without getting overwritten anymore, and is stored in the cart table.

---

_[View the full topic](https://forum.shopware.com/t/how-can-we-set-custom-fields-per-cart-line-item/62122)._
