Magento 2.4 问题:优惠券代码无效。验证代码并重试

问题描述 投票:0回答:1

我使用的是magento 2.4。我已经创建了自动生成的优惠券,但不起作用。
在这里,我附上了图片。你能帮我吗?enter image description here

最初我会确定起始日期和截止日期。
然后,我尝试将其添加到 coupon.phtml 文件中

<input name="form_key" type="hidden" value="{{form_key}}"/>

还运行以下命令

php bin/magento indexer:reindex

php bin/magento cache:flush

magento magento2 coupon magento2.4
1个回答
0
投票
  1. 我只是给出了“起始日期”仅用于价格规则。
  2. 在购物车价格规则表单页面中,我们可以看到要么停止规则处理,要么放弃后续规则。
  • 只需将停止规则处理/放弃后续规则设置为“是”即可。
  • 一些现有的优惠券可能会影响您当前的优惠券。
  1. 确保在管理优惠券代码选项卡中确认优惠券已使用或未使用。

我使用下面的 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,
            ]
        ]);

终于,优惠券生效了。这里我附上截图供大家参考。

© www.soinside.com 2019 - 2024. All rights reserved.