Created
May 23, 2020 15:04
-
-
Save BedrosovaYulia/ade7788a41d2e3eb4d50949fd4c07721 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
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