Skip to content

Instantly share code, notes, and snippets.

@megamosk
Created July 17, 2023 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save megamosk/b315fee5808bfe561075d6c8ec384fc0 to your computer and use it in GitHub Desktop.
Save megamosk/b315fee5808bfe561075d6c8ec384fc0 to your computer and use it in GitHub Desktop.
1C-Битрикс добавление скидки по внешнему коду продукта
<?php
require $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php';
use Bitrix\Main\Loader;
Loader::includeModule('catalog');
// add discount by product xml id
$uuid = 'f0a73f90-57ec-11ec-8ea2-005056b8434b';
$discountName = 'Blahblah';
$price = 3333;
$discount = new CCatalogCondTree();
$conditions = $discount->GetDefaultConditions();
$conditions['CHILDREN'] = [
0 => [
'CLASS_ID' => 'CondIBXmlID',
'DATA' => [
'logic' => 'Equal',
'value' => $uuid,
],
],
];
$arFields = [
// 'ACTIVE' => 'N',
'SITE_ID' => SITE_ID, // обязательное
'NAME' => $discountName, // обязательное
'CURRENCY' => 'RUB', // обязательное
'CONDITIONS' => $conditions,
'VALUE_TYPE' => 'S', // тип скидки (P - в процентах, F - фиксированная величина, S - фиксированная цена);
'VALUE' => $price, // значение скидки
];
$added = CCatalogDiscount::Add($arFields);
$res = $added > 0;
if (!$res) {
$ex = $APPLICATION->GetException();
echo $ex->GetString();
} else {
echo 'Done';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment