R
R
ragnar_ok2018-09-02 12:31:04
1C-Bitrix
ragnar_ok, 2018-09-02 12:31:04

Bitrix: CSaleBasket::Update - why is the quantity being modified, but the price is not?

Created a handler file. The quantity in the cart is updated, but the price is not. Why is unclear.

<?
require_once($_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/include/prolog_before.php");
if(CModule::IncludeModule('sale')){
    $arBasketItems = array();
    $dbBasketItems = CSaleBasket::GetList(
        array(
            "NAME" => "ASC",
            "ID" => "ASC"
        ),
        array(
            "FUSER_ID" => CSaleBasket::GetBasketUserID(),
            "LID" => SITE_ID,
            "ORDER_ID" => "NULL",
            "PRODUCT_ID" => $_POST['id']
        ),
        false,
        false,
        array("ID", "PRODUCT_ID", "QUANTITY", "PRICE", "NAME")
    );
    while ($arItems = $dbBasketItems->Fetch()) {
        $arBasketItems[] = $arItems;
    }
}
$price = (int)$arBasketItems[0]['PRICE'];
$count = (int)$arBasketItems[0]['QUANTITY'];
if (CModule::IncludeModule("catalog"))
{
    if($_POST['type']=='min'){
        $arFields = array(
            "QUANTITY" => $count-1,
            "PRICE" => $price-1
        );
    }
    if($_POST['type']=='plus'){
        $arFields = array(
            "QUANTITY" => $count + 1,
            "PRICE" => $price+1
        );
    }
    $ID = CSaleBasket::Update($arBasketItems[0]['ID'], $arFields);
}
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
ragnar_ok, 2018-09-02
@ragnar_ok

Here is the answer:

$arFields = array(
            "CALLBACK_FUNC" => "",
            "PRODUCT_PROVIDER_CLASS" => "",
            "CUSTOM_PRICE"      => "Y",
            "IGNORE_CALLBACK_FUNC"  => "Y"
        );

There are two options: "CUSTOM_PRICE", "IGNORE_CALLBACK_FUNC". They allow you to disable GetOptimalPrice and use a custom price.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question