Add
Description and parameters
mixed
CCatalogDiscountCoupon::Add (
array arFields
boolean $bAffectDataFile = True
);
Method adds coupon for selected discount. Non-static method.
Call parameters
Parameter | Описание | Available from version | to version |
---|---|---|---|
arFields | Associative array with parameters of new coupon with keys as parameter names and corresponding values:
| ||
bAffectDataFile | Optional parameter, indicating the necessity to pre-generate discount and coupon file. These actions are performed by the method CCatalogDiscount::GenerateDataFile().
Note: starting from version 12.0 this parameter isn't required. Starting from version, the discount file cache is no longer used. | 5.1.1 | 12.0.0 |
Returned value
Method returns coupon code (ID) on a successful creating and false otherwise. You need to call $APPLICATION->GetException() to get detailed information about the encountered error.
Before adding a record to the table, parameters are checked by associating via the method CCatalogDiscountCoupon::CheckFields. In case verification is successful, writes record to database.
See Also
Before using the method, make to generate coupon code by function CatalogGenerateCoupon().
Examples
if (CModule::IncludeModule("catalog")) { $COUPON = CatalogGenerateCoupon(); $arCouponFields = array( "DISCOUNT_ID" => "4", "ACTIVE" => "Y", "ONE_TIME" => "Y", "COUPON" => $COUPON, "DATE_APPLY" => false ); $CID = CCatalogDiscountCoupon::Add($arCouponFields); $CID = IntVal($CID); if ($CID <= 0) { $ex = $APPLICATION->GetException(); $errorMessage = $ex->GetString(); echo $errorMessage; } }
© «Bitrix24», 2001-2024