我使用的是magento 2.4。我已经创建了自动生成的优惠券,但不起作用。
在这里,我附上了图片。你能帮我吗?
最初我会确定起始日期和截止日期。
然后,我尝试将其添加到 coupon.phtml 文件中
<input name="form_key" type="hidden" value="{{form_key}}"/>
还运行以下命令
php bin/magento indexer:reindex
php bin/magento cache:flush
我使用下面的 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,
]
]);