fix(core-flows): copy line items attribute (#8471)
removing `requires_shipping` from variant won't be part of this PR
This commit is contained in:
@@ -2032,6 +2032,7 @@ medusaIntegrationTestRunner({
|
|||||||
original_shipping_total: 0,
|
original_shipping_total: 0,
|
||||||
items: [
|
items: [
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
|
id: expect.stringContaining("ordli_"),
|
||||||
product_id: product.id,
|
product_id: product.id,
|
||||||
unit_price: 100,
|
unit_price: 100,
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ export const completeCartFields = [
|
|||||||
"payment_collection.*",
|
"payment_collection.*",
|
||||||
"payment_collection.payment_sessions.*",
|
"payment_collection.payment_sessions.*",
|
||||||
"items.variant.id",
|
"items.variant.id",
|
||||||
|
"items.variant.product.id",
|
||||||
"items.variant.manage_inventory",
|
"items.variant.manage_inventory",
|
||||||
"items.variant.allow_backorder",
|
"items.variant.allow_backorder",
|
||||||
"items.variant.inventory_items.inventory_item_id",
|
"items.variant.inventory_items.inventory_item_id",
|
||||||
@@ -95,6 +96,9 @@ export const productVariantsFields = [
|
|||||||
"sku",
|
"sku",
|
||||||
"manage_inventory",
|
"manage_inventory",
|
||||||
"allow_backorder",
|
"allow_backorder",
|
||||||
|
"requires_shipping",
|
||||||
|
"is_discountable",
|
||||||
|
"variant_option_values",
|
||||||
"barcode",
|
"barcode",
|
||||||
"product.id",
|
"product.id",
|
||||||
"product.title",
|
"product.title",
|
||||||
@@ -104,6 +108,7 @@ export const productVariantsFields = [
|
|||||||
"product.type",
|
"product.type",
|
||||||
"product.collection",
|
"product.collection",
|
||||||
"product.handle",
|
"product.handle",
|
||||||
|
"product.discountable",
|
||||||
"calculated_price.calculated_amount",
|
"calculated_price.calculated_amount",
|
||||||
"calculated_price.is_calculated_price_tax_inclusive",
|
"calculated_price.is_calculated_price_tax_inclusive",
|
||||||
"inventory_items.inventory_item_id",
|
"inventory_items.inventory_item_id",
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import {
|
import {
|
||||||
BigNumberInput,
|
BigNumberInput,
|
||||||
|
CartLineItemDTO,
|
||||||
CreateOrderAdjustmentDTO,
|
CreateOrderAdjustmentDTO,
|
||||||
CreateOrderLineItemTaxLineDTO,
|
CreateOrderLineItemTaxLineDTO,
|
||||||
ProductVariantDTO,
|
ProductVariantDTO,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
|
|
||||||
interface Input {
|
interface Input {
|
||||||
|
item?: CartLineItemDTO
|
||||||
quantity: BigNumberInput
|
quantity: BigNumberInput
|
||||||
metadata?: Record<string, any>
|
metadata?: Record<string, any>
|
||||||
unitPrice: BigNumberInput
|
unitPrice: BigNumberInput
|
||||||
@@ -18,6 +20,7 @@ interface Input {
|
|||||||
|
|
||||||
export function prepareLineItemData(data: Input) {
|
export function prepareLineItemData(data: Input) {
|
||||||
const {
|
const {
|
||||||
|
item,
|
||||||
variant,
|
variant,
|
||||||
unitPrice,
|
unitPrice,
|
||||||
isTaxInclusive,
|
isTaxInclusive,
|
||||||
@@ -34,23 +37,31 @@ export function prepareLineItemData(data: Input) {
|
|||||||
|
|
||||||
const lineItem: any = {
|
const lineItem: any = {
|
||||||
quantity,
|
quantity,
|
||||||
title: variant.title,
|
title: variant.title ?? item?.title,
|
||||||
|
subtitle: variant.product.title ?? item?.subtitle,
|
||||||
|
thumbnail: variant.product.thumbnail ?? item?.thumbnail,
|
||||||
|
|
||||||
subtitle: variant.product.title,
|
product_id: variant.product.id ?? item?.product_id,
|
||||||
thumbnail: variant.product.thumbnail,
|
product_title: variant.product.title ?? item?.product_title,
|
||||||
|
product_description:
|
||||||
product_id: variant.product.id,
|
variant.product.description ?? item?.product_description,
|
||||||
product_title: variant.product.title,
|
product_subtitle: variant.product.subtitle ?? item?.product_subtitle,
|
||||||
product_description: variant.product.description,
|
product_type:
|
||||||
product_subtitle: variant.product.subtitle,
|
variant.product.type?.[0]?.value ?? item?.product_type ?? null,
|
||||||
product_type: variant.product.type?.[0]?.value ?? null,
|
product_collection:
|
||||||
product_collection: variant.product.collection?.[0]?.value ?? null,
|
variant.product.collection?.[0]?.value ??
|
||||||
product_handle: variant.product.handle,
|
item?.product_collection ??
|
||||||
|
null,
|
||||||
|
product_handle: variant.product.handle ?? item?.product_handle,
|
||||||
|
|
||||||
variant_id: variant.id,
|
variant_id: variant.id,
|
||||||
variant_sku: variant.sku,
|
variant_sku: variant.sku ?? item?.variant_sku,
|
||||||
variant_barcode: variant.barcode,
|
variant_barcode: variant.barcode ?? item?.variant_barcode,
|
||||||
variant_title: variant.title,
|
variant_title: variant.title ?? item?.variant_title,
|
||||||
|
variant_option_values: item?.variant_option_values,
|
||||||
|
|
||||||
|
is_discountable: variant.product.discountable ?? item?.is_discountable,
|
||||||
|
requires_shipping: variant.requires_shipping ?? item?.requires_shipping,
|
||||||
|
|
||||||
unit_price: unitPrice,
|
unit_price: unitPrice,
|
||||||
is_tax_inclusive: !!isTaxInclusive,
|
is_tax_inclusive: !!isTaxInclusive,
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ import { authorizePaymentSessionStep } from "../../../payment/steps/authorize-pa
|
|||||||
import { validateCartPaymentsStep } from "../steps"
|
import { validateCartPaymentsStep } from "../steps"
|
||||||
import { reserveInventoryStep } from "../steps/reserve-inventory"
|
import { reserveInventoryStep } from "../steps/reserve-inventory"
|
||||||
import { completeCartFields } from "../utils/fields"
|
import { completeCartFields } from "../utils/fields"
|
||||||
|
import {
|
||||||
|
prepareAdjustmentsData,
|
||||||
|
prepareLineItemData,
|
||||||
|
prepareTaxLinesData,
|
||||||
|
} from "../utils/prepare-line-item-data"
|
||||||
import { confirmVariantInventoryWorkflow } from "./confirm-variant-inventory"
|
import { confirmVariantInventoryWorkflow } from "./confirm-variant-inventory"
|
||||||
|
|
||||||
export const completeCartWorkflowId = "complete-cart"
|
export const completeCartWorkflowId = "complete-cart"
|
||||||
@@ -80,11 +85,38 @@ export const completeCartWorkflow = createWorkflow(
|
|||||||
)
|
)
|
||||||
|
|
||||||
const cartToOrder = transform({ input, cart }, ({ cart }) => {
|
const cartToOrder = transform({ input, cart }, ({ cart }) => {
|
||||||
const itemAdjustments = (cart.items || [])
|
const allItems = (cart.items ?? []).map((item) => {
|
||||||
?.map((item) => item.adjustments || [])
|
return prepareLineItemData({
|
||||||
|
item,
|
||||||
|
variant: item.variant,
|
||||||
|
unitPrice: item.raw_unit_price ?? item.unit_price,
|
||||||
|
isTaxInclusive: item.is_tax_inclusive,
|
||||||
|
quantity: item.raw_quantity ?? item.quantity,
|
||||||
|
metadata: item?.metadata,
|
||||||
|
taxLines: item.tax_lines ?? [],
|
||||||
|
adjustments: item.adjustments ?? [],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const shippingMethods = (cart.shipping_methods ?? []).map((sm) => {
|
||||||
|
return {
|
||||||
|
name: sm.name,
|
||||||
|
description: sm.description,
|
||||||
|
amount: sm.raw_amount ?? sm.amount,
|
||||||
|
is_tax_inclusive: sm.is_tax_inclusive,
|
||||||
|
shipping_option_id: sm.shipping_option_id,
|
||||||
|
data: sm.data,
|
||||||
|
metadata: sm.metadata,
|
||||||
|
tax_lines: prepareTaxLinesData(sm.tax_lines ?? []),
|
||||||
|
adjustments: prepareAdjustmentsData(sm.adjustments ?? []),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const itemAdjustments = allItems
|
||||||
|
.map((item) => item.adjustments ?? [])
|
||||||
.flat(1)
|
.flat(1)
|
||||||
const shippingAdjustments = (cart.shipping_methods || [])
|
const shippingAdjustments = shippingMethods
|
||||||
?.map((sm) => sm.adjustments || [])
|
.map((sm) => sm.adjustments ?? [])
|
||||||
.flat(1)
|
.flat(1)
|
||||||
|
|
||||||
const promoCodes = [...itemAdjustments, ...shippingAdjustments]
|
const promoCodes = [...itemAdjustments, ...shippingAdjustments]
|
||||||
@@ -101,8 +133,8 @@ export const completeCartWorkflow = createWorkflow(
|
|||||||
shipping_address: cart.shipping_address,
|
shipping_address: cart.shipping_address,
|
||||||
billing_address: cart.billing_address,
|
billing_address: cart.billing_address,
|
||||||
no_notification: false,
|
no_notification: false,
|
||||||
items: cart.items,
|
items: allItems,
|
||||||
shipping_methods: cart.shipping_methods,
|
shipping_methods: shippingMethods,
|
||||||
metadata: cart.metadata,
|
metadata: cart.metadata,
|
||||||
promo_codes: promoCodes,
|
promo_codes: promoCodes,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -192,6 +192,10 @@ export interface ProductVariantDTO {
|
|||||||
* Whether the product variant's inventory should be managed by the core system.
|
* Whether the product variant's inventory should be managed by the core system.
|
||||||
*/
|
*/
|
||||||
manage_inventory: boolean
|
manage_inventory: boolean
|
||||||
|
/**
|
||||||
|
* Whether the product variant's requires shipping.
|
||||||
|
*/
|
||||||
|
requires_shipping: boolean
|
||||||
/**
|
/**
|
||||||
* The HS Code of the product variant.
|
* The HS Code of the product variant.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export const defaultAdminRetrieveOrderFields = [
|
|||||||
"total",
|
"total",
|
||||||
"subtotal",
|
"subtotal",
|
||||||
"tax_total",
|
"tax_total",
|
||||||
|
"order_change",
|
||||||
"discount_total",
|
"discount_total",
|
||||||
"discount_tax_total",
|
"discount_tax_total",
|
||||||
"original_total",
|
"original_total",
|
||||||
|
|||||||
Reference in New Issue
Block a user