$order = Bitrix\Sale\Order::load($order_id);
далее
$discounts = $order ->getDiscount();
$res = $discounts ->getApplyResult();
foreach($res['COUPON_LIST'] as $cupo_n=>$ar_r){
protected static $Action3for2Disallow = false;
public static function Action3for2($event)
{
if (self::$Action3for2Disallow)
return;
/* взводим флаг запуска */
self::$Action3for2Disallow = true;
global $USER;
if(!is_object($USER)){
$USER = new CUser();
}
$userId=$USER->GetID();
if ($userId=="81035" ){
$_SESSION["Action3for2"]=2;
Loader::IncludeModule('iblock');
Loader::IncludeModule('catalog');
Loader::IncludeModule('sale');
$basket = $event->getParameter("ENTITY");
$res=[];
$tovar=[];
foreach ($basket as $basketItem) {
$basketPropertyCollection = $basketItem->getPropertyCollection();
$res[]=[$basketItem->getProductId(),$basketItem->getPrice(), $basketItem->getQuantity(), $basketItem->getFinalPrice(), $basketPropertyCollection->getPropertyValues()['BAR_CODE']['VALUE']];
$tovar[]=$basketPropertyCollection->getPropertyValues()['BAR_CODE']['VALUE'];
$basketItem->delete();
}
file_put_contents($_SERVER["DOCUMENT_ROOT"]."/even.txt", "\n** ".date("d.m.Y H:i:s")." ****". __FILE__ ." ". __LINE__ ."**********\n".print_r($res, true), FILE_APPEND | LOCK_EX);
//удаляем если что-то есть в корзине
$fuser=\Bitrix\Sale\Fuser::getIdByUserId($userId);
$coli=[];
foreach($res as $vl){
for ($x=1; $x<=$vl[2]; $x++){
$coli[]=[$vl[4],$vl[1]];
}
}
$cont=count($coli);
usort($coli, function($a, $b){
return $a['1'] <=> $b['1'];
});
$skidka = floor($cont / 3);
for ($x=0; $x<$skidka; $x++){
$coli[$x][1]=0;
}
$coli = array_reverse($coli);
file_put_contents($_SERVER["DOCUMENT_ROOT"]."/even.txt", "\n** ".date("d.m.Y H:i:s")." ****". __FILE__ ." ". __LINE__ ."**********\n".print_r($coli, true), FILE_APPEND | LOCK_EX);
$arFilter = Array( "IBLOCK_ID"=>27, "PROPERTY_CML2_BAR_CODE"=>$tovar );
$res = \CIBlockElement::GetList(Array("SORT"=>"ASC",), $arFilter, false,false,array('ID',"PROPERTY_CML2_BAR_CODE",'CATALOG_QUANTITY','PROPERTY_CML2_LINK','IBLOCK_EXTERNAL_ID','XML_ID'));
$productsId=[];
$productsIdXml=[];
while($ar_fields = $res->GetNext())
{
$productsId[$ar_fields["PROPERTY_CML2_BAR_CODE_VALUE"]]=$ar_fields['ID'];
$productsIdXml[$ar_fields["PROPERTY_CML2_BAR_CODE_VALUE"]]=['IBLOCK_EXTERNAL_ID'=>$ar_fields['IBLOCK_EXTERNAL_ID'],'XML_ID'=>$ar_fields['XML_ID']];
}
$itogTovar=[];
foreach($coli as $val){
$itogTovar[$val[1]][$val[0]]++;
}
file_put_contents($_SERVER["DOCUMENT_ROOT"]."/even.txt", "\n** ".date("d.m.Y H:i:s")." ****". __FILE__ ." ". __LINE__ ."**********\n".print_r($itogTovar, true), FILE_APPEND | LOCK_EX);
foreach($itogTovar as $price0=>$value){
foreach($value as $barcode=>$qunt){
$arParams = \bh\catalog\tools::getBasketPropsByOfferId($productsId[$barcode]);
unset($arParams['more_photos']);
unset($arParams['more_images']);
$arParams['CATALOG_XML_ID']=array(
'NAME' => 'Catalog XML_ID',
'CODE' => 'CATALOG.XML_ID',
'VALUE' => $productsIdXml[$barcode]['IBLOCK_EXTERNAL_ID']
);
$arParams['PRODUCT_XML_ID']=array(
"NAME" => "Product XML_ID",
"CODE" => "PRODUCT.XML_ID",
"VALUE" => $productsIdXml[$barcode]['XML_ID']
);
if($price0<1){
$arParams['ACTION']=array(
"NAME" => "ACTION",
"CODE" => "ACTION",
"VALUE" => 'Товар по акции 2=3'
);
}
$item = $basket->createItem('catalog', $productsId[$barcode]); //создаём новый товар в корзине
$itemField=[];
$itemField['CURRENCY']=\Bitrix\Currency\CurrencyManager::getBaseCurrency();
$itemField['LID']=\Bitrix\Main\Context::getCurrent()->getSite();
$itemField['PRODUCT_PROVIDER_CLASS']='CCatalogProductProvider';
$itemField['CATALOG_XML_ID']=$productsIdXml[$barcode]['IBLOCK_EXTERNAL_ID'];
$itemField['PRODUCT_XML_ID']=$productsIdXml[$barcode]['XML_ID'];
$itemField['QUANTITY']=$qunt;
if($price0<1){
$itemField['CUSTOM_PRICE']='Y';
$itemField['PRICE']=0;
}
$item->setFields($itemField);
$item->getPropertyCollection()->setProperty($arParams);
}
}
if(\CSaleBasket::DeleteAll($fuser,false)) {$basket->save();}
self::$Action3for2Disallow = true;
}
}
если на отдельной странице вызвать
то пересчет срабатывает, в событии нет