E
E
Eugene M.2020-01-09 16:36:16
1C-Bitrix
Eugene M., 2020-01-09 16:36:16

How to write a property to several products in Bitrix through an SQL query?

How to write a property to several products in Bitrix through an SQL query? That is, the property already exists, you need to write the correct value from the list, how to do this, it seems like it can and should not be difficult!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Andrey Nikolaev, 2020-01-09
@gromdron

TLDR; Loop through the elements to change the property.
In fact, figuratively speaking - no way.
You can write a specific solution for your structure, but there is no way to fit it into the request (at least a procedure).
The thing is that, depending on the type of infoblock, you can store property values ​​either in one table or in separate ones.
If the record is in the same table, then you will first need to look for the property ID, and only then update several elements and add elements where this property does not exist.
In the case of storage in a separate table, the algorithm is almost the same, except that you need to look not for the value of the property, but for the entry of the element in the table, taking into account that these are not multiple properties.

A
Alexander, 2020-01-09
Madzhugin @Suntechnic

I will add to Andrey's answer (in principle, completely correct) that you should not even try to do this at all - use the API and you will insure yourself against many problems in the future.
If you need an action as a transaction - this can be arranged: google "StartTransaction"

A
Anton, 2020-01-09
@anton99zel

You can’t do it through SQL, if only because there may be dependencies in different tables. Then get errors and glitches.
The property can be assigned like this:
https://dev.1c-bitrix.ru/api_help/iblock/classes/c... You
can run the code above by looping through the GetList, selecting the elements you need
https://dev.1c-bitrix. ru/api_help/iblock/classes/c
...

<?
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php");
//это просто нужно
CModule::IncludeModule("catalog");
// подключаем модуль каталога
$arSelect = Array("ID", "IBLOCK_ID", "CATALOG_PRICE_1");
// выбираем поля
$arFilter = Array("IBLOCK_ID"=>8, "CATALOG_PRICE_1" => '9000');
// фильтруем, выбирая инфоблок и товары с ценой в 9000 рублей, сюда же можно вписать свойства
$resw = CIBlockElement::GetList(Array(), $arFilter, false, Array("nPageSize"=>1000000), $arSelect);
while($ob = $resw->GetNextElement()){ 
 $arFields = $ob->GetFields();  
 $arProps = $ob->GetProperties(); 
{
//echo $arFields[ID].' - '.$arFields['CATALOG_PRICE_1'].'</br>';
$PRODUCT_ID = $arFields[ID];
$PRICE_TYPE_ID = 1;
$arFields = Array(
    "PRODUCT_ID" => $PRODUCT_ID,
    "CATALOG_GROUP_ID" => $PRICE_TYPE_ID,
    "PRICE" => '9500', //повысим цены с 9000 до 9500
    "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);
};
}
};

V
Viktor Taran, 2020-01-10
@shambler81

on any CMS in any documentation you will see "use API methods"
, especially with a database in which there is a table dependency.
Therefore, if you want to make a direct query to the database, you are either trying to do something crazy
or you are wrong.
To do this, you have the standard Bitrix api methods, working with them guarantees that when the engine is updated, your art will continue to work (gee-gee and a big asterisk in small text)
Also, do not forget that Bitrix is ​​developing along with this and the structure of the database itself is changing .
So the answer is no way
Because you could not motivate the reason for such actions.
well, if you just really use custom hiload blocks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question