Answer the question
In order to leave comments, you need to log in
How to write a value to the Bitrix property for all products?
Good evening! The problem is that you need to add a value to the property for all products. but is added to only one product if we $arFilter
write "ID"=>"707"
then the value is written to the property. but when I remove this inscription "ID"=>"707"
and the code for writing the value to the properties was executed for all products, it does not work. code below. what's my mistake?
<?
Cmodule::IncludeModule('catalog');
CModule::IncludeModule("iblock");
?>
<?
$arSelect = Array("ID", "IBLOCK_ID", "NAME", "DATE_ACTIVE_FROM","PROPERTY_*");
$arFilter = Array("IBLOCK_ID"=>18, "ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y");
$res = CIBlockElement::GetList(Array(), $arFilter, false, Array("nPageSize"=>50), $arSelect);
while($ob = $res->GetNextElement()){
$arFields = $ob->GetFields();
//print_r($arFields);
echo $arFields[ID];?><br><?
$arProps = $ob->GetProperties();
//print_r($arProps);
//echo $arProps[TSENA_ZA_KG][VALUE];
// предполагаем, что валюты RUB и EUR существуют в базе
$val = $arProps[TSENA_ZA_KG][VALUE]; // сумма в EUR
$newval = round(CCurrencyRates::ConvertCurrency($val, "EUR", "RUB"), 2);
echo $newval;
// добавление в свойство "по цене"
CIBlockElement::SetPropertyValuesEx($arFields[ID], false, array("PRICE_FILTER" => $newval));
$arFields = array("PRICE_FILTER" => $newval);// зарезервированное количество
CCatalogProduct::Update($arFields[ID], $arFields);
}
?>
Answer the question
In order to leave comments, you need to log in
"nPageSize"=>50 - costs 50 products to display. those. actions will be performed only for the first 50 products.
1) Don't forget that array keys are strings. $arProps[TSENA_ZA_KG][VALUE] -> $arProps["TSENA_ZA_KG"]["VALUE"
]
$arFields = array("PRICE_FILTER" => $newval);// зарезервированное количество
CCatalogProduct::Update($arFields["ID"], $arFields);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question