I
I
IliaMal2020-08-31 11:53:04
1C-Bitrix
IliaMal, 2020-08-31 11:53:04

Why is the coupon not added via CCatalogDiscountCoupon::Add?

Hello.

I'm trying to add a coupon to the "Rule for working with the basket" No. 3, I used the office. documentation CCatalogDiscountCoupon I'll attach

the whole code: https://pastebin.com/TSwu8zms

It seems that everything is simple, there is no place to make a mistake, but for some reason the coupon is not added to me. At the same time, it $CIDgives the coupon number, and with each attempt the number increases by one, but there are no coupons in the admin panel, they are not applied in the basket.
Where did I go wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2020-08-31
@IliaMal

<?php
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
CModule::IncludeModule("sale");
CModule::IncludeModule("catalog");
$COUPON = randString(5);

    $addDb = \Bitrix\Sale\Internals\DiscountCouponTable::add(array(
      'DISCOUNT_ID' => 3,
      'COUPON'      => $COUPON,
      'TYPE'        => \Bitrix\Sale\Internals\DiscountCouponTable::TYPE_ONE_ORDER,
      'MAX_USE'     => 1,
      'USER_ID'     => 0,
      'DESCRIPTION' => ''
   ));
echo $COUPON;
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question