Answer the question
In order to leave comments, you need to log in
How to create a shopping cart rule via API?
Good afternoon!
After executing this code, the cart rule does not appear on the page /bitrix/admin/sale_discount.php?lang=ru
$arF = array(
"SITE_ID" => "s1",
"NAME"=> "Тест",
"CURRENCY" => "RUB",
"MAX_DISCOUNT" => 0,
"VALUE" => 20,
"ACTIVE" => "Y",
"CONDITIONS" => array (
'CLASS_ID' => 'CondGroup',
'DATA' =>
array (
'All' => 'AND',
'True' => 'True',
),
'CHILDREN' => array(),
)
);
CCatalogDiscount::Add($arF);
Answer the question
In order to leave comments, you need to log in
UPD replaced example with normal
Use CSaleDiscount::Add($arFields)
\Bitrix\Main\Loader::includeModule('sale');
$arFields = [
'LID' => 's1',
'NAME' => 'Тест ядра33',
'ACTIVE_FROM' => '',
'ACTIVE_TO' => '',
'ACTIVE' => 'Y',
'SORT' => 100,
'PRIORITY' => 1,
'LAST_DISCOUNT' => 'Y',
'LAST_LEVEL_DISCOUNT' => 'N',
'XML_ID' => '',
'CONDITIONS' => [
'CLASS_ID' => 'CondGroup',
'DATA' => [
'All' => 'AND',
'True' => 'True',
],
'CHILDREN' => [
0 => [
'CLASS_ID' => 'CondBsktProductGroup',
'DATA' => [
'Found' => 'Found',
'All' => 'AND',
],
'CHILDREN' => [
'0' => [
'CLASS_ID' => 'CondBsktFldProduct',
'DATA' => [
'logic' => 'Equal',
'value' => '92',
]
]
]
]
]
],
'ACTIONS' => [
'CLASS_ID' => 'CondGroup',
'DATA' => [
'All' => 'AND',
],
'CHILDREN' => [
0 => [
'CLASS_ID' => 'ActSaleBsktGrp',
'DATA' => [
'Type' => 'Discount',
'Value' => 10,
'Unit' => 'Perc',
'Max' => 0,
'All' => 'AND',
'True' => 'True',
],
'CHILDREN' => []
]
]
],
'USER_GROUPS' => [1]
];
CSaleDiscount::Add($arFields);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question