Создание скидки
function skidka_add($PRODUCT_ID, $DISCOUNT_VALUE){
CModule::IncludeModule("catalog");
CModule::IncludeModule("iblock");
CModule::IncludeModule("sale");
$arFields = [
"LID" => "s1",
"NAME" => "Скидка ".$DISCOUNT_VALUE."%",
"LAST_DISCOUNT" => "Y", // последующие скидки не будут использованы
"ACTIVE" => "Y",
"CURRENCY" => "RUB",
"USER_GROUPS" => [2], // все пользователи
'ACTIONS' => [
'CLASS_ID' => 'CondGroup',
'DATA' => ['All' => 'AND'],
'CHILDREN' => [
[
'CLASS_ID' => 'ActSaleBsktGrp',
'DATA' => [
'Type' => 'Discount', // скидку
'Value' => $DISCOUNT_VALUE,
'Unit' => 'Perc', // процент
'All' => 'AND', // все условия
'True' => 'True' // выполнено(ы)
],
'CHILDREN' => [
[
'CLASS_ID' => 'CondIBElement',
'DATA' => [
'logic' => 'Equal', // только равно
'value' => $PRODUCT_ID
]
]
]
]
]
],
"CONDITIONS"=> [ // дополнительные условия правила
'CLASS_ID' => 'CondGroup',
'DATA' => [
'All' => 'AND',
'True' => 'True',
],
'CHILDREN' => [],
],
];
if ($ID = CSaleDiscount::Add($arFields)){
return $ID;
}
else
return "error ".$ID;
}
Поиск скидки по ID
function skidka_search($PRODUCT_ID){
CModule::IncludeModule("catalog");
CModule::IncludeModule("iblock");
CModule::IncludeModule("sale");
$arDiscounts = CCatalogDiscount::GetDiscountByProduct($PRODUCT_ID,2,"N",4,SITE_ID);
foreach ($arDiscounts as $value) {
$return[] = [
"ID" => $value["ID"], // ID скидки
"VALUE" => $value["VALUE"], // Процент скидки
];
}
return $return;
}
Удалить скидку
function skidka_delet($ID){
CModule::IncludeModule("catalog");
CModule::IncludeModule("iblock");
CModule::IncludeModule("sale");
CSaleDiscount::Delete($ID);
}
Обновить скидку
function skidka_update($SKIDKA_ID, $PRODUCT_ID, $DISCOUNT_VALUE){
CModule::IncludeModule("catalog");
CModule::IncludeModule("iblock");
CModule::IncludeModule("sale");
$arFields = [
"NAME" => "Скидка ".$DISCOUNT_VALUE."%",
'ACTIONS'=>[
'CLASS_ID' => 'CondGroup',
'DATA' => ['All'=>'AND'],
'CHILDREN' =>[
[
'CLASS_ID'=>'ActSaleBsktGrp',
'DATA'=> [
'Type' => 'Discount',
'Value'=> $DISCOUNT_VALUE,
'Unit' => 'Perc',
'All' => 'AND',
'True' => 'True'
],
'CHILDREN'=>[
[
'CLASS_ID'=>'CondIBElement',
'DATA'=>[
'logic'=>'Equal',
'value'=> $PRODUCT_ID
]
]
]
]
]
]
];
CSaleDiscount::Update($SKIDKA_ID, $arFields);
}