Description and parameters
bool
CCatalogDiscount::Add(
array arFields );
Method adds a new discount according to the data from the array arFields. Non-static method.
Call parameters
Parameter | Description |
arFields | Associative array with parameters for new discount, with keys as parameters and corresponding values. Available keys:
- SITE_ID - site, required field;
- ACTIVE - active status flag;
- NAME - discount name, required field;
- COUPON - coupon code;
- SORT - sort index;
- MAX_DISCOUNT - max discount amount;
- LAST_DISCOUNT - if N, cancels the option Don't apply further discounts;
- VALUE_TYPE - discount type (P - in percentage, F - fixed, S - fixed amount);
- VALUE - discount value;
- CURRENCY - currency, required field;
- RENEWAL - flag "Скидка на продление";
- ACTIVE_FROM - discount activity start date;
- ACTIVE_TO - discount activity end date;
- IBLOCK_IDS - array with iblock codes, with applied discount (if the discount is applied not to all iblocks). Key has deprecated starting from version 12.0.0;
- PRODUCT_IDS - array with product codes, with applied discount (if the discount is applied not to all products). Key has deprecated starting from version 12.0.0;
- SECTION_IDS - array with product group codes with applied discount (if the discount is applied not to all product groups). Key has deprecated starting from version 12.0.0;
- GROUP_IDS - array with user group codes, with applied discount (if the discount is applied not to all user groups);
- CATALOG_GROUP_IDS - array with price type codes, with applied discount (if the discount is applied not to all price types).
- CATALOG_COUPONS - array with discount coupons.
- USE_COUPONS - [Y/N] - coupon availability. Updated automatically.
- PRIORITY - applicability priority;
- CONDITIONS - array for creating conditions for discount use. Key is available from version 12.0.0.
If completed and not empty, arrays PRODUCT_IDS, SECTION_IDS and IBLOCK_IDS won't be used. CONDITIONS must be unavailable in the array arFields to specify discount parameters using these 3 keys.
Each condition of array CONDITIONS is described by the array of the following structure:
- CLASS_ID - identifier (string);
- DATA => array() - array with condition parameters;
- CHILDREN => array() - array with subconditions, each as array with similar structure, where keys are values 0,1,2,3,..
Possible logic conditions:
- Equal;
- Not - not equal;
- Great - more;
- Less - less;
- EqGr - more or equal;
- EqLs - less or equal.
Condition names:
- CondIBElement - product;
- CondIBIBlock - iblock;
- CondIBSection - section;
- CondIBCode - character code;
- CondIBXmlID - external code;
- CondIBName - name;
- CondIBActive - active;
- CondIBDateActiveFrom - activity start;
- CondIBDateActiveTo - activity end;
- CondIBSort - sorting;
- CondIBPreviewText - description for preview;
- CondIBDetailText - detailed description;
- CondIBDateCreate - date created;
- CondIBCreatedBy - author;
- CondIBTimestampX - date updated;
- CondIBModifiedBy - modified by;
- CondIBTags - tags;
- CondCatQuantity - amount of product at warehouse;
- CondCatWeight - product weight;
- CondCatVatID - VAT;
- CondCatVatIncluded - VAT included into price.
Additionally, conditions can be bound to product properties.
Array upper element CONDITIONS is always the same (catalog discount can be retrieved with method CCatalogCondTree::GetDefaultConditions()):
array(
'CLASS_ID' => 'CondGroup',
'DATA' => array('All' => 'AND', 'True' => 'True'),
'CHILDREN' => array()
);
|
Returned values
Method returns code for inserted entry or false otherwise.
Example
You can get error details as follows:
$ID = CCatalogDiscount::Add($arFields);
$res = $ID>0;
if (!$res) {
$ex = $APPLICATION->GetException();
$ex->GetString();
}