D
D
Denis2017-10-10 13:25:07
Prestashop
Denis, 2017-10-10 13:25:07

How to create a coupon / voucher in PrestaShop via API?

Such a situation: when buying in store A, you need to create a coupon in store B.
Store B is prestashop. Is it possible to create a coupon through the API?
Google does not help, there is very little information in general about coupons and vouchers.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Ilyasov, 2018-01-03
@IvanIlyasov

As an example:

$cart_rule = new CartRule();
            $cart_rule->code = $discountCode;
            foreach (Language::getLanguages(false) as $language)
            $cart_rule->name[$language['id_lang']] = Configuration::get('COUPON_DESC');
            $cart_rule->id_customer = (int)$customer->id;
            $cart_rule->free_shipping = false;
            $cart_rule->quantity = 1;
            $cart_rule->quantity_per_user = 1;
            $cart_rule->reduction_currency = (int)$this->context->cart->id_currency;
            $cart_rule->reduction_percent = Configuration::get('COUPON_DISCOUNT');
            $cart_rule->date_from = date('Y-m-d H:i:s', time());
            $cart_rule->date_to = date('Y-m-d H:i:s', time() + (3600 * 24 * Configuration::get('COUPON_DAY')));
            $cart_rule->active = 1;

        if ($cart_rule->add())
        {
            Mail::Send(Configuration::get('PS_LANG_DEFAULT'), 'coupon', 'Вам купон на скидку', array('{shop_name}' => Configuration::get('PS_SHOP_NAME'), '{firstname}' => $customer->firstname, '{lastname}' => '', '{email}' => $customer->email, '{code}' => $discountCode), $customer->email, NULL, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__).'/mails/');
            die(true);
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question