0

I am using Magento2 enterprice edition 2.1.2

Magneto2 specific coupons are working well.

When created a cart price rule with coupon as a "auto" and generated multiple coupons in Manage Coupon code. When used this coupon code magento showing all coupons are invalid.

Please check attached screen-shot's

[enter image description here][1]enter image description here

enter image description here

4
  • facing same problem.
    – Sejal Shah
    Commented May 18, 2017 at 11:34
  • are you fixed it?
    – Init
    Commented Jun 29, 2017 at 4:26
  • i found it: youtu.be/4B_9sWsJcYM , you can follow step of video
    – Init
    Commented Jun 29, 2017 at 15:57
  • 1
    In my case the issue is To Date. It was set too far ahead i.e. 09/30/2117. When I cross checked, it was working upto 2035.
    – Deeps
    Commented Sep 21, 2017 at 14:26

3 Answers 3

1

Since code generator is also become part of consumer queue after 2.3.x , you can manually run this command to start generating the coupon codes,

php bin/magento queue:consumers:start codegeneratorProcessor

thanks.

0

Because this is a bug on Magento 2.1. There is a difference about the type of coupon which auto-generate To fix it. Go to file vendor/magento/module-sales-rule/Model/ResourceModel/Rule/Collection.php

 
$orWhereConditions = [
    $connection->quoteInto(
        '(main_table.coupon_type = ? AND rule_coupons.type = 0)',
        \Magento\SalesRule\Model\Rule::COUPON_TYPE_AUTO
    ),
    ....
];

Then change rule_coupons.type = 0 to rule_coupons.type = 1 Hope that this will help everyone

0
  1. I just given "from date" only for the price rule.
  2. In the cart price rules form page, we can see that either Stop Rules Processing or Discard Subsequent Rules.
  • Just set "Yes" for Stop Rules Processing/Discard Subsequent Rules.
  • Some existing coupon may affect your current coupon.I removed that coupon.
  1. Make sure in the manage coupon codes tab, confirm either coupon is used or unused.

I've created the auto generated coupon using the below api.

$accessToken = 'ymuo1rkbggrh467tmtlk502hw9fd2v8z'
$response = Http::withHeaders([
            'Content-Type' => 'application/json',
            'Authorization' => 'Bearer ' . $accessToken,
        ])->post(
            'https://example.com/rest/default/V1/salesRules',
            [
                'rule' => [
                    "name" => "TESTCOUPON",
                    "website_ids" => [1],
                    "customer_group_ids" => [0, 1, 2, 3],
                    "uses_per_customer" => 1,
                    "is_active" => true,
                    "stop_rules_processing" => true,
                    "is_advanced" => true,
                    "sort_order" => 0,
                    "discount_amount" => 10,
                    "discount_step" => 0,
                    "apply_to_shipping" => false,
                    "times_used" => 0,
                    "is_rss" => true,
                    "coupon_type" => "SPECIFIC_COUPON",
                    "use_auto_generation" => true, // Setting auto-generation to false
                    "uses_per_coupon" => 1,
                    "from_date" => Carbon::now()->toDateString(),
                    "simple_action" => "by_fixed"
                ]
            ]
        );
        $actionRule = $response->json();

        // Make POST request to create autogenerate coupon by using rule_id
        $response = Http::withHeaders([
            'Authorization' => 'Bearer ' . $accessToken,
            'Content-Type' => 'application/json',
        ])->post('https://example.com/rest/default/V1/coupons/generate', [
            'couponSpec' => [
                'rule_id' => $actionRule['rule_id'],
                'quantity' => 5,
                'length' => 12,
            ]
        ]);

Finally, The coupon is working.Here, I attached the screenshot for your reference. enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.