Answer the question
In order to leave comments, you need to log in
How to create property from property with multiple value and update after exchange?
The product has the property "details"
How can I take one subproperty from there and enter it as a separate property of the product, while updating it during the exchange and not touching it again?
Answer the question
In order to leave comments, you need to log in
VicTHOR , in general terms, I see this:
1) creating the OnAfterIBlockElementAdd handler in init.php (after creating the element)
and OnAfterIBlockElementUpdate (changing the element) during the exchange
2) Getting the Details data in the CIBlockElement::GetPropertyValues handler (for a multiple property of the string type)
3 ) CIBlockElement::SetPropertyValues (Set a new value for this property of this element)
There was such a task when exchanging with 1s. The weight was unloaded in the form of props. Here is the complete code for getting the given value and updating it in another sv.
$db_res = CIBlockElement::GetList(
array(),
array('IBLOCK_ID' => 1, 'IBLOCK_TYPE' => 'catalog', 'ACTIVE' => 'Y'),
false,
false
);
while ($ar_res = $db_res->Fetch())
{
if(isset($ar_res['IBLOCK_SECTION_ID'])){
$ID = $ar_res['ID'];
// все поля
$ar_res2 = CCatalogProduct::GetByIDEx($ID);
$property_enums = CIBlockPropertyEnum::GetList(Array("DEF" => "DESC", "SORT" => "ASC"), Array("IBLOCK_ID" => $ar_res["IBLOCK_ID"], "CODE" => "VES"));
$arPropertyArchive = [];
while($enum_fields = $property_enums->GetNext()) {
/* Если значение равно "Да" */
if ($enum_fields["VALUE"] == $ar_res2['PROPERTIES']['CML2_TRAITS']['VALUE']) {
$arPropertyArchive = Array(
"VES" => $enum_fields["ID"],
);
break;
}
}
if(empty($arPropertyArchive)){
$ibpenum = new CIBlockPropertyEnum;
$PropID = $ibpenum->Add(Array('PROPERTY_ID'=> 396, 'VALUE'=>$ar_res2['PROPERTIES']['CML2_TRAITS']['VALUE']));
$arPropertyArchive = array(
'VES' => $PropID
);
}
CIBlockElement::SetPropertyValuesEx($ar_res['ID'], $ar_res['IBLOCK_ID'], $arPropertyArchive, ['DoNotValidateLists']);
echo "========================================================================";
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question