$ID = CSaleDiscount::Add($arFields); //Создаем правило корзины
private function basketCalc($realDisc){
$unixStart = strtotime(date("d.m.Y H:i:s"));
$unixEnd = $unixStart+3600;
$xcount = 0;
$discountValue = $this->BASKET_PRICE*$realDisc/100;
$Actions["CLASS_ID"] = "CondGroup";
$Actions["DATA"]["All"] = "AND";
$Actions["CLASS_ID"] = "CondGroup";
$Actions["CHILDREN"][0]["CLASS_ID"] = "ActSaleBsktGrp";
$Actions["CHILDREN"][0]["DATA"]["Type"] = "Discount";
$Actions["CHILDREN"][0]["DATA"]["Value"] = $discountValue;
$Actions["CHILDREN"][0]["DATA"]["Unit"] = "Perc";
$Actions["CHILDREN"][0]["DATA"]["All"] = "OR";
$DbParentEl = CIBlockElement::GetList(array(),array("SECTION_ID"=>array(10,11)),false,false,array("ID"));
while($ParentId = $DbParentEl->Fetch()){
//Массив товаров к которым будет применяться скидка
$Actions["CHILDREN"][0]["CHILDREN"][$xcount]["CLASS_ID"] = "CondIBElement";
$Actions["CHILDREN"][0]["CHILDREN"][$xcount]["DATA"]["logic"] = "Equal";
$Actions["CHILDREN"][0]["CHILDREN"][$xcount]["DATA"]["value"] = $ParentId["ID"];
$xcount++;
}
$Conditions["CLASS_ID"] = "CondGroup";
$Conditions["DATA"]["All"] = "AND";
$Conditions["DATA"]["True"] = "True";
$Conditions["CHILDREN"] = "";
//Массив для создания правила
$arFields = array(
"LID"=>"s1",
"NAME"=>$discountValue."% Скидки ".date("d.m.y"),
"CURRENCY"=>"RUB",
"ACTIVE"=>"Y",
"USER_GROUPS"=>array(1),
"ACTIVE_FROM"=>ConvertTimeStamp($unixStart, "FULL"),
"ACTIVE_TO"=>ConvertTimeStamp($unixEnd, "FULL"),
"CONDITIONS"=>$Conditions,
'ACTIONS' => $Actions
);
$ID = CSaleDiscount::Add($arFields); //Создаем правило корзины
$res = $ID>0;
if ($res) {
$codeCoupon = CatalogGenerateCoupon(); //Генирация купона
$fields["DISCOUNT_ID"] = $ID;
$fields["COUPON"] = $codeCoupon;
$fields["ACTIVE"] = "Y";
$fields["TYPE"] = 2;
$fields["MAX_USE"] = 0;
$dd = Internals\DiscountCouponTable::add($fields); //Создаем купон для этого правила
if (!$dd->isSuccess())
{
$err = $dd->getErrorMessages();
}else{
echo 'Купон на скидку: '.$codeCoupon;
}
}else{
// $ex = $APPLICATION->GetException();
echo "Ошибка <br>";
}
}
<?php
CModule::IncludeModule("disnuts");
global $DBType;
$arClasses=array(
'discount_nuts\Docking' =>'controller/Docking.php',
'discount_nuts\GetBonuce' => 'controller/GetBonuce.php',
'discount_nuts\DBConnect' => 'service/DBConnect.php',
'discount_nuts\addUser' => 'service/addUser.php',
'discount_nuts\getDiscount' => '/controller/getDiscount.php',
'discount_nuts\Disnuts' => 'index.php'
);
CModule::AddAutoloadClasses("disnuts",$arClasses);
use discount_nuts\Disnuts;
$arResult['ORDER_PRICE_FORMATED'] = SaleFormatCurrency($arResult['ORDER_PRICE'], $this->order->getCurrency());
$arResult['ORDER_WEIGHT'] = $basket->getWeight();
$arResult['ORDER_WEIGHT_FORMATED'] = roundEx(floatval($arResult['ORDER_WEIGHT'] / $arResult['WEIGHT_KOEF']), SALE_WEIGHT_PRECISION).' '.$arResult['WEIGHT_UNIT'];
$arResult['PRICE_WITHOUT_DISCOUNT_VALUE'] = $basket->getBasePrice(); //значение float
$arResult['PRICE_WITHOUT_DISCOUNT'] = SaleFormatCurrency($arResult['PRICE_WITHOUT_DISCOUNT_VALUE'], $this->order->getCurrency());
$disnuts = new Disnuts($arResult['PRICE_WITHOUT_DISCOUNT']);
// $arResult['DISCOUNT_PRICE'] = Sale\PriceMaths::roundPrecision(
// $this->order->getDiscountPrice() + ($arResult['PRICE_WITHOUT_DISCOUNT_VALUE'] - $arResult['ORDER_PRICE'])
// ); //значение float
$arResult['DISCOUNT_PRICE'] = Sale\PriceMaths::roundPrecision(
$this->order->getDiscountPrice() + ($disnuts->discActions())
); //значение float
$arResult['DISCOUNT_PRICE_FORMATED'] = SaleFormatCurrency($arResult['DISCOUNT_PRICE'], $this->order->getCurrency());