Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien2p committed Nov 4, 2022
1 parent e395b3e commit 85951fb
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default async (req, res) => {
relations: defaultAdminDraftOrdersRelations,
})

draftOrder.cart = await cartService.retrieve(draftOrder.cart_id, {
draftOrder.cart = await cartService.retrieveWithTotals(draftOrder.cart_id, {
relations: defaultAdminDraftOrdersCartRelations,
select: defaultAdminDraftOrdersCartFields,
})
Expand Down
3 changes: 3 additions & 0 deletions packages/medusa/src/services/__mocks__/totals.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export const TotalsServiceMock = {
getCalculationContext: jest.fn().mockImplementation((order, lineItems) => {
return Promise.resolve({})
}),
getLineItemTotals: jest.fn().mockImplementation(() => {
return Promise.resolve({})
}),
}

const mock = jest.fn().mockImplementation(() => {
Expand Down
8 changes: 8 additions & 0 deletions packages/medusa/src/services/__tests__/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ describe("OrderService", () => {
withTransaction: function () {
return this
},
getCalculationContext: jest.fn().mockImplementation((order, lineItems) => {
return Promise.resolve({})
}),
getLineItemTotals: jest.fn().mockImplementation(() => {
return Promise.resolve({})
}),
getLineItemRefund: () => {},
getTotal: (o) => {
return o.total || 0
Expand Down Expand Up @@ -1249,6 +1255,7 @@ describe("OrderService", () => {
{
order: {
id: IdMap.getId("order"),
items: [],
shipping_methods: [
{
shipping_option: {
Expand Down Expand Up @@ -1278,6 +1285,7 @@ describe("OrderService", () => {
{
order: {
id: IdMap.getId("order"),
items: [],
shipping_methods: [
{
shipping_option: {
Expand Down
21 changes: 0 additions & 21 deletions packages/medusa/src/services/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,27 +251,6 @@ class CartService extends TransactionBaseService {
): Promise<Cart> {
const totals: { [K in TotalField]?: number | null } = {}

if (totalsToSelect.some((field) => ["subtotal", "total"].includes(field))) {
const calculationContext =
await this.totalsService_.getCalculationContext(cart, {
exclude_shipping: true,
})
cart.items = await Promise.all(
(cart.items || []).map(async (item) => {
const itemTotals = await this.totalsService_.getLineItemTotals(
item,
cart,
{
include_tax: options.force_taxes ?? cart.region.automatic_taxes,
calculation_context: calculationContext,
}
)

return Object.assign(item, itemTotals)
})
)
}

for (const key of totalsToSelect) {
switch (key) {
case "total": {
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/src/services/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ class OrderService extends TransactionBaseService {
item,
order,
{
include_tax: order.region.automatic_taxes,
include_tax: order.region?.automatic_taxes,
calculation_context: calculationContext,
}
)
Expand Down

0 comments on commit 85951fb

Please sign in to comment.