Skip to content

Instantly share code, notes, and snippets.

@BedrosovaYulia
Created May 23, 2020 15:04
Show Gist options
  • Save BedrosovaYulia/ade7788a41d2e3eb4d50949fd4c07721 to your computer and use it in GitHub Desktop.
Save BedrosovaYulia/ade7788a41d2e3eb4d50949fd4c07721 to your computer and use it in GitHub Desktop.
<?
use Bitrix\Main;
Main\EventManager::getInstance()->addEventHandler(
'sale',
'OnSaleOrderBeforeSaved',
'saleOrderBeforeSaved'
);
function saleOrderBeforeSaved(Main\Event $event)
{
$order = $event->getParameter("ENTITY");
$coupons = $order->getDiscount()->getApplyResult()["COUPON_LIST"];
$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 'PROMOKOD':
foreach($coupons as $coupon_key=>$coupon_val)
{
$propertyItem->setField("VALUE", $coupon_val['COUPON']);
}
break;
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment