Answer the question
In order to leave comments, you need to log in
Saving value to order property via API?
Good afternoon, tell me why the save may not work, I tried this:
use Bitrix\Main;
Main\EventManager::getInstance()->addEventHandler(
'sale',
'OnSaleOrderSaved',
'myFunction'
);
function myFunction(Main\Event $event) {
$order = $event->getParameter("ENTITY");
$res = CSaleBasket::GetList(array(), array("ORDER_ID" => $order->getField("ID")));
$items = array();
while ($arItem = $res->Fetch()) {
$items .= $arItem['PRODUCT_XML_ID'].':'.$arItem['PRICE_TYPE_ID'].';';
}
$order->setField("PRICE_TYPE", $items);
AddMessage2Log($items);
}
use Bitrix\Main;
Main\EventManager::getInstance()->addEventHandler(
'sale',
'OnSaleOrderSaved',
'myFunction'
);
function myFunction(Main\Event $event) {
$order = $event->getParameter("ENTITY");
$res = CSaleBasket::GetList(array(), array("ORDER_ID" => $order->getField("ID")));
$items = array();
while ($arItem = $res->Fetch()) {
$items .= $arItem['PRICE_TYPE_ID'].';';
}
$propertyCollection = $order->getPropertyCollection();
$propsData = [];
foreach ($propertyCollection as $propertyItem) {
if (!empty($propertyItem->getField("CODE"))) {
$propsData[$propertyItem->getField("CODE")] = trim($propertyItem->getValue());
}
}
foreach ($propertyCollection as $propertyItem) {
switch ($propertyItem->getField("CODE")) {
case 'PRICE_TYPE':
AddMessage2Log('Условие сработало');
$propertyItem->setField("VALUE", $items);
break;
}
}
AddMessage2Log($items);
}
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