feat(core-flows,types,order,cart): assign tax lines only to regular products (#11994)
what: - assign tax lines only to regular products
This commit is contained in:
@@ -16,6 +16,7 @@ export const cartFieldsForRefreshSteps = [
|
||||
"region.*",
|
||||
"items.*",
|
||||
"items.product.id",
|
||||
"items.product.is_giftcard",
|
||||
"items.product.collection_id",
|
||||
"items.product.categories.id",
|
||||
"items.product.tags.id",
|
||||
@@ -105,6 +106,7 @@ export const completeCartFields = [
|
||||
"payment_collection.payment_sessions.*",
|
||||
"items.variant.id",
|
||||
"items.variant.product.id",
|
||||
"items.variant.product.is_giftcard",
|
||||
"items.variant.product.shipping_profile.id",
|
||||
"items.variant.manage_inventory",
|
||||
"items.variant.allow_backorder",
|
||||
@@ -157,6 +159,7 @@ export const productVariantsFields = [
|
||||
"product.collection.title",
|
||||
"product.handle",
|
||||
"product.discountable",
|
||||
"product.is_giftcard",
|
||||
"product.shipping_profile.id",
|
||||
"calculated_price.*",
|
||||
"inventory_items.inventory_item_id",
|
||||
|
||||
@@ -150,6 +150,7 @@ export function prepareLineItemData(data: PrepareLineItemDataInput) {
|
||||
variant_option_values: item?.variant_option_values,
|
||||
|
||||
is_discountable: variant?.product?.discountable ?? item?.is_discountable,
|
||||
is_giftcard: variant?.product?.is_giftcard ?? false,
|
||||
requires_shipping: requiresShipping,
|
||||
|
||||
unit_price: unitPrice,
|
||||
|
||||
@@ -21,6 +21,7 @@ const cartFields = [
|
||||
"items.id",
|
||||
"items.variant_id",
|
||||
"items.product_id",
|
||||
"items.product.is_giftcard",
|
||||
"items.product_title",
|
||||
"items.product_description",
|
||||
"items.product_subtitle",
|
||||
|
||||
@@ -86,13 +86,13 @@ export const createOrdersWorkflowId = "create-orders"
|
||||
/**
|
||||
* This workflow creates an order. It's used by the [Create Draft Order Admin API Route](https://docs.medusajs.com/api/admin#draft-orders_postdraftorders), but
|
||||
* you can also use it to create any order.
|
||||
*
|
||||
* This workflow has a hook that allows you to perform custom actions on the created order. For example, you can pass under `additional_data` custom data that
|
||||
*
|
||||
* This workflow has a hook that allows you to perform custom actions on the created order. For example, you can pass under `additional_data` custom data that
|
||||
* allows you to create custom data models linked to the order.
|
||||
*
|
||||
*
|
||||
* You can also use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around creating an order. For example,
|
||||
* you can create a workflow that imports orders from an external system, then uses this workflow to create the orders in Medusa.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* const { result } = await createOrderWorkflow(container)
|
||||
* .run({
|
||||
@@ -121,11 +121,11 @@ export const createOrdersWorkflowId = "create-orders"
|
||||
* }
|
||||
* }
|
||||
* })
|
||||
*
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
*
|
||||
* Create an order.
|
||||
*
|
||||
*
|
||||
* @property hooks.orderCreated - This hook is executed after the order is created. You can consume this hook to perform custom actions on the created order.
|
||||
*/
|
||||
export const createOrderWorkflow = createWorkflow(
|
||||
|
||||
@@ -17,6 +17,7 @@ const completeOrderFields = [
|
||||
"region.automatic_taxes",
|
||||
"items.id",
|
||||
"items.is_tax_inclusive",
|
||||
"items.is_giftcard",
|
||||
"items.variant_id",
|
||||
"items.product_id",
|
||||
"items.product_title",
|
||||
@@ -101,6 +102,7 @@ const lineItemFields = [
|
||||
"variant_id",
|
||||
"product_id",
|
||||
"is_tax_inclusive",
|
||||
"is_giftcard",
|
||||
"product_title",
|
||||
"product_description",
|
||||
"product_subtitle",
|
||||
@@ -137,7 +139,7 @@ export type UpdateOrderTaxLinesWorkflowInput = {
|
||||
shipping_method_ids?: string[]
|
||||
/**
|
||||
* Whether to force the tax calculation. If enabled, the tax provider
|
||||
* may send request to a third-party service to retrieve the calculated
|
||||
* may send request to a third-party service to retrieve the calculated
|
||||
* tax rates. This depends on the chosen tax provider in the order's tax region.
|
||||
*/
|
||||
force_tax_calculation?: boolean
|
||||
@@ -156,10 +158,10 @@ export const updateOrderTaxLinesWorkflowId = "update-order-tax-lines"
|
||||
* This workflow updates the tax lines of items and shipping methods in an order. It's used by
|
||||
* other order-related workflows, such as the {@link createOrderWorkflow} to set the order's
|
||||
* tax lines.
|
||||
*
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to update an
|
||||
* order's tax lines in your custom flows.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* const { result } = await updateOrderTaxLinesWorkflow(container)
|
||||
* .run({
|
||||
@@ -168,9 +170,9 @@ export const updateOrderTaxLinesWorkflowId = "update-order-tax-lines"
|
||||
* item_ids: ["orli_123", "orli_456"],
|
||||
* }
|
||||
* })
|
||||
*
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
*
|
||||
* Update the tax lines of items and shipping methods in an order.
|
||||
*/
|
||||
export const updateOrderTaxLinesWorkflow = createWorkflow(
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
TaxableShippingDTO,
|
||||
TaxCalculationContext,
|
||||
} from "@medusajs/framework/types"
|
||||
import { MedusaError, Modules } from "@medusajs/framework/utils"
|
||||
import { isDefined, MedusaError, Modules } from "@medusajs/framework/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
@@ -168,6 +168,11 @@ export const getItemTaxLinesStep = createStep(
|
||||
is_return: isReturn = false,
|
||||
shipping_address: shippingAddress,
|
||||
} = data
|
||||
|
||||
const filteredItems = items.filter(
|
||||
(item) => !item.is_giftcard || !isDefined(item.is_giftcard)
|
||||
) as OrderLineItemDTO[] | CartLineItemDTO[]
|
||||
|
||||
const taxService = container.resolve<ITaxModuleService>(Modules.TAX)
|
||||
|
||||
const taxContext = normalizeTaxModuleContext(
|
||||
@@ -188,7 +193,7 @@ export const getItemTaxLinesStep = createStep(
|
||||
|
||||
if (items.length) {
|
||||
stepResponseData.lineItemTaxLines = (await taxService.getTaxLines(
|
||||
normalizeLineItemsForTax(orderOrCart, items),
|
||||
normalizeLineItemsForTax(orderOrCart, filteredItems),
|
||||
taxContext
|
||||
)) as ItemTaxLineDTO[]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user