A
A
Alexer052019-07-02 08:34:36
1C-Bitrix
Alexer05, 2019-07-02 08:34:36

CSaleBasket::Update does not update the number of products if the value is less than the current one, what could be causing this?

The CSaleBasket::Update() method does not update the quantity of items if the specified quantity is less than the current one (returns false). If you specify more, the record is updated. If you again specify the number of goods less than it was, then the record is not updated. Because of what it can be, how can you set any number of goods?
I am using the code below:

// Работает, если кол-во больше текущего
CSaleBasket::Update($id, array('QUANTITY' => $quantity));

Also tried to use
// Работает, если кол-во больше изначального в заказе
$basketItem = $basket->getItemById($id);
$basketItem->setField('QUANTITY', $quantity);
$order->save();

But it also doesn't store the number of products if the value is less than the current one. But if you specify the number of goods more, then it allows you to specify the initial value later, but you cannot specify less.
Bitrix 16.5.5

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Gritsuk, 2019-07-02
@Alexer05

$updateResult = CSaleBasket::Update($id, array('QUANTITY' => $quantity));
if(!$updateResult){
    print_r($APPLICATION->LAST_ERROR);
}

$basketItem = $basket->getItemById($id);
$basketItem->setField('QUANTITY', $quantity);
$orderSaveResult = $order->save();
if(!$orderSaveResult->isSuccess()){
    var_dump($orderSaveResult->getErrors());
}

If you don't see anything there, look at the OnBeforeBasketUpdate and OnBeforeBasketUpdateAfterCheck event handlers.
foreach(GetModuleEvents("sale", "OnBeforeBasketUpdate", true) as $arEvent){
    var_dump($arEvent);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question