S
S
Smeecy Smeecy2021-06-28 22:28:59
1C-Bitrix
Smeecy Smeecy, 2021-06-28 22:28:59

Why is the product not being added to the cart?

The product is not added to the cart when you click on the "Add to cart" button, plus the error Warning: Static call CUser::IsAuthorized() is deprecated, will be removed soon. Use global $USER. in /home/bitrix/www/bitrix/modules/main/classes/general/user.php on line 2853.
When executing the command in the php command line, it gives:
Error adding product 86333 to the cart: Error getting the price of the product "DIAM drilling machine ML-180N"

$productId = 86333;

if (!\Bitrix\Main\Loader::includeModule('catalog')) {
    throw new \Bitrix\Main\SystemException('Ошибка подключения модуля "catalog"');
}

$addResult = Add2BasketByProductID(
    $productId, 
    1, 
    [
        'LID' => 's1',
    ], 
    []
);

if (!$addResult) {

    $strError = '';

    /** @global $APPLICATION $ex */
    if ($ex = $APPLICATION->GetException()) {
        $strError = $ex->GetString();
    }

    echo sprintf('Ошибка добавления товара %s в корзину: %s', $productId, $strError);

} else {

    echo sprintf('Товар %s успешно добавлен в корзину', $productId);

}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question