hotfix: Add shipping method to draft order

This commit is contained in:
olivermrbl
2021-06-08 16:55:53 +02:00
parent 4f76088382
commit eb0a4afd79
2 changed files with 11 additions and 40 deletions

View File

@@ -88,6 +88,7 @@ describe("DraftOrderService", () => {
...data,
})
),
addShippingMethod: jest.fn(),
withTransaction: function() {
return this
},
@@ -156,22 +157,11 @@ describe("DraftOrderService", () => {
type: "draft_order",
})
expect(shippingOptionService.createShippingMethod).toHaveBeenCalledTimes(
1
)
expect(shippingOptionService.createShippingMethod).toHaveBeenCalledWith(
expect(cartService.addShippingMethod).toHaveBeenCalledTimes(1)
expect(cartService.addShippingMethod).toHaveBeenCalledWith(
"test-cart",
"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)
@@ -185,7 +175,6 @@ describe("DraftOrderService", () => {
expect(lineItemService.create).toHaveBeenCalledTimes(1)
expect(lineItemService.create).toHaveBeenCalledWith({
cart_id: "test-cart",
has_shipping: true,
title: "test-item",
variant_id: "test-variant",
})

View File

@@ -272,22 +272,6 @@ class DraftOrderService extends BaseService {
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) {
if (item.variant_id) {
const line = await this.lineItemService_
@@ -297,16 +281,8 @@ class DraftOrderService extends BaseService {
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({
cart_id: createdCart.id,
has_shipping: hasShipping,
...line,
})
} 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
})
}