M
M
Michael Kim2020-09-21 17:03:27
1C-Bitrix
Michael Kim, 2020-09-21 17:03:27

Why does the product have a zero price?

Catalog with kits and trade offers.
If you add a set to the basket and then a trade offer, then the price is corresponding - 100 rubles.
If you remove the set from the cart, then the price of the added early trade offer is 0r.

What I did:
1. Disabled all the rules for working with the basket.
2. Disabled all event handlers (OnSaleBasketBeforeSaved, OnSaleBasketItemRefreshDataHandler).
3. Cleared the cache on the entire site.
Removed all CustomProviderClass.
The product is added to the cart by calling

Loader::includeModule('catalog');
        Loader::includeModule('sale');

    $price = self::getPriceElement($id, 1);  // возвращает цену, данные берутся из каталога поле BASE_PRICE.

        $arFields = [
            'PRODUCT_ID' => (int)$id,
            'QUANTITY' => (int)$quantity,
            'PRICE' => $price,
            'CURRENCY' => 'RUB',
        ];

        if ($sort > 0)
        {
            $arFields['SORT'] = $sort;
        }

        $obBasket = self::getBasketForCurrentFUser();
    $strategy = \Bitrix\Sale\Basket\RefreshFactory::create(\Bitrix\Sale\Basket\RefreshFactory::TYPE_FULL);
        $items = $obBasket->getBasketItems();

        $bHasItem = false;
        $thisItem = false;
        $itemId = false;

        foreach ($items as $item)
        {
            if ($item->getField('PRODUCT_ID') !== $id) continue;

            $thisItem = $item;
            $bHasItem = true;
            $itemId = $item->getId();
            break;
        }

        $isSuccess = false;
        $rs = false;

        if (! $bHasItem)
        {
            $rs = \Bitrix\Catalog\Product\Basket::addProductToBasketWithPermissions($obBasket, $arFields, ['SITE_ID' => 's3'], false);
        }
        else
        {
            if ($quantity > 0)
            {
                $thisItem->setField('QUANTITY', $quantity);
            }
            else
            {
                $rsDelete = $thisItem->delete();

                $obBasket->refresh($strategy);
                $rsSaved = $obBasket->save();

                return $rsSaved->isSuccess();
            }
        }

        if (!$bHasItem && !$rs->isSuccess())
        {
            self::log($rs->getErrorMessages(), 'logs/erronbasketadd.log');
            return false;
        }

    $obBasket->refresh($strategy);
        $saved = $obBasket->save();


In init.php, there is only the connection of the handlers.php and functions.php files, and below - the registration of custom classes.

Why is this happening?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Kim, 2020-09-21
@devjob

this is the body of the function.
Of course, which is called when items in the cart change (delete, add, update quantity), etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question