A
A
Anton2019-02-08 15:13:28
1C-Bitrix
Anton, 2019-02-08 15:13:28

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;
?>

Added a new entry to the rules of the basket, a discount on goods
The code shows the cid number and the generated coupon, but the coupon does not get into the coupon database

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2019-02-08
@anton99zel

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 question

Ask a Question

731 491 924 answers to any question