fix(medusa): Add usage_count + usage_limit to discount
This commit is contained in:
@@ -1,15 +1,43 @@
|
||||
const { Customer, Region, Cart } = require("@medusajs/medusa");
|
||||
const {
|
||||
Customer,
|
||||
Region,
|
||||
Cart,
|
||||
DiscountRule,
|
||||
Discount,
|
||||
} = require("@medusajs/medusa");
|
||||
|
||||
module.exports = async (connection, data = {}) => {
|
||||
const manager = connection.manager;
|
||||
|
||||
await manager.insert(Region, {
|
||||
const r = manager.create(Region, {
|
||||
id: "test-region",
|
||||
name: "Test Region",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
});
|
||||
|
||||
const d = await manager.create(Discount, {
|
||||
id: "test-discount",
|
||||
code: "CREATED",
|
||||
is_dynamic: false,
|
||||
is_disabled: false,
|
||||
});
|
||||
|
||||
const dr = await manager.create(DiscountRule, {
|
||||
id: "test-discount-rule",
|
||||
description: "Created",
|
||||
type: "fixed",
|
||||
value: 10000,
|
||||
allocation: "total",
|
||||
usage_limit: 2,
|
||||
usage_count: 2,
|
||||
});
|
||||
|
||||
d.rule = dr;
|
||||
d.regions = [r];
|
||||
|
||||
await manager.save(d);
|
||||
|
||||
await manager.query(
|
||||
`UPDATE "country" SET region_id='test-region' WHERE iso_2 = 'us'`
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user