P
P
photosho2020-05-19 12:07:09
1C-Bitrix
photosho, 2020-05-19 12:07:09

How to add a custom field to the cart?

You need to add a text field to the cart. Not a product property, but a separate field in the cart - so that it is filled in on the cart page, but then saved as an order property. What is the best way to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2020-05-19
@anton99zel

So do it:
1. Add a field:
<input type="text" value="Моё отдельное поле">
Pass the value of this field through cookies or through the form using the post method in the code below
2. Update the order properties:

$order = \Bitrix\Sale\Order::load(123); //загрузим номер созданного заказа
$collection = $order->getPropertyCollection();
$propertyValue = $collection->getItemById(10);//id свойства
$r = $propertyValue->setField('VALUE', 'Моё отдельное поле');
if (!$r->isSuccess())
{
    var_dump($r->getErrorMessages());
}
$order->save();

This and other information: https://dev.1c-bitrix.ru/api_d7/bitrix/sale/techni...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question