Answer the question
In order to leave comments, you need to log in
How can I update the product price after the OnAfterIBlockElementUpdate event?
The task when changing one of the properties of a product in the admin panel (this property is the cost of the product in currency), you automatically need to update the price of the product (recalculate the price from the Price property in currency and save it in the price).
As I understand it, for this you need to run the OnAfterIBlockElementUpdate event handler for the information block. Below is my code
AddEventHandler('iblock', 'OnAfterIBlockElementUpdate', array("IblockHandler", "UpdateElement"));
class IblockHandler {
// создаем обработчик события "OnAfterIBlockElementUpdate"
public function UpdateElement(&$arFields){
setLog($arFields['ID']);
self::_updateField($arFields);
}
static private function _updateField($arFields) {
CModule::IncludeModule("catalog");
$arField = Array(
"PRODUCT_ID" => $arFields['ID'],
"CATALOG_GROUP_ID" => 1,
"PRICE" => '2', // тестовое значение цены товара
"CURRENCY" => "RUB"
);
$res = CPrice::GetList(array(),array("PRODUCT_ID" => $arFields['ID'], "CATALOG_GROUP_ID" => 1));
if ($arr = $res->Fetch()) {
CPrice::Update($arr["ID"], $arField);
}
else {
CPrice::Add($arField);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question