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:
1 parent
3960c80e9f
commit
5ea32aaa44
281 files changed
+1196
-798
No files matched your search
@@ -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", () => {
|
||||
let priceList
|
||||
|
||||
|
||||
@@ -1881,7 +1881,7 @@ medusaIntegrationTestRunner({
|
||||
|
||||
expect(errors).toEqual([
|
||||
{
|
||||
action: "get-variant-price-sets",
|
||||
action: "get-variant-items-with-prices-workflow-as-step",
|
||||
handlerType: "invoke",
|
||||
error: expect.objectContaining({
|
||||
message: expect.stringContaining(
|
||||
@@ -4307,18 +4307,20 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
}
|
||||
|
||||
const { result: result1 } = await listShippingOptionsForCartWorkflow(
|
||||
appContainer
|
||||
).run({ input: { cart_id: cart.id } })
|
||||
const { result: result1 } =
|
||||
await listShippingOptionsForCartWorkflow(appContainer).run({
|
||||
input: { cart_id: cart.id },
|
||||
})
|
||||
|
||||
expect(result1).toHaveLength(1)
|
||||
expect(result1[0].name).toEqual(shippingOption.name)
|
||||
|
||||
setShippingOptionsContextHook = undefined
|
||||
|
||||
const { result: result2 } = await listShippingOptionsForCartWorkflow(
|
||||
appContainer
|
||||
).run({ input: { cart_id: cart.id } })
|
||||
const { result: result2 } =
|
||||
await listShippingOptionsForCartWorkflow(appContainer).run({
|
||||
input: { cart_id: cart.id },
|
||||
})
|
||||
|
||||
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 { 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 {
|
||||
ContainerRegistrationKeys,
|
||||
Modules,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ISalesChannelModuleService } from "@medusajs/framework/types"
|
||||
import type { ISalesChannelModuleService } from "@medusajs/framework/types"
|
||||
import {
|
||||
MedusaError,
|
||||
Modules,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ApiKeyDTO, CreateApiKeyDTO } from "@medusajs/framework/types"
|
||||
import type { ApiKeyDTO, CreateApiKeyDTO } from "@medusajs/framework/types"
|
||||
import {
|
||||
WorkflowData,
|
||||
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 {
|
||||
linkSalesChannelsToApiKeyStep,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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"
|
||||
|
||||
export type SetAuthAppMetadataStepInput = {
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Logger } from "@medusajs/framework/types"
|
||||
import type { Logger } from "@medusajs/framework/types"
|
||||
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||
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 {
|
||||
MathBN,
|
||||
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 { 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 { 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 { 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 {
|
||||
MedusaError,
|
||||
Modules,
|
||||
@@ -79,7 +79,7 @@ export const getPromotionCodesToApply = createStep(
|
||||
const adjustmentCodes: string[] = []
|
||||
items.concat(shipping_methods).forEach((object) => {
|
||||
object.adjustments?.forEach((adjustment) => {
|
||||
if (adjustment.code && !adjustmentCodes.includes(adjustment.code)) {
|
||||
if (adjustment.code) {
|
||||
adjustmentCodes.push(adjustment.code)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -34,6 +34,10 @@ export interface GetVariantPriceSetsStepBulkInput {
|
||||
* The variants to get price sets for.
|
||||
*/
|
||||
data: {
|
||||
/**
|
||||
* The ID of the item.
|
||||
*/
|
||||
id?: string
|
||||
/**
|
||||
* The ID of the variant to get the price set for.
|
||||
*/
|
||||
@@ -51,6 +55,10 @@ interface VariantPriceSetData {
|
||||
}
|
||||
|
||||
interface PriceCalculationItem {
|
||||
/**
|
||||
* The ID of the item. In case of variants we wont have an item id
|
||||
*/
|
||||
id?: string
|
||||
variantId: string
|
||||
priceSetId: string
|
||||
context?: Record<string, unknown>
|
||||
@@ -124,7 +132,7 @@ async function processVariantPriceSets(
|
||||
for (const item of groupItems) {
|
||||
const calculatedPriceSet = priceSetMap.get(item.priceSetId)
|
||||
if (calculatedPriceSet) {
|
||||
result[item.variantId] = calculatedPriceSet
|
||||
result[item.id ?? item.variantId] = calculatedPriceSet
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,6 +204,7 @@ function createCalculationItemsFromBulkData(
|
||||
const priceSetId = variantToPriceSetId.get(item.variantId)
|
||||
if (priceSetId) {
|
||||
calculationItems.push({
|
||||
id: item.id,
|
||||
variantId: item.variantId,
|
||||
priceSetId,
|
||||
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 { 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 { 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 { 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
|
||||
* that were removed.
|
||||
*/
|
||||
export type RemoveShippingMethodFromCartStepOutput = Record<string, string[]> | void
|
||||
export type RemoveShippingMethodFromCartStepOutput = Record<
|
||||
string,
|
||||
string[]
|
||||
> | void
|
||||
|
||||
export const removeShippingMethodFromCartStepId =
|
||||
"remove-shipping-method-to-cart-step"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { MathBN, Modules } from "@medusajs/framework/utils"
|
||||
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.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IPromotionModuleService } from "@medusajs/framework/types"
|
||||
import type { IPromotionModuleService } from "@medusajs/framework/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
Modules,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CartWorkflowDTO } from "@medusajs/framework/types"
|
||||
import type { CartWorkflowDTO } from "@medusajs/framework/types"
|
||||
import {
|
||||
isPresent,
|
||||
MathBN,
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
import { CartDTO, IFulfillmentModuleService } from "@medusajs/framework/types"
|
||||
import { arrayDifference, MedusaError, Modules, } from "@medusajs/framework/utils"
|
||||
import type {
|
||||
CartDTO,
|
||||
IFulfillmentModuleService,
|
||||
} from "@medusajs/framework/types"
|
||||
import {
|
||||
arrayDifference,
|
||||
MedusaError,
|
||||
Modules,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
@@ -52,7 +59,12 @@ export const validateCartShippingOptionsStepId =
|
||||
export const validateCartShippingOptionsStep = createStep(
|
||||
validateCartShippingOptionsStepId,
|
||||
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) {
|
||||
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 { createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { MedusaError } from "@medusajs/framework/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
import { SalesChannelDTO } from "@medusajs/types"
|
||||
import type { SalesChannelDTO } from "@medusajs/framework/types"
|
||||
|
||||
export const validateSalesChannelStep = createStep(
|
||||
"validate-sales-channel",
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Modules, promiseAll } from "@medusajs/framework/utils"
|
||||
import {
|
||||
IFulfillmentModuleService,
|
||||
ValidateFulfillmentDataContext,
|
||||
} from "@medusajs/types"
|
||||
} from "@medusajs/framework/types"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
/**
|
||||
@@ -36,8 +36,10 @@ export type ValidateShippingMethodsDataInput = {
|
||||
/**
|
||||
* The validated data of the shipping methods.
|
||||
*/
|
||||
export type ValidateShippingMethodsDataOutput = void | {
|
||||
[x: string]: Record<string, unknown>;
|
||||
export type ValidateShippingMethodsDataOutput =
|
||||
| void
|
||||
| {
|
||||
[x: string]: Record<string, unknown>
|
||||
}[]
|
||||
|
||||
export const validateAndReturnShippingMethodsDataStepId =
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
CartWorkflowDTO,
|
||||
ProductVariantDTO,
|
||||
ShippingOptionDTO,
|
||||
} from "@medusajs/types"
|
||||
} from "@medusajs/framework/types"
|
||||
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 { 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 { prepareConfirmInventoryInput } from "../prepare-confirm-inventory-input"
|
||||
|
||||
|
||||
@@ -2,12 +2,11 @@ import {
|
||||
AdditionalData,
|
||||
AddToCartWorkflowInputDTO,
|
||||
ConfirmVariantInventoryWorkflowInputDTO,
|
||||
WithCalculatedPrice,
|
||||
CreateLineItemForCartDTO,
|
||||
} from "@medusajs/framework/types"
|
||||
import {
|
||||
CartWorkflowEvents,
|
||||
deduplicate,
|
||||
filterObjectByKeys,
|
||||
isDefined,
|
||||
} from "@medusajs/framework/utils"
|
||||
import {
|
||||
@@ -16,7 +15,6 @@ import {
|
||||
parallelize,
|
||||
transform,
|
||||
when,
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { useQueryGraphStep } from "../../common"
|
||||
@@ -25,12 +23,10 @@ import { acquireLockStep, releaseLockStep } from "../../locking"
|
||||
import {
|
||||
createLineItemsStep,
|
||||
getLineItemActionsStep,
|
||||
getVariantPriceSetsStep,
|
||||
updateLineItemsStep,
|
||||
} from "../steps"
|
||||
import { validateCartStep } from "../steps/validate-cart"
|
||||
import { validateLineItemPricesStep } from "../steps/validate-line-item-prices"
|
||||
import { validateVariantPricesStep } from "../steps/validate-variant-prices"
|
||||
import {
|
||||
cartFieldsForPricingContext,
|
||||
productVariantsFields,
|
||||
@@ -43,6 +39,7 @@ import {
|
||||
} from "../utils/prepare-line-item-data"
|
||||
import { pricingContextResult } from "../utils/schemas"
|
||||
import { confirmVariantInventoryWorkflow } from "./confirm-variant-inventory"
|
||||
import { getVariantsAndItemsWithPrices } from "./get-variants-and-items-with-prices"
|
||||
import { refreshCartItemsWorkflow } from "./refresh-cart-items"
|
||||
|
||||
const cartFields = ["completed_at"].concat(cartFieldsForPricingContext)
|
||||
@@ -119,32 +116,30 @@ export const addToCartWorkflow = createWorkflow(
|
||||
name: addToCartWorkflowId,
|
||||
idempotent: false,
|
||||
},
|
||||
(input: WorkflowData<AddToCartWorkflowInputDTO & AdditionalData>) => {
|
||||
(input: AddToCartWorkflowInputDTO & AdditionalData) => {
|
||||
acquireLockStep({
|
||||
key: input.cart_id,
|
||||
timeout: 2,
|
||||
ttl: 10,
|
||||
})
|
||||
|
||||
const cartQuery = useQueryGraphStep({
|
||||
const { data: cart } = useQueryGraphStep({
|
||||
entity: "cart",
|
||||
filters: { id: input.cart_id },
|
||||
fields: cartFields,
|
||||
options: { throwIfKeyNotFound: true },
|
||||
options: { throwIfKeyNotFound: true, isList: false },
|
||||
}).config({ name: "get-cart" })
|
||||
|
||||
const cart = transform({ cartQuery }, ({ cartQuery }) => {
|
||||
return cartQuery.data[0]
|
||||
})
|
||||
|
||||
validateCartStep({ cart })
|
||||
const validate = createHook("validate", {
|
||||
input,
|
||||
cart,
|
||||
})
|
||||
|
||||
const variantIds = transform({ input }, (data) => {
|
||||
return (data.input.items ?? []).map((i) => i.variant_id).filter(Boolean)
|
||||
const variantIds = transform({ input }, (data): string[] => {
|
||||
return (data.input.items ?? [])
|
||||
.map((i) => i.variant_id)
|
||||
.filter((v): v is string => !!v)
|
||||
})
|
||||
|
||||
const setPricingContext = createHook(
|
||||
@@ -162,43 +157,46 @@ export const addToCartWorkflow = createWorkflow(
|
||||
|
||||
const setPricingContextResult = setPricingContext.getResult()
|
||||
|
||||
const variants = when(
|
||||
const { variants: variantsData, lineItems: lineItemsData } = when(
|
||||
"should-calculate-prices",
|
||||
{ variantIds },
|
||||
({ variantIds }) => {
|
||||
return !!variantIds.length
|
||||
}
|
||||
).then(() => {
|
||||
const pricingContext = transform(
|
||||
{ cart, items: input.items, setPricingContextResult },
|
||||
(data): { variantId: string; context: Record<string, unknown> }[] => {
|
||||
const baseContext = {
|
||||
...filterObjectByKeys(data.cart, cartFieldsForPricingContext),
|
||||
...(data.setPricingContextResult
|
||||
? data.setPricingContextResult
|
||||
: {}),
|
||||
currency_code: data.cart.currency_code,
|
||||
region_id: data.cart.region_id,
|
||||
region: data.cart.region,
|
||||
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 { variants: variantsData, lineItems: items } =
|
||||
getVariantsAndItemsWithPrices.runAsStep({
|
||||
input: {
|
||||
cart,
|
||||
items: input.items,
|
||||
setPricingContextResult: setPricingContextResult!,
|
||||
variants: {
|
||||
id: variantIds,
|
||||
fields: deduplicate([
|
||||
...productVariantsFields,
|
||||
...requiredVariantFieldsForInventoryConfirmation,
|
||||
]),
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
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",
|
||||
fields: deduplicate([
|
||||
...productVariantsFields,
|
||||
@@ -207,39 +205,33 @@ export const addToCartWorkflow = createWorkflow(
|
||||
filters: {
|
||||
id: variantIds,
|
||||
},
|
||||
})
|
||||
|
||||
const calculatedPriceSets = getVariantPriceSetsStep({
|
||||
data: pricingContext,
|
||||
}).config({ name: "fetch-variants" })
|
||||
})
|
||||
|
||||
const variants = transform(
|
||||
{ variantsData, calculatedPriceSets },
|
||||
({ variantsData, calculatedPriceSets }) => {
|
||||
return variantsData.map((variant) => {
|
||||
variant.calculated_price = calculatedPriceSets[variant.id]
|
||||
return variant
|
||||
})
|
||||
{ variantsData, fetchedVariants },
|
||||
({ variantsData, fetchedVariants }) => {
|
||||
return (variantsData ??
|
||||
fetchedVariants) as unknown as PrepareVariantLineItemInput[]
|
||||
}
|
||||
)
|
||||
|
||||
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 &
|
||||
ConfirmVariantInventoryWorkflowInputDTO["variants"][number] &
|
||||
WithCalculatedPrice)[]
|
||||
})
|
||||
|
||||
const lineItems = transform({ input, variants }, (data) => {
|
||||
const items = (data.input.items ?? []).map((item) => {
|
||||
const variant = (data.variants ?? []).find(
|
||||
const items = (items_ ?? []).map((item) => {
|
||||
const variant = (variants ?? []).find(
|
||||
(v) => v.id === item.variant_id
|
||||
)!
|
||||
|
||||
const input: PrepareLineItemDataInput = {
|
||||
item,
|
||||
variant: variant,
|
||||
cartId: data.input.cart_id,
|
||||
cartId: cart_id,
|
||||
unitPrice: item.unit_price,
|
||||
isTaxInclusive:
|
||||
item.is_tax_inclusive ??
|
||||
@@ -255,7 +247,8 @@ export const addToCartWorkflow = createWorkflow(
|
||||
})
|
||||
|
||||
return items
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
validateLineItemPricesStep({ items: lineItems })
|
||||
|
||||
@@ -287,7 +280,8 @@ export const addToCartWorkflow = createWorkflow(
|
||||
confirmVariantInventoryWorkflow.runAsStep({
|
||||
input: {
|
||||
sales_channel_id: cart.sales_channel_id,
|
||||
variants,
|
||||
variants:
|
||||
variants as unknown as ConfirmVariantInventoryWorkflowInputDTO["variants"],
|
||||
items: input.items,
|
||||
itemsToUpdate: itemsToConfirmInventory,
|
||||
},
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { ConfirmVariantInventoryWorkflowInputDTO } from "@medusajs/framework/types"
|
||||
import type { ConfirmVariantInventoryWorkflowInputDTO } from "@medusajs/framework/types"
|
||||
import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
createWorkflow,
|
||||
transform,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { BigNumberInput } from "@medusajs/types"
|
||||
import type { BigNumberInput } from "@medusajs/framework/types"
|
||||
import { confirmInventoryStep } from "../steps"
|
||||
import { prepareConfirmInventoryInput } from "../utils/prepare-confirm-inventory-input"
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import {
|
||||
AdditionalData,
|
||||
ConfirmVariantInventoryWorkflowInputDTO,
|
||||
CreateCartDTO,
|
||||
CreateCartWorkflowInputDTO,
|
||||
} from "@medusajs/framework/types"
|
||||
import {
|
||||
CartWorkflowEvents,
|
||||
deduplicate,
|
||||
isDefined,
|
||||
MedusaError,
|
||||
} from "@medusajs/framework/utils"
|
||||
import {
|
||||
@@ -13,30 +14,22 @@ import {
|
||||
createWorkflow,
|
||||
parallelize,
|
||||
transform,
|
||||
when,
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { useQueryGraphStep } from "../../common"
|
||||
import { emitEventStep } from "../../common/steps/emit-event"
|
||||
import {
|
||||
createCartsStep,
|
||||
findOneOrAnyRegionStep,
|
||||
findOrCreateCustomerStep,
|
||||
findSalesChannelStep,
|
||||
getVariantPriceSetsStep,
|
||||
} from "../steps"
|
||||
import { validateLineItemPricesStep } from "../steps/validate-line-item-prices"
|
||||
import { validateSalesChannelStep } from "../steps/validate-sales-channel"
|
||||
import { validateVariantPricesStep } from "../steps/validate-variant-prices"
|
||||
import { productVariantsFields } from "../utils/fields"
|
||||
import { requiredVariantFieldsForInventoryConfirmation } from "../utils/prepare-confirm-inventory-input"
|
||||
import {
|
||||
prepareLineItemData,
|
||||
PrepareLineItemDataInput,
|
||||
} from "../utils/prepare-line-item-data"
|
||||
import { pricingContextResult } from "../utils/schemas"
|
||||
import { confirmVariantInventoryWorkflow } from "./confirm-variant-inventory"
|
||||
import { getVariantsAndItemsWithPrices } from "./get-variants-and-items-with-prices"
|
||||
import { refreshPaymentCollectionForCartWorkflow } from "./refresh-payment-collection"
|
||||
import { updateCartPromotionsWorkflow } from "./update-cart-promotions"
|
||||
import { updateTaxLinesWorkflow } from "./update-tax-lines"
|
||||
@@ -119,7 +112,9 @@ export const createCartWorkflow = createWorkflow(
|
||||
createCartWorkflowId,
|
||||
(input: WorkflowData<CreateCartWorkflowInput>) => {
|
||||
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(
|
||||
@@ -151,79 +146,31 @@ export const createCartWorkflow = createWorkflow(
|
||||
)
|
||||
const setPricingContextResult = setPricingContext.getResult()
|
||||
|
||||
// TODO: This is on par with the context used in v1.*, but we can be more flexible.
|
||||
const pricingContext = transform(
|
||||
{ input, region, customerData, setPricingContextResult },
|
||||
(data) => {
|
||||
if (!data.region) {
|
||||
throw new MedusaError(MedusaError.Types.NOT_FOUND, "No regions found")
|
||||
}
|
||||
|
||||
return {
|
||||
...(data.setPricingContextResult ? data.setPricingContextResult : {}),
|
||||
currency_code: data.input.currency_code ?? data.region.currency_code,
|
||||
region_id: data.region.id,
|
||||
customer_id: data.customerData.customer?.id,
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const variants = when("has-variants", { variantIds }, ({ variantIds }) => {
|
||||
return !!variantIds.length
|
||||
}).then(() => {
|
||||
const { data: variantsData } = useQueryGraphStep({
|
||||
entity: "variants",
|
||||
const { variants, lineItems } = getVariantsAndItemsWithPrices.runAsStep({
|
||||
input: {
|
||||
cart: {
|
||||
currency_code: input.currency_code,
|
||||
region,
|
||||
region_id: region.id,
|
||||
customer_id: customerData.customer?.id,
|
||||
},
|
||||
items: input.items,
|
||||
setPricingContextResult: setPricingContextResult!,
|
||||
variants: {
|
||||
id: variantIds,
|
||||
fields: deduplicate([
|
||||
...productVariantsFields,
|
||||
...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({
|
||||
input: {
|
||||
sales_channel_id: salesChannel.id,
|
||||
variants: variants!,
|
||||
variants:
|
||||
variants as unknown as ConfirmVariantInventoryWorkflowInputDTO["variants"],
|
||||
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) => {
|
||||
return {
|
||||
...data.cartInput,
|
||||
items: data.lineItems,
|
||||
}
|
||||
items: data.lineItems.map((i) => i.data),
|
||||
} as unknown as CreateCartDTO
|
||||
})
|
||||
|
||||
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,
|
||||
CalculateShippingOptionPriceDTO,
|
||||
ListShippingOptionsForCartWithPricingWorkflowInput,
|
||||
} from "@medusajs/types"
|
||||
} from "@medusajs/framework/types"
|
||||
|
||||
import { useQueryGraphStep, validatePresenceOfStep } from "../../common"
|
||||
import { useRemoteQueryStep } from "../../common/steps/use-remote-query"
|
||||
|
||||
@@ -14,9 +14,16 @@ import { cartFieldsForPricingContext } from "../utils/fields"
|
||||
import {
|
||||
AdditionalData,
|
||||
ListShippingOptionsForCartWorkflowInput,
|
||||
} from "@medusajs/types"
|
||||
import { deduplicate, filterObjectByKeys, isDefined } from "@medusajs/framework/utils"
|
||||
import { pricingContextResult, shippingOptionsContextResult } from "../utils/schemas"
|
||||
} from "@medusajs/framework/types"
|
||||
import {
|
||||
deduplicate,
|
||||
filterObjectByKeys,
|
||||
isDefined,
|
||||
} from "@medusajs/framework/utils"
|
||||
import {
|
||||
pricingContextResult,
|
||||
shippingOptionsContextResult,
|
||||
} from "../utils/schemas"
|
||||
|
||||
export const listShippingOptionsForCartWorkflowId =
|
||||
"list-shipping-options-for-cart"
|
||||
@@ -209,16 +216,31 @@ export const listShippingOptionsForCartWorkflow = createWorkflow(
|
||||
resultValidator: shippingOptionsContextResult,
|
||||
}
|
||||
)
|
||||
const setShippingOptionsContextResult = setShippingOptionsContext.getResult()
|
||||
const setShippingOptionsContextResult =
|
||||
setShippingOptionsContext.getResult()
|
||||
|
||||
const queryVariables = transform(
|
||||
{ input, fulfillmentSetIds, cart, setPricingContextResult, setShippingOptionsContextResult },
|
||||
({ input, fulfillmentSetIds, cart, setPricingContextResult, setShippingOptionsContextResult }) => {
|
||||
{
|
||||
input,
|
||||
fulfillmentSetIds,
|
||||
cart,
|
||||
setPricingContextResult,
|
||||
setShippingOptionsContextResult,
|
||||
},
|
||||
({
|
||||
input,
|
||||
fulfillmentSetIds,
|
||||
cart,
|
||||
setPricingContextResult,
|
||||
setShippingOptionsContextResult,
|
||||
}) => {
|
||||
return {
|
||||
id: input.option_ids,
|
||||
|
||||
context: {
|
||||
...(setShippingOptionsContextResult ? setShippingOptionsContextResult : {}),
|
||||
...(setShippingOptionsContextResult
|
||||
? setShippingOptionsContextResult
|
||||
: {}),
|
||||
is_return: input.is_return ? "true" : "false",
|
||||
enabled_in_store: !isDefined(input.enabled_in_store)
|
||||
? "true"
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import {
|
||||
filterObjectByKeys,
|
||||
isDefined,
|
||||
PromotionActions,
|
||||
} from "@medusajs/framework/utils"
|
||||
import type { AdditionalData } from "@medusajs/framework/types"
|
||||
import { isDefined, PromotionActions } from "@medusajs/framework/utils"
|
||||
import {
|
||||
createHook,
|
||||
createWorkflow,
|
||||
@@ -11,22 +8,13 @@ import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { AdditionalData, CartDTO } from "@medusajs/types"
|
||||
import { useQueryGraphStep } from "../../common"
|
||||
import { useRemoteQueryStep } from "../../common/steps/use-remote-query"
|
||||
import { acquireLockStep, releaseLockStep } from "../../locking"
|
||||
import { getVariantPriceSetsStep, updateLineItemsStep } from "../steps"
|
||||
import { validateVariantPricesStep } from "../steps/validate-variant-prices"
|
||||
import {
|
||||
cartFieldsForPricingContext,
|
||||
cartFieldsForRefreshSteps,
|
||||
productVariantsFields,
|
||||
} from "../utils/fields"
|
||||
import {
|
||||
prepareLineItemData,
|
||||
PrepareLineItemDataInput,
|
||||
} from "../utils/prepare-line-item-data"
|
||||
import { updateLineItemsStep } from "../steps"
|
||||
import { cartFieldsForRefreshSteps } from "../utils/fields"
|
||||
import { pricingContextResult } from "../utils/schemas"
|
||||
import { getVariantsAndItemsWithPrices } from "./get-variants-and-items-with-prices"
|
||||
import { refreshCartShippingMethodsWorkflow } from "./refresh-cart-shipping-methods"
|
||||
import { refreshPaymentCollectionForCartWorkflow } from "./refresh-payment-collection"
|
||||
import { updateCartPromotionsWorkflow } from "./update-cart-promotions"
|
||||
@@ -168,93 +156,11 @@ export const refreshCartItemsWorkflow = createWorkflow(
|
||||
},
|
||||
})
|
||||
|
||||
const variantIds = transform({ cart }, (data: { cart: CartDTO }) => {
|
||||
return (data.cart.items ?? []).map((i) => i.variant_id).filter(Boolean)
|
||||
})
|
||||
|
||||
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 { lineItems } = getVariantsAndItemsWithPrices.runAsStep({
|
||||
input: {
|
||||
cart,
|
||||
setPricingContextResult: setPricingContextResult!,
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
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({
|
||||
|
||||
+4
-1
@@ -1,4 +1,7 @@
|
||||
import { BigNumberInput, PaymentSessionDTO } from "@medusajs/framework/types"
|
||||
import type {
|
||||
BigNumberInput,
|
||||
PaymentSessionDTO,
|
||||
} from "@medusajs/framework/types"
|
||||
import {
|
||||
createWorkflow,
|
||||
WorkflowData,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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 { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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 { ContainerRegistrationKeys } from "@medusajs/framework/utils"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Link } from "@medusajs/framework/modules-sdk"
|
||||
import { LinkDefinition } from "@medusajs/framework/types"
|
||||
import type { LinkDefinition } from "@medusajs/framework/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
MedusaError,
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { BatchWorkflowInput, LinkDefinition } from "@medusajs/framework/types"
|
||||
import type {
|
||||
BatchWorkflowInput,
|
||||
LinkDefinition,
|
||||
} from "@medusajs/framework/types"
|
||||
import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { LinkDefinition } from "@medusajs/framework/types"
|
||||
import type { LinkDefinition } from "@medusajs/framework/types"
|
||||
import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { LinkDefinition } from "@medusajs/framework/types"
|
||||
import type { LinkDefinition } from "@medusajs/framework/types"
|
||||
import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { LinkDefinition } from "@medusajs/framework/types"
|
||||
import type { LinkDefinition } from "@medusajs/framework/types"
|
||||
import {
|
||||
WorkflowData,
|
||||
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 { 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 { linkCustomerGroupsToCustomerStep } from "../steps"
|
||||
|
||||
@@ -36,7 +36,9 @@ export const linkCustomerGroupsToCustomerWorkflowId =
|
||||
*/
|
||||
export const linkCustomerGroupsToCustomerWorkflow = createWorkflow(
|
||||
linkCustomerGroupsToCustomerWorkflowId,
|
||||
(input: WorkflowData<LinkCustomerGroupsToCustomerWorkflowInput>): WorkflowData<void> => {
|
||||
(
|
||||
input: WorkflowData<LinkCustomerGroupsToCustomerWorkflowInput>
|
||||
): WorkflowData<void> => {
|
||||
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 { linkCustomersToCustomerGroupStep } from "../steps"
|
||||
|
||||
@@ -36,7 +36,9 @@ export const linkCustomersToCustomerGroupWorkflowId =
|
||||
*/
|
||||
export const linkCustomersToCustomerGroupWorkflow = createWorkflow(
|
||||
linkCustomersToCustomerGroupWorkflowId,
|
||||
(input: WorkflowData<LinkCustomersToCustomerGroupWorkflow>): WorkflowData<void> => {
|
||||
(
|
||||
input: WorkflowData<LinkCustomersToCustomerGroupWorkflow>
|
||||
): WorkflowData<void> => {
|
||||
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 { 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 { 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 {
|
||||
createWorkflow,
|
||||
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 {
|
||||
WorkflowData,
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||
import {
|
||||
CreateLineItemAdjustmentDTO,
|
||||
IOrderModuleService,
|
||||
} from "@medusajs/types"
|
||||
} from "@medusajs/framework/types"
|
||||
|
||||
export const createDraftOrderLineItemAdjustmentsStepId =
|
||||
"create-draft-order-line-item-adjustments"
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||
import {
|
||||
CreateShippingMethodAdjustmentDTO,
|
||||
IOrderModuleService,
|
||||
} from "@medusajs/types"
|
||||
} from "@medusajs/framework/types"
|
||||
|
||||
export const createDraftOrderShippingMethodAdjustmentsStepId =
|
||||
"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 { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
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.
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||
import { IOrderModuleService } from "@medusajs/types"
|
||||
import type { IOrderModuleService } from "@medusajs/framework/types"
|
||||
export const removeDraftOrderLineItemAdjustmentsStepId =
|
||||
"remove-draft-order-line-item-adjustments"
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
import { IOrderModuleService } from "@medusajs/types"
|
||||
import type { IOrderModuleService } from "@medusajs/framework/types"
|
||||
|
||||
export const removeDraftOrderShippingMethodAdjustmentsStepId =
|
||||
"remove-draft-order-shipping-method-adjustments"
|
||||
|
||||
+4
-1
@@ -1,6 +1,9 @@
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
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 =
|
||||
"restore-draft-order-shipping-methods"
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
PromotionActions,
|
||||
} from "@medusajs/framework/utils"
|
||||
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"
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { MedusaError, Modules } from "@medusajs/framework/utils"
|
||||
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 =
|
||||
"update-draft-order-shipping-method"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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 { 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 { 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.
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import {
|
||||
OrderChangeActionDTO,
|
||||
OrderChangeDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
} from "@medusajs/framework/types"
|
||||
|
||||
/**
|
||||
* 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 { 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.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { MedusaError, OrderStatus } from "@medusajs/framework/utils"
|
||||
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.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createStep } from "@medusajs/framework/workflows-sdk"
|
||||
import { PromotionDTO } from "@medusajs/types"
|
||||
import type { PromotionDTO } from "@medusajs/framework/types"
|
||||
import {
|
||||
throwIfCodesAreInactive,
|
||||
throwIfCodesAreMissing,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createStep } from "@medusajs/framework/workflows-sdk"
|
||||
import { PromotionDTO } from "@medusajs/types"
|
||||
import type { PromotionDTO } from "@medusajs/framework/types"
|
||||
import { throwIfCodesAreMissing } from "../utils/validation"
|
||||
|
||||
export const validatePromoCodesToRemoveId = "validate-promo-codes-to-remove"
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
OrderStatus,
|
||||
PromotionStatus,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { OrderDTO, PromotionDTO } from "@medusajs/types"
|
||||
import type { OrderDTO, PromotionDTO } from "@medusajs/framework/types"
|
||||
|
||||
interface ThrowIfNotDraftOrderInput {
|
||||
order: OrderDTO
|
||||
|
||||
@@ -10,7 +10,11 @@ import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} 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 {
|
||||
addOrderLineItemsWorkflow,
|
||||
|
||||
@@ -9,7 +9,11 @@ import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} 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 {
|
||||
createOrderChangeActionsWorkflow,
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ import {
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
ShippingOptionDTO,
|
||||
} from "@medusajs/types"
|
||||
} from "@medusajs/framework/types"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import {
|
||||
createOrderChangeActionsWorkflow,
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { OrderDTO, OrderWorkflow } from "@medusajs/types"
|
||||
import type { OrderDTO, OrderWorkflow } from "@medusajs/framework/types"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import { createOrderChangeStep, previewOrderChangeStep } from "../../order"
|
||||
import { validateDraftOrderStep } from "../steps"
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
when,
|
||||
WorkflowData,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { OrderChangeDTO, OrderDTO } from "@medusajs/types"
|
||||
import type { OrderChangeDTO, OrderDTO } from "@medusajs/framework/types"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import { deleteOrderChangesStep, deleteOrderShippingMethods } from "../../order"
|
||||
import { restoreDraftOrderShippingMethodsStep } from "../steps/restore-draft-order-shipping-methods"
|
||||
|
||||
@@ -8,7 +8,11 @@ import {
|
||||
transform,
|
||||
WorkflowResponse,
|
||||
} 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 {
|
||||
prepareConfirmInventoryInput,
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} 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 { validateDraftOrderStep } from "../steps/validate-draft-order"
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
createWorkflow,
|
||||
transform,
|
||||
} 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 { removeRemoteLinkStep, useQueryGraphStep } from "../../common"
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { OrderDTO } from "@medusajs/types"
|
||||
import type { OrderDTO } from "@medusajs/framework/types"
|
||||
import {
|
||||
getActionsToComputeFromPromotionsStep,
|
||||
getPromotionCodesToApply,
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import {
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
} from "@medusajs/framework/types"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import {
|
||||
deleteOrderChangeActionsStep,
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ import {
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
} from "@medusajs/framework/types"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import {
|
||||
deleteOrderChangeActionsStep,
|
||||
|
||||
@@ -9,7 +9,11 @@ import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} 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 {
|
||||
createOrderChangeActionsWorkflow,
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { OrderChangeDTO, OrderDTO } from "@medusajs/types"
|
||||
import type { OrderChangeDTO, OrderDTO } from "@medusajs/framework/types"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import {
|
||||
createOrderChangeActionsWorkflow,
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
transform,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { OrderChangeDTO, OrderDTO } from "@medusajs/types"
|
||||
import type { OrderChangeDTO, OrderDTO } from "@medusajs/framework/types"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import {
|
||||
createOrUpdateOrderPaymentCollectionWorkflow,
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import {
|
||||
OrderChangeDTO,
|
||||
OrderDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
} from "@medusajs/framework/types"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import {
|
||||
previewOrderChangeStep,
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ import {
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
} from "@medusajs/framework/types"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import {
|
||||
previewOrderChangeStep,
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
OrderDTO,
|
||||
OrderPreviewDTO,
|
||||
OrderWorkflow,
|
||||
} from "@medusajs/types"
|
||||
} from "@medusajs/framework/types"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import {
|
||||
createOrderChangeActionsWorkflow,
|
||||
|
||||
+5
-1
@@ -10,7 +10,11 @@ import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} 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 {
|
||||
createOrderChangeActionsWorkflow,
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
RegisterOrderChangeDTO,
|
||||
UpdateOrderDTO,
|
||||
UpsertOrderAddressDTO,
|
||||
} from "@medusajs/types"
|
||||
} from "@medusajs/framework/types"
|
||||
import { emitEventStep, useRemoteQueryStep } from "../../common"
|
||||
import { previewOrderChangeStep, registerOrderChangesStep } from "../../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 { 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 { 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 {
|
||||
WorkflowData,
|
||||
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 { 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 { 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 { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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 { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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 {
|
||||
ContainerRegistrationKeys,
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { ServiceZoneDTO, ShippingOptionDTO } from "@medusajs/framework/types"
|
||||
import type {
|
||||
ServiceZoneDTO,
|
||||
ShippingOptionDTO,
|
||||
} from "@medusajs/framework/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
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 { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { FulfillmentWorkflow } from "@medusajs/framework/types"
|
||||
import { MedusaError, Modules, ShippingOptionPriceType, } from "@medusajs/framework/utils"
|
||||
import type { FulfillmentWorkflow } from "@medusajs/framework/types"
|
||||
import {
|
||||
MedusaError,
|
||||
Modules,
|
||||
ShippingOptionPriceType,
|
||||
} from "@medusajs/framework/utils"
|
||||
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.
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import { FulfillmentWorkflow } from "@medusajs/framework/types"
|
||||
import type { FulfillmentWorkflow } from "@medusajs/framework/types"
|
||||
import {
|
||||
createWorkflow,
|
||||
transform,
|
||||
|
||||
Loaded 100 of 281 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user