hotfix: Add shipping method to draft order
This commit is contained in:
1 parent
4f76088382
commit
eb0a4afd79
2 files changed
+11
-40
No files matched your search
@@ -88,6 +88,7 @@ describe("DraftOrderService", () => {
|
|||||||
...data,
|
...data,
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
|
addShippingMethod: jest.fn(),
|
||||||
withTransaction: function() {
|
withTransaction: function() {
|
||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
@@ -156,22 +157,11 @@ describe("DraftOrderService", () => {
|
|||||||
type: "draft_order",
|
type: "draft_order",
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(shippingOptionService.createShippingMethod).toHaveBeenCalledTimes(
|
expect(cartService.addShippingMethod).toHaveBeenCalledTimes(1)
|
||||||
1
|
expect(cartService.addShippingMethod).toHaveBeenCalledWith(
|
||||||
)
|
"test-cart",
|
||||||
expect(shippingOptionService.createShippingMethod).toHaveBeenCalledWith(
|
|
||||||
"test-option",
|
"test-option",
|
||||||
{},
|
{}
|
||||||
{
|
|
||||||
cart: {
|
|
||||||
id: "test-cart",
|
|
||||||
region_id: "test-region",
|
|
||||||
shipping_address_id: "test-shipping",
|
|
||||||
billing_address_id: "test-billing",
|
|
||||||
customer_id: "test-customer",
|
|
||||||
type: "draft_order",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(lineItemService.generate).toHaveBeenCalledTimes(1)
|
expect(lineItemService.generate).toHaveBeenCalledTimes(1)
|
||||||
@@ -185,7 +175,6 @@ describe("DraftOrderService", () => {
|
|||||||
expect(lineItemService.create).toHaveBeenCalledTimes(1)
|
expect(lineItemService.create).toHaveBeenCalledTimes(1)
|
||||||
expect(lineItemService.create).toHaveBeenCalledWith({
|
expect(lineItemService.create).toHaveBeenCalledWith({
|
||||||
cart_id: "test-cart",
|
cart_id: "test-cart",
|
||||||
has_shipping: true,
|
|
||||||
title: "test-item",
|
title: "test-item",
|
||||||
variant_id: "test-variant",
|
variant_id: "test-variant",
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -272,22 +272,6 @@ class DraftOrderService extends BaseService {
|
|||||||
id: result.id,
|
id: result.id,
|
||||||
})
|
})
|
||||||
|
|
||||||
let shippingMethods = []
|
|
||||||
|
|
||||||
for (const method of shipping_methods) {
|
|
||||||
const m = await this.shippingOptionService_
|
|
||||||
.withTransaction(manager)
|
|
||||||
.createShippingMethod(method.option_id, method.data, {
|
|
||||||
cart: createdCart,
|
|
||||||
})
|
|
||||||
|
|
||||||
shippingMethods.push(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
const profiles = shippingMethods.map(
|
|
||||||
({ shipping_option }) => shipping_option.profile_id
|
|
||||||
)
|
|
||||||
|
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
if (item.variant_id) {
|
if (item.variant_id) {
|
||||||
const line = await this.lineItemService_
|
const line = await this.lineItemService_
|
||||||
@@ -297,16 +281,8 @@ class DraftOrderService extends BaseService {
|
|||||||
unit_price: item.unit_price,
|
unit_price: item.unit_price,
|
||||||
})
|
})
|
||||||
|
|
||||||
const variant = await this.productVariantService_
|
|
||||||
.withTransaction(manager)
|
|
||||||
.retrieve(item.variant_id)
|
|
||||||
const itemProfile = variant.product.profile_id
|
|
||||||
|
|
||||||
const hasShipping = profiles.includes(itemProfile)
|
|
||||||
|
|
||||||
await this.lineItemService_.withTransaction(manager).create({
|
await this.lineItemService_.withTransaction(manager).create({
|
||||||
cart_id: createdCart.id,
|
cart_id: createdCart.id,
|
||||||
has_shipping: hasShipping,
|
|
||||||
...line,
|
...line,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@@ -329,6 +305,12 @@ class DraftOrderService extends BaseService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const method of shipping_methods) {
|
||||||
|
await this.cartService_
|
||||||
|
.withTransaction(manager)
|
||||||
|
.addShippingMethod(createdCart.id, method.option_id, method.data)
|
||||||
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user