D
D
digamer2020-06-02 07:20:28
PHP
digamer, 2020-06-02 07:20:28

How to update the quantity of goods in stock in the Bitrix Small Business edition?

Bitrix edition - Small business. Warehouse 1.

Task. When adding / updating a product, take "Parameters - available quantity" that comes from 1s and insert it into Warehouses - quantity of goods.

I tried to do it with various events, it did not work.

$arFieldsStoreAmount = Array(
                "PRODUCT_ID" => $arFields['ID'],
                "STORE_ID" => STORE_ID,
                "AMOUNT" => $arFields["QUANTITY"]
            );
            $amount = \CCatalogStoreProduct::Add($arFieldsStoreAmount);

When adding a product, the code is executed, it returns the id, but the entry in b_catalog_store_product does not go through.

If I explicitly enter in the PHP command line:

$arFieldsStoreAmount = Array(
                "PRODUCT_ID" => 544,
                "STORE_ID" => 1,
                "AMOUNT" => 33
            );
            $amount = \CCatalogStoreProduct::Add($arFieldsStoreAmount);


That record in basis perfectly happens.

What to do, who got out how, or in this edition there is no point in messing with this task at all?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
digamer, 2020-06-03
@digamer

In general, I agreed that instead of incomprehensible crutches, the easiest way would be to set the external code of the warehouse in Bitrix from 1c, and in the unload settings, check the box "Unload leftovers from warehouses". Should earn.
APD. In 1s, I made an unloading with a checkmark "Upload balances by warehouses" to a file on your computer. In this file, I found the Warehouse ID and entered it in the "External code" field on the site. Everything worked.
So there is no need to invent anything in terms of code, everything has already been invented before us.

A
Anton, 2020-06-02
@anton99zel

Here is a working example for you, add a warehouse and fire from 1s get requests
$iOstatok - Quantity in stock
$iElementID - product id
$iBlock - infoblock

if (isset($iOstatok)) {
        if ($iOstatok > 0) {
            $el = new CIBlockElement;
            /*активировать, если деактивирована*/
            if ($ar_res["ACTIVE"] == "N") {
                /*активировать*/
                $arLoadProductArray = Array(
                    "IBLOCK_SECTION_ID" => false,
                    "IBLOCK_ID" => $iBlock,
                    "ACTIVE" => "Y"
                );
                $el->Update($iElementID, $arLoadProductArray);
            }
            Cmodule::IncludeModule('catalog');
            $arFields = array("QUANTITY" => $iOstatok);
            CCatalogProduct::Update($iElementID, $arFields);
            //$el->SetPropertyValues($iElementID, $iBlock, $iOstatok, "QUANTITY");
            /*обновление остатков*/
        } else {
            /*обновление остатков*/
            Cmodule::IncludeModule('catalog');
            $el = new CIBlockElement;
            $arFields = array("QUANTITY" => $iOstatok);
            CCatalogProduct::Update($iElementID, $arFields);
        }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question