E
E
Ex1st2021-04-02 10:12:49
1C-Bitrix
Ex1st, 2021-04-02 10:12:49

Add2BasketByProductID refuses to add properties?

subject.

We need to add properties coming from the front via AJAX. I act as it is written in the documentation:

if (!Add2BasketByProductID($_REQUEST["item"], $_REQUEST["quantity"], array(), array(
                    array(
                        "NAME" => "Цвет",
                        "CODE" => "CLR",
                        "VALUE" => "красный"
                    )
                ))) {
                    if ($ex = $APPLICATION->GetException())
                        $strErrorExt = $ex->GetString();

                    $strError = "ERROR_ADD2BASKET";
                    $successfulAdd = false;
                }


Goods are added, but the property is not (I check against the records in the b_sale_basket_props table)

In which direction to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Gritsuk, 2021-04-02
@Ex1st

Use the new API.
Examples of working with a shopping cart and cart properties
Getting a BUYER 's cart

/*
 * $fuser - ID пользователя
 * $siteId - ID сайта, к которому привязана корзина
 */
$basket = \Bitrix\Sale\Basket::loadItemsForFUser($fuser, $siteId);

Adding a product:
$basketItem = $basket->createItem($moduleId, $productId);
$basketItem->setField('QUANTITY', 4);

Adding a property
$collection = $basketItem->getPropertyCollection();

$item = $collection->createItem();
$item->setFields([
    'NAME' => 'Новое свойство',
    'CODE' => 'XXX',
    'VALUE' => 'Значение',
]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question