fix(): Cart workflow price calculation for different items but same variant (#13511)
RESOLVES CORE-1204 **What** - Fix wrong price tier when multiple items are targetting the same variant - fix type import from the wrong package **Notes** If you are struggling navigating the changes, you can focus on the following files: ``` integration-tests/http/__tests__/cart/store/cart.spec.ts integration-tests/modules/__tests__/cart/store/cart.workflows.spec.ts packages/core/core-flows/src/cart/steps/get-promotion-codes-to-apply.ts packages/core/core-flows/src/cart/steps/get-variant-price-sets.ts packages/core/core-flows/src/cart/workflows/add-to-cart.ts packages/core/core-flows/src/cart/workflows/create-carts.ts packages/core/core-flows/src/cart/workflows/get-variants-and-items-with-prices.ts packages/core/core-flows/src/cart/workflows/refresh-cart-items.ts packages/core/core-flows/src/order/workflows/add-line-items.ts packages/core/core-flows/src/order/workflows/create-order.ts ```
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/core-flows": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(): Cart workflow price calculation for different items but same variant
|
||||||
@@ -285,6 +285,156 @@ medusaIntegrationTestRunner({
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should successfully create a cart with a line items for the same variant with different quantities and calculate prices based on the correct quantity", async () => {
|
||||||
|
const productData = {
|
||||||
|
title: "Medusa T-Shirt based quantity",
|
||||||
|
handle: "t-shirt-with-quantity-prices",
|
||||||
|
status: ProductStatus.PUBLISHED,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
title: "Size",
|
||||||
|
values: ["S"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
title: "S",
|
||||||
|
sku: "SHIRT-S-BLACK-w-quantity-prices",
|
||||||
|
options: {
|
||||||
|
Size: "S",
|
||||||
|
},
|
||||||
|
manage_inventory: false,
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
amount: 1500,
|
||||||
|
currency_code: "usd",
|
||||||
|
min_quantity: 1,
|
||||||
|
max_quantity: 4,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: 1000,
|
||||||
|
currency_code: "usd",
|
||||||
|
min_quantity: 5,
|
||||||
|
max_quantity: 10,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const newProduct = await api.post(
|
||||||
|
`/admin/products`,
|
||||||
|
productData,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const variantId = newProduct.data.product.variants[0].id
|
||||||
|
|
||||||
|
const newCart = (
|
||||||
|
await api.post(
|
||||||
|
`/store/carts`,
|
||||||
|
{
|
||||||
|
currency_code: "usd",
|
||||||
|
sales_channel_id: salesChannel.id,
|
||||||
|
region_id: region.id,
|
||||||
|
shipping_address: shippingAddressData,
|
||||||
|
items: [{ variant_id: variantId, quantity: 6 }],
|
||||||
|
},
|
||||||
|
storeHeaders
|
||||||
|
)
|
||||||
|
).data.cart
|
||||||
|
|
||||||
|
expect(newCart).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
item_subtotal: 5714.285714285715,
|
||||||
|
item_tax_total: 285.7142857142857,
|
||||||
|
item_total: 6000,
|
||||||
|
items: [
|
||||||
|
expect.objectContaining({
|
||||||
|
quantity: 6,
|
||||||
|
title: "Medusa T-Shirt based quantity",
|
||||||
|
unit_price: 1000,
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
variant_barcode: null,
|
||||||
|
variant_id: expect.any(String),
|
||||||
|
variant_sku: "SHIRT-S-BLACK-w-quantity-prices",
|
||||||
|
variant_title: "S",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
original_item_subtotal: 5714.285714285715,
|
||||||
|
original_item_tax_total: 285.7142857142857,
|
||||||
|
original_item_total: 6000,
|
||||||
|
original_shipping_subtotal: 0,
|
||||||
|
original_shipping_tax_total: 0,
|
||||||
|
original_shipping_total: 0,
|
||||||
|
original_tax_total: 285.7142857142857,
|
||||||
|
original_total: 6000,
|
||||||
|
shipping_subtotal: 0,
|
||||||
|
shipping_tax_total: 0,
|
||||||
|
shipping_total: 0,
|
||||||
|
subtotal: 5714.285714285715,
|
||||||
|
tax_total: 285.7142857142857,
|
||||||
|
total: 6000,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
const updatedCart = (
|
||||||
|
await api.post(
|
||||||
|
`/store/carts/${newCart.id}/line-items`,
|
||||||
|
{
|
||||||
|
variant_id: variantId,
|
||||||
|
quantity: 1,
|
||||||
|
metadata: { custom: true },
|
||||||
|
},
|
||||||
|
storeHeaders
|
||||||
|
)
|
||||||
|
).data.cart
|
||||||
|
|
||||||
|
expect(updatedCart).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
item_subtotal: 7142.857142857143,
|
||||||
|
item_tax_total: 357.14285714285717,
|
||||||
|
item_total: 7500,
|
||||||
|
items: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
quantity: 6,
|
||||||
|
title: "Medusa T-Shirt based quantity",
|
||||||
|
unit_price: 1000,
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
variant_barcode: null,
|
||||||
|
variant_id: expect.any(String),
|
||||||
|
variant_sku: "SHIRT-S-BLACK-w-quantity-prices",
|
||||||
|
variant_title: "S",
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
quantity: 1,
|
||||||
|
title: "Medusa T-Shirt based quantity",
|
||||||
|
unit_price: 1500,
|
||||||
|
updated_at: expect.any(String),
|
||||||
|
variant_barcode: null,
|
||||||
|
variant_id: expect.any(String),
|
||||||
|
variant_sku: "SHIRT-S-BLACK-w-quantity-prices",
|
||||||
|
variant_title: "S",
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
original_item_subtotal: 7142.857142857143,
|
||||||
|
original_item_tax_total: 357.14285714285717,
|
||||||
|
original_item_total: 7500,
|
||||||
|
original_shipping_subtotal: 0,
|
||||||
|
original_shipping_tax_total: 0,
|
||||||
|
original_shipping_total: 0,
|
||||||
|
original_tax_total: 357.14285714285717,
|
||||||
|
original_total: 7500,
|
||||||
|
shipping_subtotal: 0,
|
||||||
|
shipping_tax_total: 0,
|
||||||
|
shipping_total: 0,
|
||||||
|
subtotal: 7142.857142857143,
|
||||||
|
tax_total: 357.14285714285717,
|
||||||
|
total: 7500,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
describe("with sale price lists", () => {
|
describe("with sale price lists", () => {
|
||||||
let priceList
|
let priceList
|
||||||
|
|
||||||
|
|||||||
@@ -1881,7 +1881,7 @@ medusaIntegrationTestRunner({
|
|||||||
|
|
||||||
expect(errors).toEqual([
|
expect(errors).toEqual([
|
||||||
{
|
{
|
||||||
action: "get-variant-price-sets",
|
action: "get-variant-items-with-prices-workflow-as-step",
|
||||||
handlerType: "invoke",
|
handlerType: "invoke",
|
||||||
error: expect.objectContaining({
|
error: expect.objectContaining({
|
||||||
message: expect.stringContaining(
|
message: expect.stringContaining(
|
||||||
@@ -4307,18 +4307,20 @@ medusaIntegrationTestRunner({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const { result: result1 } = await listShippingOptionsForCartWorkflow(
|
const { result: result1 } =
|
||||||
appContainer
|
await listShippingOptionsForCartWorkflow(appContainer).run({
|
||||||
).run({ input: { cart_id: cart.id } })
|
input: { cart_id: cart.id },
|
||||||
|
})
|
||||||
|
|
||||||
expect(result1).toHaveLength(1)
|
expect(result1).toHaveLength(1)
|
||||||
expect(result1[0].name).toEqual(shippingOption.name)
|
expect(result1[0].name).toEqual(shippingOption.name)
|
||||||
|
|
||||||
setShippingOptionsContextHook = undefined
|
setShippingOptionsContextHook = undefined
|
||||||
|
|
||||||
const { result: result2 } = await listShippingOptionsForCartWorkflow(
|
const { result: result2 } =
|
||||||
appContainer
|
await listShippingOptionsForCartWorkflow(appContainer).run({
|
||||||
).run({ input: { cart_id: cart.id } })
|
input: { cart_id: cart.id },
|
||||||
|
})
|
||||||
|
|
||||||
expect(result2).toHaveLength(0)
|
expect(result2).toHaveLength(0)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { IApiKeyModuleService } from "@medusajs/framework/types"
|
import type { IApiKeyModuleService } from "@medusajs/framework/types"
|
||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import { LinkWorkflowInput } from "@medusajs/framework/types"
|
import type { LinkWorkflowInput } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
Modules,
|
Modules,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ISalesChannelModuleService } from "@medusajs/framework/types"
|
import type { ISalesChannelModuleService } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
MedusaError,
|
MedusaError,
|
||||||
Modules,
|
Modules,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ApiKeyDTO, CreateApiKeyDTO } from "@medusajs/framework/types"
|
import type { ApiKeyDTO, CreateApiKeyDTO } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
WorkflowData,
|
WorkflowData,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import { LinkWorkflowInput } from "@medusajs/framework/types"
|
import type { LinkWorkflowInput } from "@medusajs/framework/types"
|
||||||
import { WorkflowData, createWorkflow } from "@medusajs/framework/workflows-sdk"
|
import { WorkflowData, createWorkflow } from "@medusajs/framework/workflows-sdk"
|
||||||
import {
|
import {
|
||||||
linkSalesChannelsToApiKeyStep,
|
linkSalesChannelsToApiKeyStep,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
import { IAuthModuleService } from "@medusajs/framework/types"
|
import type { IAuthModuleService } from "@medusajs/framework/types"
|
||||||
import { isDefined, Modules } from "@medusajs/framework/utils"
|
import { isDefined, Modules } from "@medusajs/framework/utils"
|
||||||
|
|
||||||
export type SetAuthAppMetadataStepInput = {
|
export type SetAuthAppMetadataStepInput = {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { emitEventStep, useRemoteQueryStep } from "../../common"
|
import { emitEventStep, useRemoteQueryStep } from "../../common"
|
||||||
import { ProjectConfigOptions } from "@medusajs/framework/types"
|
import type { ProjectConfigOptions } from "@medusajs/framework/types"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This workflow generates a reset password token for a user. It's used by the
|
* This workflow generates a reset password token for a user. It's used by the
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Logger } from "@medusajs/framework/types"
|
import type { Logger } from "@medusajs/framework/types"
|
||||||
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
import { refundPaymentAndRecreatePaymentSessionWorkflow } from "../workflows/refund-payment-recreate-payment-session"
|
import { refundPaymentAndRecreatePaymentSessionWorkflow } from "../workflows/refund-payment-recreate-payment-session"
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { BigNumberInput, IInventoryService } from "@medusajs/framework/types"
|
import type {
|
||||||
|
BigNumberInput,
|
||||||
|
IInventoryService,
|
||||||
|
} from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
MathBN,
|
MathBN,
|
||||||
MedusaError,
|
MedusaError,
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { CreateCartDTO, ICartModuleService } from "@medusajs/framework/types"
|
import type {
|
||||||
|
CreateCartDTO,
|
||||||
|
ICartModuleService,
|
||||||
|
} from "@medusajs/framework/types"
|
||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { CustomerDTO, ICustomerModuleService } from "@medusajs/framework/types"
|
import type {
|
||||||
|
CustomerDTO,
|
||||||
|
ICustomerModuleService,
|
||||||
|
} from "@medusajs/framework/types"
|
||||||
import { isDefined, Modules, validateEmail } from "@medusajs/framework/utils"
|
import { isDefined, Modules, validateEmail } from "@medusajs/framework/utils"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { CartDTO, IPromotionModuleService } from "@medusajs/framework/types"
|
import type {
|
||||||
|
CartDTO,
|
||||||
|
IPromotionModuleService,
|
||||||
|
} from "@medusajs/framework/types"
|
||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { IPromotionModuleService } from "@medusajs/framework/types"
|
import type { IPromotionModuleService } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
MedusaError,
|
MedusaError,
|
||||||
Modules,
|
Modules,
|
||||||
@@ -79,7 +79,7 @@ export const getPromotionCodesToApply = createStep(
|
|||||||
const adjustmentCodes: string[] = []
|
const adjustmentCodes: string[] = []
|
||||||
items.concat(shipping_methods).forEach((object) => {
|
items.concat(shipping_methods).forEach((object) => {
|
||||||
object.adjustments?.forEach((adjustment) => {
|
object.adjustments?.forEach((adjustment) => {
|
||||||
if (adjustment.code && !adjustmentCodes.includes(adjustment.code)) {
|
if (adjustment.code) {
|
||||||
adjustmentCodes.push(adjustment.code)
|
adjustmentCodes.push(adjustment.code)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ export interface GetVariantPriceSetsStepBulkInput {
|
|||||||
* The variants to get price sets for.
|
* The variants to get price sets for.
|
||||||
*/
|
*/
|
||||||
data: {
|
data: {
|
||||||
|
/**
|
||||||
|
* The ID of the item.
|
||||||
|
*/
|
||||||
|
id?: string
|
||||||
/**
|
/**
|
||||||
* The ID of the variant to get the price set for.
|
* The ID of the variant to get the price set for.
|
||||||
*/
|
*/
|
||||||
@@ -51,6 +55,10 @@ interface VariantPriceSetData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface PriceCalculationItem {
|
interface PriceCalculationItem {
|
||||||
|
/**
|
||||||
|
* The ID of the item. In case of variants we wont have an item id
|
||||||
|
*/
|
||||||
|
id?: string
|
||||||
variantId: string
|
variantId: string
|
||||||
priceSetId: string
|
priceSetId: string
|
||||||
context?: Record<string, unknown>
|
context?: Record<string, unknown>
|
||||||
@@ -124,7 +132,7 @@ async function processVariantPriceSets(
|
|||||||
for (const item of groupItems) {
|
for (const item of groupItems) {
|
||||||
const calculatedPriceSet = priceSetMap.get(item.priceSetId)
|
const calculatedPriceSet = priceSetMap.get(item.priceSetId)
|
||||||
if (calculatedPriceSet) {
|
if (calculatedPriceSet) {
|
||||||
result[item.variantId] = calculatedPriceSet
|
result[item.id ?? item.variantId] = calculatedPriceSet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -196,6 +204,7 @@ function createCalculationItemsFromBulkData(
|
|||||||
const priceSetId = variantToPriceSetId.get(item.variantId)
|
const priceSetId = variantToPriceSetId.get(item.variantId)
|
||||||
if (priceSetId) {
|
if (priceSetId) {
|
||||||
calculationItems.push({
|
calculationItems.push({
|
||||||
|
id: item.id,
|
||||||
variantId: item.variantId,
|
variantId: item.variantId,
|
||||||
priceSetId,
|
priceSetId,
|
||||||
context: item.context,
|
context: item.context,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ICartModuleService } from "@medusajs/framework/types"
|
import type { ICartModuleService } from "@medusajs/framework/types"
|
||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ICartModuleService } from "@medusajs/framework/types"
|
import type { ICartModuleService } from "@medusajs/framework/types"
|
||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ICartModuleService } from "@medusajs/framework/types"
|
import type { ICartModuleService } from "@medusajs/framework/types"
|
||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
@@ -16,7 +16,10 @@ export interface RemoveShippingMethodFromCartStepInput {
|
|||||||
* The shipping methods removed from the cart, along with IDs of related records
|
* The shipping methods removed from the cart, along with IDs of related records
|
||||||
* that were removed.
|
* that were removed.
|
||||||
*/
|
*/
|
||||||
export type RemoveShippingMethodFromCartStepOutput = Record<string, string[]> | void
|
export type RemoveShippingMethodFromCartStepOutput = Record<
|
||||||
|
string,
|
||||||
|
string[]
|
||||||
|
> | void
|
||||||
|
|
||||||
export const removeShippingMethodFromCartStepId =
|
export const removeShippingMethodFromCartStepId =
|
||||||
"remove-shipping-method-to-cart-step"
|
"remove-shipping-method-to-cart-step"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { MathBN, Modules } from "@medusajs/framework/utils"
|
import { MathBN, Modules } from "@medusajs/framework/utils"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
import { BigNumberInput } from "@medusajs/types"
|
import type { BigNumberInput } from "@medusajs/framework/types"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The details of the items and their quantity to reserve.
|
* The details of the items and their quantity to reserve.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { IPromotionModuleService } from "@medusajs/framework/types"
|
import type { IPromotionModuleService } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
Modules,
|
Modules,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { CartWorkflowDTO } from "@medusajs/framework/types"
|
import type { CartWorkflowDTO } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
isPresent,
|
isPresent,
|
||||||
MathBN,
|
MathBN,
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
import { CartDTO, IFulfillmentModuleService } from "@medusajs/framework/types"
|
import type {
|
||||||
import { arrayDifference, MedusaError, Modules, } from "@medusajs/framework/utils"
|
CartDTO,
|
||||||
|
IFulfillmentModuleService,
|
||||||
|
} from "@medusajs/framework/types"
|
||||||
|
import {
|
||||||
|
arrayDifference,
|
||||||
|
MedusaError,
|
||||||
|
Modules,
|
||||||
|
} from "@medusajs/framework/utils"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,7 +59,12 @@ export const validateCartShippingOptionsStepId =
|
|||||||
export const validateCartShippingOptionsStep = createStep(
|
export const validateCartShippingOptionsStep = createStep(
|
||||||
validateCartShippingOptionsStepId,
|
validateCartShippingOptionsStepId,
|
||||||
async (data: ValidateCartShippingOptionsStepInput, { container }) => {
|
async (data: ValidateCartShippingOptionsStepInput, { container }) => {
|
||||||
const { option_ids: optionIds = [], cart, shippingOptionsContext, prefetched_shipping_options: prefetchedShippingOptions } = data
|
const {
|
||||||
|
option_ids: optionIds = [],
|
||||||
|
cart,
|
||||||
|
shippingOptionsContext,
|
||||||
|
prefetched_shipping_options: prefetchedShippingOptions,
|
||||||
|
} = data
|
||||||
|
|
||||||
if (!optionIds.length) {
|
if (!optionIds.length) {
|
||||||
return new StepResponse(void 0)
|
return new StepResponse(void 0)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { CartDTO, CartWorkflowDTO } from "@medusajs/framework/types"
|
import type { CartDTO, CartWorkflowDTO } from "@medusajs/framework/types"
|
||||||
import { MedusaError } from "@medusajs/framework/utils"
|
import { MedusaError } from "@medusajs/framework/utils"
|
||||||
import { createStep } from "@medusajs/framework/workflows-sdk"
|
import { createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { MedusaError } from "@medusajs/framework/utils"
|
import { MedusaError } from "@medusajs/framework/utils"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
import { SalesChannelDTO } from "@medusajs/types"
|
import type { SalesChannelDTO } from "@medusajs/framework/types"
|
||||||
|
|
||||||
export const validateSalesChannelStep = createStep(
|
export const validateSalesChannelStep = createStep(
|
||||||
"validate-sales-channel",
|
"validate-sales-channel",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Modules, promiseAll } from "@medusajs/framework/utils"
|
|||||||
import {
|
import {
|
||||||
IFulfillmentModuleService,
|
IFulfillmentModuleService,
|
||||||
ValidateFulfillmentDataContext,
|
ValidateFulfillmentDataContext,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/framework/types"
|
||||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,9 +36,11 @@ export type ValidateShippingMethodsDataInput = {
|
|||||||
/**
|
/**
|
||||||
* The validated data of the shipping methods.
|
* The validated data of the shipping methods.
|
||||||
*/
|
*/
|
||||||
export type ValidateShippingMethodsDataOutput = void | {
|
export type ValidateShippingMethodsDataOutput =
|
||||||
[x: string]: Record<string, unknown>;
|
| void
|
||||||
}[]
|
| {
|
||||||
|
[x: string]: Record<string, unknown>
|
||||||
|
}[]
|
||||||
|
|
||||||
export const validateAndReturnShippingMethodsDataStepId =
|
export const validateAndReturnShippingMethodsDataStepId =
|
||||||
"validate-and-return-shipping-methods-data"
|
"validate-and-return-shipping-methods-data"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
CartWorkflowDTO,
|
CartWorkflowDTO,
|
||||||
ProductVariantDTO,
|
ProductVariantDTO,
|
||||||
ShippingOptionDTO,
|
ShippingOptionDTO,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/framework/types"
|
||||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { BigNumberInput } from "@medusajs/framework/types"
|
import type { BigNumberInput } from "@medusajs/framework/types"
|
||||||
import { MedusaError, isPresent } from "@medusajs/framework/utils"
|
import { MedusaError, isPresent } from "@medusajs/framework/utils"
|
||||||
import { createStep } from "@medusajs/framework/workflows-sdk"
|
import { createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import { ConfirmVariantInventoryWorkflowInputDTO } from "@medusajs/framework/types"
|
import type { ConfirmVariantInventoryWorkflowInputDTO } from "@medusajs/framework/types"
|
||||||
import { MedusaError } from "@medusajs/framework/utils"
|
import { MedusaError } from "@medusajs/framework/utils"
|
||||||
import { prepareConfirmInventoryInput } from "../prepare-confirm-inventory-input"
|
import { prepareConfirmInventoryInput } from "../prepare-confirm-inventory-input"
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,11 @@ import {
|
|||||||
AdditionalData,
|
AdditionalData,
|
||||||
AddToCartWorkflowInputDTO,
|
AddToCartWorkflowInputDTO,
|
||||||
ConfirmVariantInventoryWorkflowInputDTO,
|
ConfirmVariantInventoryWorkflowInputDTO,
|
||||||
WithCalculatedPrice,
|
CreateLineItemForCartDTO,
|
||||||
} from "@medusajs/framework/types"
|
} from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
CartWorkflowEvents,
|
CartWorkflowEvents,
|
||||||
deduplicate,
|
deduplicate,
|
||||||
filterObjectByKeys,
|
|
||||||
isDefined,
|
isDefined,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
import {
|
import {
|
||||||
@@ -16,7 +15,6 @@ import {
|
|||||||
parallelize,
|
parallelize,
|
||||||
transform,
|
transform,
|
||||||
when,
|
when,
|
||||||
WorkflowData,
|
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { useQueryGraphStep } from "../../common"
|
import { useQueryGraphStep } from "../../common"
|
||||||
@@ -25,12 +23,10 @@ import { acquireLockStep, releaseLockStep } from "../../locking"
|
|||||||
import {
|
import {
|
||||||
createLineItemsStep,
|
createLineItemsStep,
|
||||||
getLineItemActionsStep,
|
getLineItemActionsStep,
|
||||||
getVariantPriceSetsStep,
|
|
||||||
updateLineItemsStep,
|
updateLineItemsStep,
|
||||||
} from "../steps"
|
} from "../steps"
|
||||||
import { validateCartStep } from "../steps/validate-cart"
|
import { validateCartStep } from "../steps/validate-cart"
|
||||||
import { validateLineItemPricesStep } from "../steps/validate-line-item-prices"
|
import { validateLineItemPricesStep } from "../steps/validate-line-item-prices"
|
||||||
import { validateVariantPricesStep } from "../steps/validate-variant-prices"
|
|
||||||
import {
|
import {
|
||||||
cartFieldsForPricingContext,
|
cartFieldsForPricingContext,
|
||||||
productVariantsFields,
|
productVariantsFields,
|
||||||
@@ -43,6 +39,7 @@ import {
|
|||||||
} from "../utils/prepare-line-item-data"
|
} from "../utils/prepare-line-item-data"
|
||||||
import { pricingContextResult } from "../utils/schemas"
|
import { pricingContextResult } from "../utils/schemas"
|
||||||
import { confirmVariantInventoryWorkflow } from "./confirm-variant-inventory"
|
import { confirmVariantInventoryWorkflow } from "./confirm-variant-inventory"
|
||||||
|
import { getVariantsAndItemsWithPrices } from "./get-variants-and-items-with-prices"
|
||||||
import { refreshCartItemsWorkflow } from "./refresh-cart-items"
|
import { refreshCartItemsWorkflow } from "./refresh-cart-items"
|
||||||
|
|
||||||
const cartFields = ["completed_at"].concat(cartFieldsForPricingContext)
|
const cartFields = ["completed_at"].concat(cartFieldsForPricingContext)
|
||||||
@@ -119,32 +116,30 @@ export const addToCartWorkflow = createWorkflow(
|
|||||||
name: addToCartWorkflowId,
|
name: addToCartWorkflowId,
|
||||||
idempotent: false,
|
idempotent: false,
|
||||||
},
|
},
|
||||||
(input: WorkflowData<AddToCartWorkflowInputDTO & AdditionalData>) => {
|
(input: AddToCartWorkflowInputDTO & AdditionalData) => {
|
||||||
acquireLockStep({
|
acquireLockStep({
|
||||||
key: input.cart_id,
|
key: input.cart_id,
|
||||||
timeout: 2,
|
timeout: 2,
|
||||||
ttl: 10,
|
ttl: 10,
|
||||||
})
|
})
|
||||||
|
|
||||||
const cartQuery = useQueryGraphStep({
|
const { data: cart } = useQueryGraphStep({
|
||||||
entity: "cart",
|
entity: "cart",
|
||||||
filters: { id: input.cart_id },
|
filters: { id: input.cart_id },
|
||||||
fields: cartFields,
|
fields: cartFields,
|
||||||
options: { throwIfKeyNotFound: true },
|
options: { throwIfKeyNotFound: true, isList: false },
|
||||||
}).config({ name: "get-cart" })
|
}).config({ name: "get-cart" })
|
||||||
|
|
||||||
const cart = transform({ cartQuery }, ({ cartQuery }) => {
|
|
||||||
return cartQuery.data[0]
|
|
||||||
})
|
|
||||||
|
|
||||||
validateCartStep({ cart })
|
validateCartStep({ cart })
|
||||||
const validate = createHook("validate", {
|
const validate = createHook("validate", {
|
||||||
input,
|
input,
|
||||||
cart,
|
cart,
|
||||||
})
|
})
|
||||||
|
|
||||||
const variantIds = transform({ input }, (data) => {
|
const variantIds = transform({ input }, (data): string[] => {
|
||||||
return (data.input.items ?? []).map((i) => i.variant_id).filter(Boolean)
|
return (data.input.items ?? [])
|
||||||
|
.map((i) => i.variant_id)
|
||||||
|
.filter((v): v is string => !!v)
|
||||||
})
|
})
|
||||||
|
|
||||||
const setPricingContext = createHook(
|
const setPricingContext = createHook(
|
||||||
@@ -162,43 +157,46 @@ export const addToCartWorkflow = createWorkflow(
|
|||||||
|
|
||||||
const setPricingContextResult = setPricingContext.getResult()
|
const setPricingContextResult = setPricingContext.getResult()
|
||||||
|
|
||||||
const variants = when(
|
const { variants: variantsData, lineItems: lineItemsData } = when(
|
||||||
"should-calculate-prices",
|
"should-calculate-prices",
|
||||||
{ variantIds },
|
{ variantIds },
|
||||||
({ variantIds }) => {
|
({ variantIds }) => {
|
||||||
return !!variantIds.length
|
return !!variantIds.length
|
||||||
}
|
}
|
||||||
).then(() => {
|
).then(() => {
|
||||||
const pricingContext = transform(
|
const { variants: variantsData, lineItems: items } =
|
||||||
{ cart, items: input.items, setPricingContextResult },
|
getVariantsAndItemsWithPrices.runAsStep({
|
||||||
(data): { variantId: string; context: Record<string, unknown> }[] => {
|
input: {
|
||||||
const baseContext = {
|
cart,
|
||||||
...filterObjectByKeys(data.cart, cartFieldsForPricingContext),
|
items: input.items,
|
||||||
...(data.setPricingContextResult
|
setPricingContextResult: setPricingContextResult!,
|
||||||
? data.setPricingContextResult
|
variants: {
|
||||||
: {}),
|
id: variantIds,
|
||||||
currency_code: data.cart.currency_code,
|
fields: deduplicate([
|
||||||
region_id: data.cart.region_id,
|
...productVariantsFields,
|
||||||
region: data.cart.region,
|
...requiredVariantFieldsForInventoryConfirmation,
|
||||||
customer_id: data.cart.customer_id,
|
]),
|
||||||
customer: data.cart.customer,
|
},
|
||||||
}
|
|
||||||
|
|
||||||
return data.items
|
|
||||||
.filter((i) => i.variant_id)
|
|
||||||
.map((item) => {
|
|
||||||
return {
|
|
||||||
variantId: item.variant_id!,
|
|
||||||
context: {
|
|
||||||
...baseContext,
|
|
||||||
quantity: item.quantity,
|
|
||||||
},
|
},
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const { data: variantsData } = useQueryGraphStep({
|
const lineItems = transform({ items }, ({ items }) => {
|
||||||
|
return items.map((item) => {
|
||||||
|
return item.data as CreateLineItemForCartDTO
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return { variants: variantsData, lineItems }
|
||||||
|
})
|
||||||
|
|
||||||
|
const fetchedVariants = when(
|
||||||
|
"fetch-variants",
|
||||||
|
{ variantsData, variantIds },
|
||||||
|
({ variantsData, variantIds }) => {
|
||||||
|
return !variantsData?.length && !!variantIds.length
|
||||||
|
}
|
||||||
|
).then(() => {
|
||||||
|
return useQueryGraphStep({
|
||||||
entity: "variants",
|
entity: "variants",
|
||||||
fields: deduplicate([
|
fields: deduplicate([
|
||||||
...productVariantsFields,
|
...productVariantsFields,
|
||||||
@@ -207,39 +205,33 @@ export const addToCartWorkflow = createWorkflow(
|
|||||||
filters: {
|
filters: {
|
||||||
id: variantIds,
|
id: variantIds,
|
||||||
},
|
},
|
||||||
})
|
}).config({ name: "fetch-variants" })
|
||||||
|
|
||||||
const calculatedPriceSets = getVariantPriceSetsStep({
|
|
||||||
data: pricingContext,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const variants = transform(
|
const variants = transform(
|
||||||
{ variantsData, calculatedPriceSets },
|
{ variantsData, fetchedVariants },
|
||||||
({ variantsData, calculatedPriceSets }) => {
|
({ variantsData, fetchedVariants }) => {
|
||||||
return variantsData.map((variant) => {
|
return (variantsData ??
|
||||||
variant.calculated_price = calculatedPriceSets[variant.id]
|
fetchedVariants) as unknown as PrepareVariantLineItemInput[]
|
||||||
return variant
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
validateVariantPricesStep({ variants })
|
const lineItems = transform(
|
||||||
|
{ cart_id: input.cart_id, items: input.items, lineItemsData, variants },
|
||||||
|
({ cart_id, items: items_, lineItemsData, variants }) => {
|
||||||
|
if (lineItemsData?.length) {
|
||||||
|
return lineItemsData
|
||||||
|
}
|
||||||
|
|
||||||
return variants as (PrepareVariantLineItemInput &
|
const items = (items_ ?? []).map((item) => {
|
||||||
ConfirmVariantInventoryWorkflowInputDTO["variants"][number] &
|
const variant = (variants ?? []).find(
|
||||||
WithCalculatedPrice)[]
|
|
||||||
})
|
|
||||||
|
|
||||||
const lineItems = transform({ input, variants }, (data) => {
|
|
||||||
const items = (data.input.items ?? []).map((item) => {
|
|
||||||
const variant = (data.variants ?? []).find(
|
|
||||||
(v) => v.id === item.variant_id
|
(v) => v.id === item.variant_id
|
||||||
)!
|
)!
|
||||||
|
|
||||||
const input: PrepareLineItemDataInput = {
|
const input: PrepareLineItemDataInput = {
|
||||||
item,
|
item,
|
||||||
variant: variant,
|
variant: variant,
|
||||||
cartId: data.input.cart_id,
|
cartId: cart_id,
|
||||||
unitPrice: item.unit_price,
|
unitPrice: item.unit_price,
|
||||||
isTaxInclusive:
|
isTaxInclusive:
|
||||||
item.is_tax_inclusive ??
|
item.is_tax_inclusive ??
|
||||||
@@ -255,7 +247,8 @@ export const addToCartWorkflow = createWorkflow(
|
|||||||
})
|
})
|
||||||
|
|
||||||
return items
|
return items
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
validateLineItemPricesStep({ items: lineItems })
|
validateLineItemPricesStep({ items: lineItems })
|
||||||
|
|
||||||
@@ -287,7 +280,8 @@ export const addToCartWorkflow = createWorkflow(
|
|||||||
confirmVariantInventoryWorkflow.runAsStep({
|
confirmVariantInventoryWorkflow.runAsStep({
|
||||||
input: {
|
input: {
|
||||||
sales_channel_id: cart.sales_channel_id,
|
sales_channel_id: cart.sales_channel_id,
|
||||||
variants,
|
variants:
|
||||||
|
variants as unknown as ConfirmVariantInventoryWorkflowInputDTO["variants"],
|
||||||
items: input.items,
|
items: input.items,
|
||||||
itemsToUpdate: itemsToConfirmInventory,
|
itemsToUpdate: itemsToConfirmInventory,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { ConfirmVariantInventoryWorkflowInputDTO } from "@medusajs/framework/types"
|
import type { ConfirmVariantInventoryWorkflowInputDTO } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
WorkflowData,
|
WorkflowData,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
createWorkflow,
|
createWorkflow,
|
||||||
transform,
|
transform,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { BigNumberInput } from "@medusajs/types"
|
import type { BigNumberInput } from "@medusajs/framework/types"
|
||||||
import { confirmInventoryStep } from "../steps"
|
import { confirmInventoryStep } from "../steps"
|
||||||
import { prepareConfirmInventoryInput } from "../utils/prepare-confirm-inventory-input"
|
import { prepareConfirmInventoryInput } from "../utils/prepare-confirm-inventory-input"
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import {
|
import {
|
||||||
AdditionalData,
|
AdditionalData,
|
||||||
|
ConfirmVariantInventoryWorkflowInputDTO,
|
||||||
|
CreateCartDTO,
|
||||||
CreateCartWorkflowInputDTO,
|
CreateCartWorkflowInputDTO,
|
||||||
} from "@medusajs/framework/types"
|
} from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
CartWorkflowEvents,
|
CartWorkflowEvents,
|
||||||
deduplicate,
|
deduplicate,
|
||||||
isDefined,
|
|
||||||
MedusaError,
|
MedusaError,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
import {
|
import {
|
||||||
@@ -13,30 +14,22 @@ import {
|
|||||||
createWorkflow,
|
createWorkflow,
|
||||||
parallelize,
|
parallelize,
|
||||||
transform,
|
transform,
|
||||||
when,
|
|
||||||
WorkflowData,
|
WorkflowData,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { useQueryGraphStep } from "../../common"
|
|
||||||
import { emitEventStep } from "../../common/steps/emit-event"
|
import { emitEventStep } from "../../common/steps/emit-event"
|
||||||
import {
|
import {
|
||||||
createCartsStep,
|
createCartsStep,
|
||||||
findOneOrAnyRegionStep,
|
findOneOrAnyRegionStep,
|
||||||
findOrCreateCustomerStep,
|
findOrCreateCustomerStep,
|
||||||
findSalesChannelStep,
|
findSalesChannelStep,
|
||||||
getVariantPriceSetsStep,
|
|
||||||
} from "../steps"
|
} from "../steps"
|
||||||
import { validateLineItemPricesStep } from "../steps/validate-line-item-prices"
|
|
||||||
import { validateSalesChannelStep } from "../steps/validate-sales-channel"
|
import { validateSalesChannelStep } from "../steps/validate-sales-channel"
|
||||||
import { validateVariantPricesStep } from "../steps/validate-variant-prices"
|
|
||||||
import { productVariantsFields } from "../utils/fields"
|
import { productVariantsFields } from "../utils/fields"
|
||||||
import { requiredVariantFieldsForInventoryConfirmation } from "../utils/prepare-confirm-inventory-input"
|
import { requiredVariantFieldsForInventoryConfirmation } from "../utils/prepare-confirm-inventory-input"
|
||||||
import {
|
|
||||||
prepareLineItemData,
|
|
||||||
PrepareLineItemDataInput,
|
|
||||||
} from "../utils/prepare-line-item-data"
|
|
||||||
import { pricingContextResult } from "../utils/schemas"
|
import { pricingContextResult } from "../utils/schemas"
|
||||||
import { confirmVariantInventoryWorkflow } from "./confirm-variant-inventory"
|
import { confirmVariantInventoryWorkflow } from "./confirm-variant-inventory"
|
||||||
|
import { getVariantsAndItemsWithPrices } from "./get-variants-and-items-with-prices"
|
||||||
import { refreshPaymentCollectionForCartWorkflow } from "./refresh-payment-collection"
|
import { refreshPaymentCollectionForCartWorkflow } from "./refresh-payment-collection"
|
||||||
import { updateCartPromotionsWorkflow } from "./update-cart-promotions"
|
import { updateCartPromotionsWorkflow } from "./update-cart-promotions"
|
||||||
import { updateTaxLinesWorkflow } from "./update-tax-lines"
|
import { updateTaxLinesWorkflow } from "./update-tax-lines"
|
||||||
@@ -119,7 +112,9 @@ export const createCartWorkflow = createWorkflow(
|
|||||||
createCartWorkflowId,
|
createCartWorkflowId,
|
||||||
(input: WorkflowData<CreateCartWorkflowInput>) => {
|
(input: WorkflowData<CreateCartWorkflowInput>) => {
|
||||||
const variantIds = transform({ input }, (data) => {
|
const variantIds = transform({ input }, (data) => {
|
||||||
return (data.input.items ?? []).map((i) => i.variant_id).filter(Boolean)
|
return (data.input.items ?? [])
|
||||||
|
.map((i) => i.variant_id)
|
||||||
|
.filter((v): v is string => !!v)
|
||||||
})
|
})
|
||||||
|
|
||||||
const [salesChannel, region, customerData] = parallelize(
|
const [salesChannel, region, customerData] = parallelize(
|
||||||
@@ -151,79 +146,31 @@ export const createCartWorkflow = createWorkflow(
|
|||||||
)
|
)
|
||||||
const setPricingContextResult = setPricingContext.getResult()
|
const setPricingContextResult = setPricingContext.getResult()
|
||||||
|
|
||||||
// TODO: This is on par with the context used in v1.*, but we can be more flexible.
|
const { variants, lineItems } = getVariantsAndItemsWithPrices.runAsStep({
|
||||||
const pricingContext = transform(
|
input: {
|
||||||
{ input, region, customerData, setPricingContextResult },
|
cart: {
|
||||||
(data) => {
|
currency_code: input.currency_code,
|
||||||
if (!data.region) {
|
region,
|
||||||
throw new MedusaError(MedusaError.Types.NOT_FOUND, "No regions found")
|
region_id: region.id,
|
||||||
}
|
customer_id: customerData.customer?.id,
|
||||||
|
},
|
||||||
return {
|
items: input.items,
|
||||||
...(data.setPricingContextResult ? data.setPricingContextResult : {}),
|
setPricingContextResult: setPricingContextResult!,
|
||||||
currency_code: data.input.currency_code ?? data.region.currency_code,
|
variants: {
|
||||||
region_id: data.region.id,
|
id: variantIds,
|
||||||
customer_id: data.customerData.customer?.id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const variants = when("has-variants", { variantIds }, ({ variantIds }) => {
|
|
||||||
return !!variantIds.length
|
|
||||||
}).then(() => {
|
|
||||||
const { data: variantsData } = useQueryGraphStep({
|
|
||||||
entity: "variants",
|
|
||||||
fields: deduplicate([
|
fields: deduplicate([
|
||||||
...productVariantsFields,
|
...productVariantsFields,
|
||||||
...requiredVariantFieldsForInventoryConfirmation,
|
...requiredVariantFieldsForInventoryConfirmation,
|
||||||
]),
|
]),
|
||||||
filters: {
|
|
||||||
id: variantIds,
|
|
||||||
},
|
},
|
||||||
})
|
|
||||||
|
|
||||||
const calculatedPriceContext = transform(
|
|
||||||
{ pricingContext, items: input.items },
|
|
||||||
(data): { variantId: string; context: Record<string, unknown> }[] => {
|
|
||||||
const baseContext = data.pricingContext
|
|
||||||
|
|
||||||
return (data.items ?? [])
|
|
||||||
.filter((i) => i.variant_id)
|
|
||||||
.map((item) => {
|
|
||||||
return {
|
|
||||||
variantId: item.variant_id!,
|
|
||||||
context: {
|
|
||||||
...baseContext,
|
|
||||||
quantity: item.quantity,
|
|
||||||
},
|
},
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const calculatedPriceSets = getVariantPriceSetsStep({
|
|
||||||
data: calculatedPriceContext,
|
|
||||||
})
|
|
||||||
|
|
||||||
const variants = transform(
|
|
||||||
{ variantsData, calculatedPriceSets },
|
|
||||||
({ variantsData, calculatedPriceSets }) => {
|
|
||||||
return variantsData.map((variant) => {
|
|
||||||
variant.calculated_price = calculatedPriceSets[variant.id]
|
|
||||||
return variant
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
validateVariantPricesStep({ variants })
|
|
||||||
|
|
||||||
return variants
|
|
||||||
})
|
})
|
||||||
|
|
||||||
confirmVariantInventoryWorkflow.runAsStep({
|
confirmVariantInventoryWorkflow.runAsStep({
|
||||||
input: {
|
input: {
|
||||||
sales_channel_id: salesChannel.id,
|
sales_channel_id: salesChannel.id,
|
||||||
variants: variants!,
|
variants:
|
||||||
|
variants as unknown as ConfirmVariantInventoryWorkflowInputDTO["variants"],
|
||||||
items: input.items!,
|
items: input.items!,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -262,39 +209,11 @@ export const createCartWorkflow = createWorkflow(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const lineItems = transform({ input, variants }, (data) => {
|
|
||||||
const items = (data.input.items ?? []).map((item) => {
|
|
||||||
const variant = (data.variants ?? []).find(
|
|
||||||
(v) => v.id === item.variant_id
|
|
||||||
)!
|
|
||||||
|
|
||||||
const input: PrepareLineItemDataInput = {
|
|
||||||
item,
|
|
||||||
variant: variant,
|
|
||||||
unitPrice: item.unit_price,
|
|
||||||
isTaxInclusive:
|
|
||||||
item.is_tax_inclusive ??
|
|
||||||
variant?.calculated_price?.is_calculated_price_tax_inclusive,
|
|
||||||
isCustomPrice: isDefined(item?.unit_price),
|
|
||||||
}
|
|
||||||
|
|
||||||
if (variant && !input.unitPrice) {
|
|
||||||
input.unitPrice = variant.calculated_price?.calculated_amount
|
|
||||||
}
|
|
||||||
|
|
||||||
return prepareLineItemData(input)
|
|
||||||
})
|
|
||||||
|
|
||||||
return items
|
|
||||||
})
|
|
||||||
|
|
||||||
validateLineItemPricesStep({ items: lineItems })
|
|
||||||
|
|
||||||
const cartToCreate = transform({ lineItems, cartInput }, (data) => {
|
const cartToCreate = transform({ lineItems, cartInput }, (data) => {
|
||||||
return {
|
return {
|
||||||
...data.cartInput,
|
...data.cartInput,
|
||||||
items: data.lineItems,
|
items: data.lineItems.map((i) => i.data),
|
||||||
}
|
} as unknown as CreateCartDTO
|
||||||
})
|
})
|
||||||
|
|
||||||
const validate = createHook("validate", {
|
const validate = createHook("validate", {
|
||||||
|
|||||||
@@ -0,0 +1,226 @@
|
|||||||
|
import {
|
||||||
|
BigNumberInput,
|
||||||
|
CartDTO,
|
||||||
|
CartLineItemDTO,
|
||||||
|
CreateCartCreateLineItemDTO,
|
||||||
|
CustomerDTO,
|
||||||
|
OrderWorkflow,
|
||||||
|
RegionDTO,
|
||||||
|
UpdateLineItemDTO,
|
||||||
|
UpdateLineItemWithSelectorDTO,
|
||||||
|
} from "@medusajs/framework/types"
|
||||||
|
import {
|
||||||
|
filterObjectByKeys,
|
||||||
|
isDefined,
|
||||||
|
MedusaError,
|
||||||
|
simpleHash,
|
||||||
|
} from "@medusajs/framework/utils"
|
||||||
|
import {
|
||||||
|
createWorkflow,
|
||||||
|
transform,
|
||||||
|
WorkflowData,
|
||||||
|
WorkflowResponse,
|
||||||
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
|
import { useQueryGraphStep } from "../../common"
|
||||||
|
import { getVariantPriceSetsStep } from "../steps"
|
||||||
|
import {
|
||||||
|
cartFieldsForPricingContext,
|
||||||
|
productVariantsFields,
|
||||||
|
} from "../utils/fields"
|
||||||
|
import {
|
||||||
|
prepareLineItemData,
|
||||||
|
PrepareLineItemDataInput,
|
||||||
|
} from "../utils/prepare-line-item-data"
|
||||||
|
|
||||||
|
interface GetVariantsAndItemsWithPricesWorkflowInput {
|
||||||
|
cart: Partial<CartDTO> & {
|
||||||
|
region?: Partial<RegionDTO>
|
||||||
|
region_id?: string
|
||||||
|
customer?: Partial<CustomerDTO>
|
||||||
|
customer_id?: string
|
||||||
|
}
|
||||||
|
items?: Partial<
|
||||||
|
| CreateCartCreateLineItemDTO
|
||||||
|
| CartLineItemDTO
|
||||||
|
| OrderWorkflow.OrderAddLineItemWorkflowInput["items"][number]
|
||||||
|
>[]
|
||||||
|
setPricingContextResult: object
|
||||||
|
variants?: {
|
||||||
|
id?: string[]
|
||||||
|
fields?: string[]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetVariantsAndItemsWithPricesWorkflowOutput = {
|
||||||
|
// The variant can depend on the requested fields and therefore the caller will know better
|
||||||
|
variants: (object & {
|
||||||
|
calculated_price: {
|
||||||
|
calculated_price: {
|
||||||
|
price_list_type: string
|
||||||
|
}
|
||||||
|
is_calculated_price_tax_inclusive: boolean
|
||||||
|
original_amount: BigNumberInput
|
||||||
|
calculated_amount: BigNumberInput
|
||||||
|
}
|
||||||
|
})[]
|
||||||
|
lineItems: UpdateLineItemWithSelectorDTO[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getVariantsAndItemsWithPricesId =
|
||||||
|
"get-variant-items-with-prices-workflow"
|
||||||
|
export const getVariantsAndItemsWithPrices = createWorkflow(
|
||||||
|
getVariantsAndItemsWithPricesId,
|
||||||
|
(
|
||||||
|
input: WorkflowData<GetVariantsAndItemsWithPricesWorkflowInput>
|
||||||
|
): WorkflowResponse<GetVariantsAndItemsWithPricesWorkflowOutput> => {
|
||||||
|
const variantIds = transform(
|
||||||
|
{ cart: input.cart, items: input.items, variantIds: input.variants?.id },
|
||||||
|
(data): string[] => {
|
||||||
|
if (data.variantIds) {
|
||||||
|
return data.variantIds
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(
|
||||||
|
new Set(
|
||||||
|
(data.cart.items ?? data.items ?? []).map((i) => i.variant_id)
|
||||||
|
)
|
||||||
|
).filter((v): v is string => !!v)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const cartPricingContext = transform(
|
||||||
|
{
|
||||||
|
cart: input.cart,
|
||||||
|
items: input.items,
|
||||||
|
setPricingContextResult: input.setPricingContextResult,
|
||||||
|
},
|
||||||
|
(
|
||||||
|
data
|
||||||
|
): {
|
||||||
|
id: string
|
||||||
|
variantId: string
|
||||||
|
context: Record<string, unknown>
|
||||||
|
}[] => {
|
||||||
|
const cart = data.cart
|
||||||
|
const baseContext = {
|
||||||
|
...filterObjectByKeys(cart, cartFieldsForPricingContext),
|
||||||
|
...(data.setPricingContextResult ? data.setPricingContextResult : {}),
|
||||||
|
currency_code: cart.currency_code ?? cart.region?.currency_code,
|
||||||
|
region_id: cart.region_id,
|
||||||
|
region: cart.region,
|
||||||
|
customer_id: cart.customer_id,
|
||||||
|
customer: cart.customer,
|
||||||
|
}
|
||||||
|
|
||||||
|
return (data.items ?? cart.items ?? [])
|
||||||
|
.filter((i) => i.variant_id)
|
||||||
|
.map((item) => {
|
||||||
|
const idLike =
|
||||||
|
(item as CartLineItemDTO).id ?? simpleHash(JSON.stringify(item))
|
||||||
|
return {
|
||||||
|
id: idLike,
|
||||||
|
variantId: item.variant_id!,
|
||||||
|
context: {
|
||||||
|
...baseContext,
|
||||||
|
quantity: item.quantity,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const variantQueryFields = transform(
|
||||||
|
{ variants: input.variants },
|
||||||
|
(data) => {
|
||||||
|
return data.variants?.fields ?? productVariantsFields
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const { data: variantsData } = useQueryGraphStep({
|
||||||
|
entity: "variants",
|
||||||
|
fields: variantQueryFields,
|
||||||
|
filters: {
|
||||||
|
id: variantIds,
|
||||||
|
},
|
||||||
|
}).config({ name: "fetch-variants" })
|
||||||
|
|
||||||
|
const calculatedPriceSets = getVariantPriceSetsStep({
|
||||||
|
data: cartPricingContext,
|
||||||
|
})
|
||||||
|
|
||||||
|
const variantsItemsWithPrices = transform(
|
||||||
|
{
|
||||||
|
cart: input.cart,
|
||||||
|
items: input.items,
|
||||||
|
variantsData,
|
||||||
|
calculatedPriceSets,
|
||||||
|
},
|
||||||
|
({
|
||||||
|
cart,
|
||||||
|
items: inputItems,
|
||||||
|
variantsData,
|
||||||
|
calculatedPriceSets,
|
||||||
|
}): GetVariantsAndItemsWithPricesWorkflowOutput => {
|
||||||
|
const priceNotFound: string[] = []
|
||||||
|
|
||||||
|
const items = (inputItems ?? cart.items ?? []).map((item) => {
|
||||||
|
const item_ = item as any
|
||||||
|
const idLike =
|
||||||
|
(item as CartLineItemDTO).id ?? simpleHash(JSON.stringify(item))
|
||||||
|
let calculatedPriceSet = calculatedPriceSets[idLike]
|
||||||
|
if (!calculatedPriceSet) {
|
||||||
|
calculatedPriceSet = calculatedPriceSets[item_.variant_id!]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!calculatedPriceSet && item_.variant_id) {
|
||||||
|
priceNotFound.push(item_.variant_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
const variant = variantsData.find((v) => v.id === item.variant_id)
|
||||||
|
|
||||||
|
if (variant) {
|
||||||
|
variant.calculated_price = calculatedPriceSet
|
||||||
|
}
|
||||||
|
|
||||||
|
const isCustomPrice =
|
||||||
|
item_.is_custom_price ?? isDefined(item?.unit_price)
|
||||||
|
|
||||||
|
const input: PrepareLineItemDataInput = {
|
||||||
|
item: item_,
|
||||||
|
variant: variant,
|
||||||
|
cartId: cart.id,
|
||||||
|
unitPrice: item_.unit_price,
|
||||||
|
isTaxInclusive:
|
||||||
|
item_.is_tax_inclusive ??
|
||||||
|
calculatedPriceSet?.is_calculated_price_tax_inclusive,
|
||||||
|
isCustomPrice: isCustomPrice,
|
||||||
|
}
|
||||||
|
|
||||||
|
if (variant && !isCustomPrice) {
|
||||||
|
input.unitPrice = calculatedPriceSet.calculated_amount
|
||||||
|
input.isTaxInclusive =
|
||||||
|
calculatedPriceSet.is_calculated_price_tax_inclusive
|
||||||
|
}
|
||||||
|
|
||||||
|
const preparedItem = prepareLineItemData(input)
|
||||||
|
|
||||||
|
return {
|
||||||
|
selector: { id: (item_ as CartLineItemDTO).id },
|
||||||
|
data: preparedItem as Partial<UpdateLineItemDTO>,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (priceNotFound.length > 0) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.INVALID_DATA,
|
||||||
|
`Variants with IDs ${priceNotFound.join(", ")} do not have a price`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return { variants: variantsData, lineItems: items }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return new WorkflowResponse(variantsItemsWithPrices)
|
||||||
|
}
|
||||||
|
)
|
||||||
+1
-1
@@ -11,7 +11,7 @@ import {
|
|||||||
AdditionalData,
|
AdditionalData,
|
||||||
CalculateShippingOptionPriceDTO,
|
CalculateShippingOptionPriceDTO,
|
||||||
ListShippingOptionsForCartWithPricingWorkflowInput,
|
ListShippingOptionsForCartWithPricingWorkflowInput,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/framework/types"
|
||||||
|
|
||||||
import { useQueryGraphStep, validatePresenceOfStep } from "../../common"
|
import { useQueryGraphStep, validatePresenceOfStep } from "../../common"
|
||||||
import { useRemoteQueryStep } from "../../common/steps/use-remote-query"
|
import { useRemoteQueryStep } from "../../common/steps/use-remote-query"
|
||||||
|
|||||||
@@ -14,9 +14,16 @@ import { cartFieldsForPricingContext } from "../utils/fields"
|
|||||||
import {
|
import {
|
||||||
AdditionalData,
|
AdditionalData,
|
||||||
ListShippingOptionsForCartWorkflowInput,
|
ListShippingOptionsForCartWorkflowInput,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/framework/types"
|
||||||
import { deduplicate, filterObjectByKeys, isDefined } from "@medusajs/framework/utils"
|
import {
|
||||||
import { pricingContextResult, shippingOptionsContextResult } from "../utils/schemas"
|
deduplicate,
|
||||||
|
filterObjectByKeys,
|
||||||
|
isDefined,
|
||||||
|
} from "@medusajs/framework/utils"
|
||||||
|
import {
|
||||||
|
pricingContextResult,
|
||||||
|
shippingOptionsContextResult,
|
||||||
|
} from "../utils/schemas"
|
||||||
|
|
||||||
export const listShippingOptionsForCartWorkflowId =
|
export const listShippingOptionsForCartWorkflowId =
|
||||||
"list-shipping-options-for-cart"
|
"list-shipping-options-for-cart"
|
||||||
@@ -209,16 +216,31 @@ export const listShippingOptionsForCartWorkflow = createWorkflow(
|
|||||||
resultValidator: shippingOptionsContextResult,
|
resultValidator: shippingOptionsContextResult,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
const setShippingOptionsContextResult = setShippingOptionsContext.getResult()
|
const setShippingOptionsContextResult =
|
||||||
|
setShippingOptionsContext.getResult()
|
||||||
|
|
||||||
const queryVariables = transform(
|
const queryVariables = transform(
|
||||||
{ input, fulfillmentSetIds, cart, setPricingContextResult, setShippingOptionsContextResult },
|
{
|
||||||
({ input, fulfillmentSetIds, cart, setPricingContextResult, setShippingOptionsContextResult }) => {
|
input,
|
||||||
|
fulfillmentSetIds,
|
||||||
|
cart,
|
||||||
|
setPricingContextResult,
|
||||||
|
setShippingOptionsContextResult,
|
||||||
|
},
|
||||||
|
({
|
||||||
|
input,
|
||||||
|
fulfillmentSetIds,
|
||||||
|
cart,
|
||||||
|
setPricingContextResult,
|
||||||
|
setShippingOptionsContextResult,
|
||||||
|
}) => {
|
||||||
return {
|
return {
|
||||||
id: input.option_ids,
|
id: input.option_ids,
|
||||||
|
|
||||||
context: {
|
context: {
|
||||||
...(setShippingOptionsContextResult ? setShippingOptionsContextResult : {}),
|
...(setShippingOptionsContextResult
|
||||||
|
? setShippingOptionsContextResult
|
||||||
|
: {}),
|
||||||
is_return: input.is_return ? "true" : "false",
|
is_return: input.is_return ? "true" : "false",
|
||||||
enabled_in_store: !isDefined(input.enabled_in_store)
|
enabled_in_store: !isDefined(input.enabled_in_store)
|
||||||
? "true"
|
? "true"
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import {
|
import type { AdditionalData } from "@medusajs/framework/types"
|
||||||
filterObjectByKeys,
|
import { isDefined, PromotionActions } from "@medusajs/framework/utils"
|
||||||
isDefined,
|
|
||||||
PromotionActions,
|
|
||||||
} from "@medusajs/framework/utils"
|
|
||||||
import {
|
import {
|
||||||
createHook,
|
createHook,
|
||||||
createWorkflow,
|
createWorkflow,
|
||||||
@@ -11,22 +8,13 @@ import {
|
|||||||
WorkflowData,
|
WorkflowData,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { AdditionalData, CartDTO } from "@medusajs/types"
|
|
||||||
import { useQueryGraphStep } from "../../common"
|
import { useQueryGraphStep } from "../../common"
|
||||||
import { useRemoteQueryStep } from "../../common/steps/use-remote-query"
|
import { useRemoteQueryStep } from "../../common/steps/use-remote-query"
|
||||||
import { acquireLockStep, releaseLockStep } from "../../locking"
|
import { acquireLockStep, releaseLockStep } from "../../locking"
|
||||||
import { getVariantPriceSetsStep, updateLineItemsStep } from "../steps"
|
import { updateLineItemsStep } from "../steps"
|
||||||
import { validateVariantPricesStep } from "../steps/validate-variant-prices"
|
import { cartFieldsForRefreshSteps } from "../utils/fields"
|
||||||
import {
|
|
||||||
cartFieldsForPricingContext,
|
|
||||||
cartFieldsForRefreshSteps,
|
|
||||||
productVariantsFields,
|
|
||||||
} from "../utils/fields"
|
|
||||||
import {
|
|
||||||
prepareLineItemData,
|
|
||||||
PrepareLineItemDataInput,
|
|
||||||
} from "../utils/prepare-line-item-data"
|
|
||||||
import { pricingContextResult } from "../utils/schemas"
|
import { pricingContextResult } from "../utils/schemas"
|
||||||
|
import { getVariantsAndItemsWithPrices } from "./get-variants-and-items-with-prices"
|
||||||
import { refreshCartShippingMethodsWorkflow } from "./refresh-cart-shipping-methods"
|
import { refreshCartShippingMethodsWorkflow } from "./refresh-cart-shipping-methods"
|
||||||
import { refreshPaymentCollectionForCartWorkflow } from "./refresh-payment-collection"
|
import { refreshPaymentCollectionForCartWorkflow } from "./refresh-payment-collection"
|
||||||
import { updateCartPromotionsWorkflow } from "./update-cart-promotions"
|
import { updateCartPromotionsWorkflow } from "./update-cart-promotions"
|
||||||
@@ -168,93 +156,11 @@ export const refreshCartItemsWorkflow = createWorkflow(
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const variantIds = transform({ cart }, (data: { cart: CartDTO }) => {
|
const { lineItems } = getVariantsAndItemsWithPrices.runAsStep({
|
||||||
return (data.cart.items ?? []).map((i) => i.variant_id).filter(Boolean)
|
input: {
|
||||||
})
|
cart,
|
||||||
|
setPricingContextResult: setPricingContextResult!,
|
||||||
const cartPricingContext = transform(
|
|
||||||
{ cart, setPricingContextResult },
|
|
||||||
(data): { variantId: string; context: Record<string, unknown> }[] => {
|
|
||||||
const cart = data.cart
|
|
||||||
const baseContext = {
|
|
||||||
...filterObjectByKeys(cart, cartFieldsForPricingContext),
|
|
||||||
...(data.setPricingContextResult
|
|
||||||
? data.setPricingContextResult
|
|
||||||
: {}),
|
|
||||||
currency_code: cart.currency_code,
|
|
||||||
region_id: cart.region_id,
|
|
||||||
region: cart.region,
|
|
||||||
customer_id: cart.customer_id,
|
|
||||||
customer: cart.customer,
|
|
||||||
}
|
|
||||||
|
|
||||||
return cart.items
|
|
||||||
.filter((i) => i.variant_id)
|
|
||||||
.map((item) => {
|
|
||||||
return {
|
|
||||||
variantId: item.variant_id,
|
|
||||||
context: {
|
|
||||||
...baseContext,
|
|
||||||
quantity: item.quantity,
|
|
||||||
},
|
},
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const { data: variantsData } = useQueryGraphStep({
|
|
||||||
entity: "variants",
|
|
||||||
fields: productVariantsFields,
|
|
||||||
filters: {
|
|
||||||
id: variantIds,
|
|
||||||
},
|
|
||||||
}).config({ name: "fetch-variants" })
|
|
||||||
|
|
||||||
const calculatedPriceSets = getVariantPriceSetsStep({
|
|
||||||
data: cartPricingContext,
|
|
||||||
})
|
|
||||||
|
|
||||||
const variants = transform(
|
|
||||||
{ variantsData, calculatedPriceSets },
|
|
||||||
({ variantsData, calculatedPriceSets }) => {
|
|
||||||
return variantsData.map((variant) => {
|
|
||||||
variant.calculated_price = calculatedPriceSets[variant.id]
|
|
||||||
return variant
|
|
||||||
})
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
validateVariantPricesStep({ variants })
|
|
||||||
|
|
||||||
const lineItems = transform({ cart, variants }, ({ cart, variants }) => {
|
|
||||||
const items = cart.items.map((item) => {
|
|
||||||
const variant = (variants ?? []).find(
|
|
||||||
(v) => v.id === item.variant_id
|
|
||||||
)!
|
|
||||||
|
|
||||||
const input: PrepareLineItemDataInput = {
|
|
||||||
item,
|
|
||||||
variant: variant,
|
|
||||||
cartId: cart.id,
|
|
||||||
unitPrice: item.unit_price,
|
|
||||||
isTaxInclusive: item.is_tax_inclusive,
|
|
||||||
}
|
|
||||||
|
|
||||||
if (variant && !item.is_custom_price) {
|
|
||||||
input.unitPrice = variant.calculated_price?.calculated_amount
|
|
||||||
input.isTaxInclusive =
|
|
||||||
variant.calculated_price?.is_calculated_price_tax_inclusive
|
|
||||||
}
|
|
||||||
|
|
||||||
const preparedItem = prepareLineItemData(input)
|
|
||||||
|
|
||||||
return {
|
|
||||||
selector: { id: item.id },
|
|
||||||
data: preparedItem,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return items
|
|
||||||
})
|
})
|
||||||
|
|
||||||
updateLineItemsStep({
|
updateLineItemsStep({
|
||||||
|
|||||||
+4
-1
@@ -1,4 +1,7 @@
|
|||||||
import { BigNumberInput, PaymentSessionDTO } from "@medusajs/framework/types"
|
import type {
|
||||||
|
BigNumberInput,
|
||||||
|
PaymentSessionDTO,
|
||||||
|
} from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
createWorkflow,
|
createWorkflow,
|
||||||
WorkflowData,
|
WorkflowData,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Link } from "@medusajs/framework/modules-sdk"
|
import { Link } from "@medusajs/framework/modules-sdk"
|
||||||
import { LinkDefinition } from "@medusajs/framework/types"
|
import type { LinkDefinition } from "@medusajs/framework/types"
|
||||||
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Link } from "@medusajs/framework/modules-sdk"
|
import { Link } from "@medusajs/framework/modules-sdk"
|
||||||
import { LinkDefinition } from "@medusajs/framework/types"
|
import type { LinkDefinition } from "@medusajs/framework/types"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Link } from "@medusajs/framework/modules-sdk"
|
import { Link } from "@medusajs/framework/modules-sdk"
|
||||||
import { LinkDefinition } from "@medusajs/framework/types"
|
import type { LinkDefinition } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
MedusaError,
|
MedusaError,
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { BatchWorkflowInput, LinkDefinition } from "@medusajs/framework/types"
|
import type {
|
||||||
|
BatchWorkflowInput,
|
||||||
|
LinkDefinition,
|
||||||
|
} from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
WorkflowData,
|
WorkflowData,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { LinkDefinition } from "@medusajs/framework/types"
|
import type { LinkDefinition } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
WorkflowData,
|
WorkflowData,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { LinkDefinition } from "@medusajs/framework/types"
|
import type { LinkDefinition } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
WorkflowData,
|
WorkflowData,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { LinkDefinition } from "@medusajs/framework/types"
|
import type { LinkDefinition } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
WorkflowData,
|
WorkflowData,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ICustomerModuleService } from "@medusajs/framework/types"
|
import type { ICustomerModuleService } from "@medusajs/framework/types"
|
||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -1,4 +1,4 @@
|
|||||||
import { LinkWorkflowInput } from "@medusajs/framework/types"
|
import type { LinkWorkflowInput } from "@medusajs/framework/types"
|
||||||
import { WorkflowData, createWorkflow } from "@medusajs/framework/workflows-sdk"
|
import { WorkflowData, createWorkflow } from "@medusajs/framework/workflows-sdk"
|
||||||
import { linkCustomerGroupsToCustomerStep } from "../steps"
|
import { linkCustomerGroupsToCustomerStep } from "../steps"
|
||||||
|
|
||||||
@@ -36,7 +36,9 @@ export const linkCustomerGroupsToCustomerWorkflowId =
|
|||||||
*/
|
*/
|
||||||
export const linkCustomerGroupsToCustomerWorkflow = createWorkflow(
|
export const linkCustomerGroupsToCustomerWorkflow = createWorkflow(
|
||||||
linkCustomerGroupsToCustomerWorkflowId,
|
linkCustomerGroupsToCustomerWorkflowId,
|
||||||
(input: WorkflowData<LinkCustomerGroupsToCustomerWorkflowInput>): WorkflowData<void> => {
|
(
|
||||||
|
input: WorkflowData<LinkCustomerGroupsToCustomerWorkflowInput>
|
||||||
|
): WorkflowData<void> => {
|
||||||
return linkCustomerGroupsToCustomerStep(input)
|
return linkCustomerGroupsToCustomerStep(input)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
+4
-2
@@ -1,4 +1,4 @@
|
|||||||
import { LinkWorkflowInput } from "@medusajs/framework/types"
|
import type { LinkWorkflowInput } from "@medusajs/framework/types"
|
||||||
import { WorkflowData, createWorkflow } from "@medusajs/framework/workflows-sdk"
|
import { WorkflowData, createWorkflow } from "@medusajs/framework/workflows-sdk"
|
||||||
import { linkCustomersToCustomerGroupStep } from "../steps"
|
import { linkCustomersToCustomerGroupStep } from "../steps"
|
||||||
|
|
||||||
@@ -36,7 +36,9 @@ export const linkCustomersToCustomerGroupWorkflowId =
|
|||||||
*/
|
*/
|
||||||
export const linkCustomersToCustomerGroupWorkflow = createWorkflow(
|
export const linkCustomersToCustomerGroupWorkflow = createWorkflow(
|
||||||
linkCustomersToCustomerGroupWorkflowId,
|
linkCustomersToCustomerGroupWorkflowId,
|
||||||
(input: WorkflowData<LinkCustomersToCustomerGroupWorkflow>): WorkflowData<void> => {
|
(
|
||||||
|
input: WorkflowData<LinkCustomersToCustomerGroupWorkflow>
|
||||||
|
): WorkflowData<void> => {
|
||||||
return linkCustomersToCustomerGroupStep(input)
|
return linkCustomersToCustomerGroupStep(input)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ICustomerModuleService } from "@medusajs/framework/types"
|
import type { ICustomerModuleService } from "@medusajs/framework/types"
|
||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ICustomerModuleService } from "@medusajs/framework/types"
|
import type { ICustomerModuleService } from "@medusajs/framework/types"
|
||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { CreateCustomerDTO, CustomerDTO } from "@medusajs/framework/types"
|
import type { CreateCustomerDTO, CustomerDTO } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
createWorkflow,
|
createWorkflow,
|
||||||
transform,
|
transform,
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { AdditionalData, CreateCustomerDTO } from "@medusajs/framework/types"
|
import type {
|
||||||
|
AdditionalData,
|
||||||
|
CreateCustomerDTO,
|
||||||
|
} from "@medusajs/framework/types"
|
||||||
import { CustomerWorkflowEvents } from "@medusajs/framework/utils"
|
import { CustomerWorkflowEvents } from "@medusajs/framework/utils"
|
||||||
import {
|
import {
|
||||||
WorkflowData,
|
WorkflowData,
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
|||||||
import {
|
import {
|
||||||
CreateLineItemAdjustmentDTO,
|
CreateLineItemAdjustmentDTO,
|
||||||
IOrderModuleService,
|
IOrderModuleService,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/framework/types"
|
||||||
|
|
||||||
export const createDraftOrderLineItemAdjustmentsStepId =
|
export const createDraftOrderLineItemAdjustmentsStepId =
|
||||||
"create-draft-order-line-item-adjustments"
|
"create-draft-order-line-item-adjustments"
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
|||||||
import {
|
import {
|
||||||
CreateShippingMethodAdjustmentDTO,
|
CreateShippingMethodAdjustmentDTO,
|
||||||
IOrderModuleService,
|
IOrderModuleService,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/framework/types"
|
||||||
|
|
||||||
export const createDraftOrderShippingMethodAdjustmentsStepId =
|
export const createDraftOrderShippingMethodAdjustmentsStepId =
|
||||||
"create-draft-order-shipping-method-adjustments"
|
"create-draft-order-shipping-method-adjustments"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { IOrderModuleService } from "@medusajs/framework/types"
|
import type { IOrderModuleService } from "@medusajs/framework/types"
|
||||||
import { createStep } from "@medusajs/framework/workflows-sdk"
|
import { createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
import { IOrderModuleService, OrderDTO } from "@medusajs/types"
|
import type { IOrderModuleService, OrderDTO } from "@medusajs/framework/types"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The details of the draft order to get the promotion context for.
|
* The details of the draft order to get the promotion context for.
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
import { IOrderModuleService } from "@medusajs/types"
|
import type { IOrderModuleService } from "@medusajs/framework/types"
|
||||||
export const removeDraftOrderLineItemAdjustmentsStepId =
|
export const removeDraftOrderLineItemAdjustmentsStepId =
|
||||||
"remove-draft-order-line-item-adjustments"
|
"remove-draft-order-line-item-adjustments"
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
import { IOrderModuleService } from "@medusajs/types"
|
import type { IOrderModuleService } from "@medusajs/framework/types"
|
||||||
|
|
||||||
export const removeDraftOrderShippingMethodAdjustmentsStepId =
|
export const removeDraftOrderShippingMethodAdjustmentsStepId =
|
||||||
"remove-draft-order-shipping-method-adjustments"
|
"remove-draft-order-shipping-method-adjustments"
|
||||||
|
|||||||
+4
-1
@@ -1,6 +1,9 @@
|
|||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
import { BigNumberInput, IOrderModuleService } from "@medusajs/types"
|
import type {
|
||||||
|
BigNumberInput,
|
||||||
|
IOrderModuleService,
|
||||||
|
} from "@medusajs/framework/types"
|
||||||
|
|
||||||
export const restoreDraftOrderShippingMethodsStepId =
|
export const restoreDraftOrderShippingMethodsStepId =
|
||||||
"restore-draft-order-shipping-methods"
|
"restore-draft-order-shipping-methods"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
PromotionActions,
|
PromotionActions,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
import { IPromotionModuleService } from "@medusajs/types"
|
import type { IPromotionModuleService } from "@medusajs/framework/types"
|
||||||
|
|
||||||
export const updateDraftOrderPromotionsStepId = "update-draft-order-promotions"
|
export const updateDraftOrderPromotionsStepId = "update-draft-order-promotions"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { MedusaError, Modules } from "@medusajs/framework/utils"
|
import { MedusaError, Modules } from "@medusajs/framework/utils"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
import { BigNumberInput, IOrderModuleService } from "@medusajs/types"
|
import type {
|
||||||
|
BigNumberInput,
|
||||||
|
IOrderModuleService,
|
||||||
|
} from "@medusajs/framework/types"
|
||||||
|
|
||||||
export const updateDraftOrderShippingMethodStepId =
|
export const updateDraftOrderShippingMethodStepId =
|
||||||
"update-draft-order-shipping-method"
|
"update-draft-order-shipping-method"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createStep } from "@medusajs/framework/workflows-sdk"
|
import { createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
import { OrderChangeDTO, OrderDTO } from "@medusajs/types"
|
import type { OrderChangeDTO, OrderDTO } from "@medusajs/framework/types"
|
||||||
import { throwIfOrderChangeIsNotActive } from "../../order/utils/order-validation"
|
import { throwIfOrderChangeIsNotActive } from "../../order/utils/order-validation"
|
||||||
import { throwIfNotDraftOrder } from "../utils/validation"
|
import { throwIfNotDraftOrder } from "../utils/validation"
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
import { OrderChangeActionDTO } from "@medusajs/types"
|
import type { OrderChangeActionDTO } from "@medusajs/framework/types"
|
||||||
|
|
||||||
import { ChangeActionType, MedusaError } from "@medusajs/framework/utils"
|
import { ChangeActionType, MedusaError } from "@medusajs/framework/utils"
|
||||||
import { createStep } from "@medusajs/framework/workflows-sdk"
|
import { createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
import { OrderChangeDTO, OrderWorkflow } from "@medusajs/types"
|
import type { OrderChangeDTO, OrderWorkflow } from "@medusajs/framework/types"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The details of the draft order and its change to validate.
|
* The details of the draft order and its change to validate.
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ import {
|
|||||||
OrderChangeActionDTO,
|
OrderChangeActionDTO,
|
||||||
OrderChangeDTO,
|
OrderChangeDTO,
|
||||||
OrderWorkflow,
|
OrderWorkflow,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/framework/types"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The details of the draft order and its change to validate.
|
* The details of the draft order and its change to validate.
|
||||||
|
|||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
import { OrderChangeActionDTO } from "@medusajs/types"
|
import type { OrderChangeActionDTO } from "@medusajs/framework/types"
|
||||||
|
|
||||||
import { ChangeActionType, MedusaError } from "@medusajs/framework/utils"
|
import { ChangeActionType, MedusaError } from "@medusajs/framework/utils"
|
||||||
import { createStep } from "@medusajs/framework/workflows-sdk"
|
import { createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
import { OrderChangeDTO, OrderWorkflow } from "@medusajs/types"
|
import type { OrderChangeDTO, OrderWorkflow } from "@medusajs/framework/types"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The details of the draft order and its change to validate.
|
* The details of the draft order and its change to validate.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { MedusaError, OrderStatus } from "@medusajs/framework/utils"
|
import { MedusaError, OrderStatus } from "@medusajs/framework/utils"
|
||||||
import { createStep } from "@medusajs/framework/workflows-sdk"
|
import { createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
import { OrderDTO } from "@medusajs/types"
|
import type { OrderDTO } from "@medusajs/framework/types"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The details of the draft order to validate.
|
* The details of the draft order to validate.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createStep } from "@medusajs/framework/workflows-sdk"
|
import { createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
import { PromotionDTO } from "@medusajs/types"
|
import type { PromotionDTO } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
throwIfCodesAreInactive,
|
throwIfCodesAreInactive,
|
||||||
throwIfCodesAreMissing,
|
throwIfCodesAreMissing,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createStep } from "@medusajs/framework/workflows-sdk"
|
import { createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
import { PromotionDTO } from "@medusajs/types"
|
import type { PromotionDTO } from "@medusajs/framework/types"
|
||||||
import { throwIfCodesAreMissing } from "../utils/validation"
|
import { throwIfCodesAreMissing } from "../utils/validation"
|
||||||
|
|
||||||
export const validatePromoCodesToRemoveId = "validate-promo-codes-to-remove"
|
export const validatePromoCodesToRemoveId = "validate-promo-codes-to-remove"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
OrderStatus,
|
OrderStatus,
|
||||||
PromotionStatus,
|
PromotionStatus,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
import { OrderDTO, PromotionDTO } from "@medusajs/types"
|
import type { OrderDTO, PromotionDTO } from "@medusajs/framework/types"
|
||||||
|
|
||||||
interface ThrowIfNotDraftOrderInput {
|
interface ThrowIfNotDraftOrderInput {
|
||||||
order: OrderDTO
|
order: OrderDTO
|
||||||
|
|||||||
@@ -10,7 +10,11 @@ import {
|
|||||||
WorkflowData,
|
WorkflowData,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { OrderChangeDTO, OrderDTO, OrderWorkflow } from "@medusajs/types"
|
import {
|
||||||
|
OrderChangeDTO,
|
||||||
|
OrderDTO,
|
||||||
|
OrderWorkflow,
|
||||||
|
} from "@medusajs/framework/types"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useRemoteQueryStep } from "../../common"
|
||||||
import {
|
import {
|
||||||
addOrderLineItemsWorkflow,
|
addOrderLineItemsWorkflow,
|
||||||
|
|||||||
@@ -9,7 +9,11 @@ import {
|
|||||||
WorkflowData,
|
WorkflowData,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { OrderChangeDTO, OrderDTO, PromotionDTO } from "@medusajs/types"
|
import {
|
||||||
|
OrderChangeDTO,
|
||||||
|
OrderDTO,
|
||||||
|
PromotionDTO,
|
||||||
|
} from "@medusajs/framework/types"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useRemoteQueryStep } from "../../common"
|
||||||
import {
|
import {
|
||||||
createOrderChangeActionsWorkflow,
|
createOrderChangeActionsWorkflow,
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ import {
|
|||||||
OrderChangeDTO,
|
OrderChangeDTO,
|
||||||
OrderDTO,
|
OrderDTO,
|
||||||
ShippingOptionDTO,
|
ShippingOptionDTO,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/framework/types"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useRemoteQueryStep } from "../../common"
|
||||||
import {
|
import {
|
||||||
createOrderChangeActionsWorkflow,
|
createOrderChangeActionsWorkflow,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
WorkflowData,
|
WorkflowData,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { OrderDTO, OrderWorkflow } from "@medusajs/types"
|
import type { OrderDTO, OrderWorkflow } from "@medusajs/framework/types"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useRemoteQueryStep } from "../../common"
|
||||||
import { createOrderChangeStep, previewOrderChangeStep } from "../../order"
|
import { createOrderChangeStep, previewOrderChangeStep } from "../../order"
|
||||||
import { validateDraftOrderStep } from "../steps"
|
import { validateDraftOrderStep } from "../steps"
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
when,
|
when,
|
||||||
WorkflowData,
|
WorkflowData,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { OrderChangeDTO, OrderDTO } from "@medusajs/types"
|
import type { OrderChangeDTO, OrderDTO } from "@medusajs/framework/types"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useRemoteQueryStep } from "../../common"
|
||||||
import { deleteOrderChangesStep, deleteOrderShippingMethods } from "../../order"
|
import { deleteOrderChangesStep, deleteOrderShippingMethods } from "../../order"
|
||||||
import { restoreDraftOrderShippingMethodsStep } from "../steps/restore-draft-order-shipping-methods"
|
import { restoreDraftOrderShippingMethodsStep } from "../steps/restore-draft-order-shipping-methods"
|
||||||
|
|||||||
@@ -8,7 +8,11 @@ import {
|
|||||||
transform,
|
transform,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { BigNumberInput, OrderChangeDTO, OrderDTO } from "@medusajs/types"
|
import {
|
||||||
|
BigNumberInput,
|
||||||
|
OrderChangeDTO,
|
||||||
|
OrderDTO,
|
||||||
|
} from "@medusajs/framework/types"
|
||||||
import { reserveInventoryStep } from "../../cart"
|
import { reserveInventoryStep } from "../../cart"
|
||||||
import {
|
import {
|
||||||
prepareConfirmInventoryInput,
|
prepareConfirmInventoryInput,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
WorkflowData,
|
WorkflowData,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { IOrderModuleService, OrderDTO } from "@medusajs/types"
|
import type { IOrderModuleService, OrderDTO } from "@medusajs/framework/types"
|
||||||
import { emitEventStep, useRemoteQueryStep } from "../../common"
|
import { emitEventStep, useRemoteQueryStep } from "../../common"
|
||||||
import { validateDraftOrderStep } from "../steps/validate-draft-order"
|
import { validateDraftOrderStep } from "../steps/validate-draft-order"
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
createWorkflow,
|
createWorkflow,
|
||||||
transform,
|
transform,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { OrderDTO } from "@medusajs/framework/types"
|
import type { OrderDTO } from "@medusajs/framework/types"
|
||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
|
|
||||||
import { removeRemoteLinkStep, useQueryGraphStep } from "../../common"
|
import { removeRemoteLinkStep, useQueryGraphStep } from "../../common"
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
WorkflowData,
|
WorkflowData,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { OrderDTO } from "@medusajs/types"
|
import type { OrderDTO } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
getActionsToComputeFromPromotionsStep,
|
getActionsToComputeFromPromotionsStep,
|
||||||
getPromotionCodesToApply,
|
getPromotionCodesToApply,
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ import {
|
|||||||
OrderDTO,
|
OrderDTO,
|
||||||
OrderPreviewDTO,
|
OrderPreviewDTO,
|
||||||
OrderWorkflow,
|
OrderWorkflow,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/framework/types"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useRemoteQueryStep } from "../../common"
|
||||||
import {
|
import {
|
||||||
deleteOrderChangeActionsStep,
|
deleteOrderChangeActionsStep,
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@ import {
|
|||||||
OrderDTO,
|
OrderDTO,
|
||||||
OrderPreviewDTO,
|
OrderPreviewDTO,
|
||||||
OrderWorkflow,
|
OrderWorkflow,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/framework/types"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useRemoteQueryStep } from "../../common"
|
||||||
import {
|
import {
|
||||||
deleteOrderChangeActionsStep,
|
deleteOrderChangeActionsStep,
|
||||||
|
|||||||
@@ -9,7 +9,11 @@ import {
|
|||||||
WorkflowData,
|
WorkflowData,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { OrderChangeDTO, OrderDTO, PromotionDTO } from "@medusajs/types"
|
import {
|
||||||
|
OrderChangeDTO,
|
||||||
|
OrderDTO,
|
||||||
|
PromotionDTO,
|
||||||
|
} from "@medusajs/framework/types"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useRemoteQueryStep } from "../../common"
|
||||||
import {
|
import {
|
||||||
createOrderChangeActionsWorkflow,
|
createOrderChangeActionsWorkflow,
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ import {
|
|||||||
WorkflowData,
|
WorkflowData,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { OrderChangeDTO, OrderDTO } from "@medusajs/types"
|
import type { OrderChangeDTO, OrderDTO } from "@medusajs/framework/types"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useRemoteQueryStep } from "../../common"
|
||||||
import {
|
import {
|
||||||
createOrderChangeActionsWorkflow,
|
createOrderChangeActionsWorkflow,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
transform,
|
transform,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { OrderChangeDTO, OrderDTO } from "@medusajs/types"
|
import type { OrderChangeDTO, OrderDTO } from "@medusajs/framework/types"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useRemoteQueryStep } from "../../common"
|
||||||
import {
|
import {
|
||||||
createOrUpdateOrderPaymentCollectionWorkflow,
|
createOrUpdateOrderPaymentCollectionWorkflow,
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ import {
|
|||||||
OrderChangeDTO,
|
OrderChangeDTO,
|
||||||
OrderDTO,
|
OrderDTO,
|
||||||
OrderWorkflow,
|
OrderWorkflow,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/framework/types"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useRemoteQueryStep } from "../../common"
|
||||||
import {
|
import {
|
||||||
previewOrderChangeStep,
|
previewOrderChangeStep,
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@ import {
|
|||||||
OrderDTO,
|
OrderDTO,
|
||||||
OrderPreviewDTO,
|
OrderPreviewDTO,
|
||||||
OrderWorkflow,
|
OrderWorkflow,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/framework/types"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useRemoteQueryStep } from "../../common"
|
||||||
import {
|
import {
|
||||||
previewOrderChangeStep,
|
previewOrderChangeStep,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
OrderDTO,
|
OrderDTO,
|
||||||
OrderPreviewDTO,
|
OrderPreviewDTO,
|
||||||
OrderWorkflow,
|
OrderWorkflow,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/framework/types"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useRemoteQueryStep } from "../../common"
|
||||||
import {
|
import {
|
||||||
createOrderChangeActionsWorkflow,
|
createOrderChangeActionsWorkflow,
|
||||||
|
|||||||
+5
-1
@@ -10,7 +10,11 @@ import {
|
|||||||
WorkflowData,
|
WorkflowData,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
} from "@medusajs/framework/workflows-sdk"
|
} from "@medusajs/framework/workflows-sdk"
|
||||||
import { BigNumberInput, OrderChangeDTO, OrderDTO } from "@medusajs/types"
|
import {
|
||||||
|
BigNumberInput,
|
||||||
|
OrderChangeDTO,
|
||||||
|
OrderDTO,
|
||||||
|
} from "@medusajs/framework/types"
|
||||||
import { useRemoteQueryStep } from "../../common"
|
import { useRemoteQueryStep } from "../../common"
|
||||||
import {
|
import {
|
||||||
createOrderChangeActionsWorkflow,
|
createOrderChangeActionsWorkflow,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
RegisterOrderChangeDTO,
|
RegisterOrderChangeDTO,
|
||||||
UpdateOrderDTO,
|
UpdateOrderDTO,
|
||||||
UpsertOrderAddressDTO,
|
UpsertOrderAddressDTO,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/framework/types"
|
||||||
import { emitEventStep, useRemoteQueryStep } from "../../common"
|
import { emitEventStep, useRemoteQueryStep } from "../../common"
|
||||||
import { previewOrderChangeStep, registerOrderChangesStep } from "../../order"
|
import { previewOrderChangeStep, registerOrderChangesStep } from "../../order"
|
||||||
import { validateDraftOrderStep } from "../steps/validate-draft-order"
|
import { validateDraftOrderStep } from "../steps/validate-draft-order"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { IFileModuleService } from "@medusajs/framework/types"
|
import type { IFileModuleService } from "@medusajs/framework/types"
|
||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { IFileModuleService } from "@medusajs/framework/types"
|
import type { IFileModuleService } from "@medusajs/framework/types"
|
||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { FileDTO } from "@medusajs/framework/types"
|
import type { FileDTO } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
WorkflowData,
|
WorkflowData,
|
||||||
WorkflowResponse,
|
WorkflowResponse,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { IFulfillmentModuleService } from "@medusajs/framework/types"
|
import type { IFulfillmentModuleService } from "@medusajs/framework/types"
|
||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { IFulfillmentModuleService } from "@medusajs/framework/types"
|
import type { IFulfillmentModuleService } from "@medusajs/framework/types"
|
||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { IFulfillmentModuleService } from "@medusajs/framework/types"
|
import type { IFulfillmentModuleService } from "@medusajs/framework/types"
|
||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { DeleteEntityInput } from "@medusajs/framework/modules-sdk"
|
import { DeleteEntityInput } from "@medusajs/framework/modules-sdk"
|
||||||
import { IFulfillmentModuleService } from "@medusajs/framework/types"
|
import type { IFulfillmentModuleService } from "@medusajs/framework/types"
|
||||||
import { Modules } from "@medusajs/framework/utils"
|
import { Modules } from "@medusajs/framework/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Link } from "@medusajs/framework/modules-sdk"
|
import { Link } from "@medusajs/framework/modules-sdk"
|
||||||
import { RemoteQueryFunction } from "@medusajs/framework/types"
|
import type { RemoteQueryFunction } from "@medusajs/framework/types"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
import {
|
import {
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import { ServiceZoneDTO, ShippingOptionDTO } from "@medusajs/framework/types"
|
import type {
|
||||||
|
ServiceZoneDTO,
|
||||||
|
ShippingOptionDTO,
|
||||||
|
} from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
ContainerRegistrationKeys,
|
ContainerRegistrationKeys,
|
||||||
MedusaError,
|
MedusaError,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { IFulfillmentModuleService } from "@medusajs/framework/types"
|
import type { IFulfillmentModuleService } from "@medusajs/framework/types"
|
||||||
import { MedusaError, Modules } from "@medusajs/framework/utils"
|
import { MedusaError, Modules } from "@medusajs/framework/utils"
|
||||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
import { FulfillmentWorkflow } from "@medusajs/framework/types"
|
import type { FulfillmentWorkflow } from "@medusajs/framework/types"
|
||||||
import { MedusaError, Modules, ShippingOptionPriceType, } from "@medusajs/framework/utils"
|
import {
|
||||||
|
MedusaError,
|
||||||
|
Modules,
|
||||||
|
ShippingOptionPriceType,
|
||||||
|
} from "@medusajs/framework/utils"
|
||||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||||
import { CreateShippingOptionDTO } from "@medusajs/types"
|
import type { CreateShippingOptionDTO } from "@medusajs/framework/types"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The data to validate shipping option prices.
|
* The data to validate shipping option prices.
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import { FulfillmentWorkflow } from "@medusajs/framework/types"
|
import type { FulfillmentWorkflow } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
createWorkflow,
|
createWorkflow,
|
||||||
transform,
|
transform,
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user