M
M
Mikhail Smirnov2019-02-27 15:56:52
1C-Bitrix
Mikhail Smirnov, 2019-02-27 15:56:52

Why is the product unavailable after adding?

There is a code that adds a product to the product catalog
and immediately after that the product is added to the order basket

$el = new \CIBlockElement;

        $arFields = [
            "CREATED_BY" => $USER->GetID(),
            "MODIFIED_BY" => $USER->GetID(),
            "ACTIVE" => 'Y',
            "IBLOCK_SECTION_ID" => $_POST['NewProduct']['SECTION_ID'],
            "IBLOCK_ID" => CATALOG_ID,
            "NAME" => trim($_POST['NewProduct']['NAME']),
            "SORT" => 100,
        ];

        $productId = $el->Add($arFields);

The product is added to the catalog without problems, but the product is not added to the order basket.
And no errors, there are no errors when adding to the basket $basketItem->save(); returns true, but nothing is actually added.
But if you add a product to the catalog in this way, then start re-indexing in the shopping catalog settings, then the product is already added to the order basket.
what could be the problem? Is it possible to somehow index the product after adding it to the catalog?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
unsweet, 2019-02-28
@unsweet

Before adding it to the cart, use the CCatalogProduct::Add method. It will add product parameters to the catalog item.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question