Answer the question
In order to leave comments, you need to log in
Why is the coupon not being added?
<? require_once($_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/include/prolog_before.php");?>
<?
CModule::IncludeModule("sale");
CModule::IncludeModule("catalog");
{
$COUPON = CatalogGenerateCoupon();
$arCouponFields = array(
"DISCOUNT_ID" => 27,
"ACTIVE" => "Y",
"ONE_TIME" => "O",
"COUPON" => $COUPON,
"DATE_APPLY" => false
);
$CID = CCatalogDiscountCoupon::Add($arCouponFields);
$CID = IntVal($CID);
if ($CID <= 0)
{
$ex = $APPLICATION->GetException();
$errorMessage = $ex->GetString();
echo $errorMessage;
}
}
echo $CID.' номер - '.$COUPON;
?>
Answer the question
In order to leave comments, you need to log in
Decided like this:
<? require_once($_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/include/prolog_before.php");?>
<?
CModule::IncludeModule("sale");
CModule::IncludeModule("catalog");
{
$COUPON = CatalogGenerateCoupon();
$addDb = \Bitrix\Sale\Internals\DiscountCouponTable::add(array(
'DISCOUNT_ID' => 27,
'COUPON' => $COUPON,
'TYPE' => \Bitrix\Sale\Internals\DiscountCouponTable::TYPE_ONE_ORDER,
'MAX_USE' => 1,
'USER_ID' => 0,
'DESCRIPTION' => ''
));
}
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question