Documentation

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 versionto version
arFields Associative array with parameters of new coupon with keys as parameter names and corresponding values:
  • DISCOUNT_ID - code (ID) for discount (required)
  • ACTIVE - coupon activity (Y|N) (optional), by default - Y
  • ONE_TIME - flag for one-time coupon use (optional). Can have one of three values: Y - to a single product item, O - to complete order, N - multiple use, by default - Y.
  • COUPON - coupon code (optional)
  • DATE_APPLY - date of applied coupon (optional), if specified - single coupon will be deemed as used
  • DESCRIPTION - comment (optional)
Optional keys, missing in array, receive default 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.112.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
Up