Добрый день.
Уже не помню, как именно решил проблему, но вот полный код, возможно поможем вам
Уже не помню, как именно решил проблему, но вот полный код, возможно поможем вам
Код |
---|
$arResult = ['result' => false, 'DELIVERY_ID' => $delivery_id]; $basket = Sale\Basket::loadItemsForFUser(Sale\Fuser::getId(), Bitrix\Main\Context::getCurrent()->getSite()); if($basketItem = $basket->getExistsItem('catalog', $productId)){ $res = $basketItem->setField('QUANTITY', $quantity); if (!$res->isSuccess()){ $arResult['ERROR'] = $res->getErrorMessages(); }else{ $res = $basket->save(); if (!$res->isSuccess()){ $arResult['ERROR'] = $res->getErrorMessages(); $arResult['ERROR_UPDATE'] = $res->getErrorMessages(); }else{ $arResult['result'] = true; } } }else { $item = $basket->createItem('catalog', $productId); $arPrice = getProductPrice($productId); $item->setFields(array( 'QUANTITY' => $quantity, 'BASE_PRICE' => $arPrice['BASE_PRICE'], 'PRICE' => $arPrice['DISCOUNT_PRICE'], 'DISCOUNT_PRICE' => $arPrice['DISCOUNT'], 'CUSTOM_PRICE' => 'Y', 'CURRENCY' => Bitrix\Currency\CurrencyManager::getBaseCurrency(), 'LID' => Bitrix\Main\Context::getCurrent()->getSite(), 'PRODUCT_PROVIDER_CLASS' => 'CCatalogProductProvider', )); $res = $basket->save(); if (!$res->isSuccess()) { $arResult['ERROR'] = $res->getErrorMessages(); $arResult['ERROR_ADD'] = $res->getErrorMessages(); } else { $arResult['result'] = true; $basketItem = $basket->getExistsItem('catalog', $productId); $arResult['id'] = $basketItem->getId(); } } |