A
A
Alexey Kot2018-05-08 10:12:13
1C-Bitrix
Alexey Kot, 2018-05-08 10:12:13

How to bulk add a price to all products in the infoblock in Bitrix?

Hey! I have an infoblock with product sections. The task is to add (do not change, there is no price at all) the same price (BASE) to all products in each category of the given infoblock. In order not to do it manually for hundreds of positions.
How can I do that?
I see that there is the following CPrice::Add method , but since Bitrix is ​​something completely new for me, I don’t know how to adapt it to the entire product catalog.
Maybe it's generally a SQL query can be done?
Let's say to make everyone the price of 1 rub.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasya, 2018-05-08
@haramba

Do it yourself, I'm on mobile.
You can also omit CPrice::GetList with an update or take it out of the loop, having previously collected the element IDs.
If there are many elements, then split the execution into parts, or the 4th parameter nPageSize, iNumPage. or read IDs once into session/file,

$PRICE_TYPE_ID = 1;
$IBLOCK_ID = 8;


$res = CIBlockElement::GetList([], ["IBLOCK_ID" => $IBLOCK_ID], false, false, ["ID"]);
while ($item = $res->Fetch())
{
$PRODUCT_ID = $item["ID"];
$arFields = Array(
    "PRODUCT_ID" => $PRODUCT_ID,
    "CATALOG_GROUP_ID" => $PRICE_TYPE_ID,
    "PRICE" => 1,
    "CURRENCY" => "RUB",
);

$res = CPrice::GetList(
        array(),
        array(
                "PRODUCT_ID" => $PRODUCT_ID,
                "CATALOG_GROUP_ID" => $PRICE_TYPE_ID
            )
    );

if ($arr = $res->Fetch())
{
    CPrice::Update($arr["ID"], $arFields);
}
else
{
    CPrice::Add($arFields);
}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question