feat(medusa,core-flows,types): add cart <> tax integration workflows + steps (#6580)

what:

- adds tax lines to cart when item operations take place

RESOLVES CORE-1821
RESOLVES CORE-1822
RESOLVES CORE-1823
RESOLVES CORE-1824
This commit is contained in:
Riqwan Thamir
2024-03-07 16:17:43 +00:00
committed by GitHub
parent 8c57e61cb8
commit e4acde1aa2
26 changed files with 1096 additions and 180 deletions
@@ -1,18 +1,20 @@
import { addToCartWorkflow } from "@medusajs/core-flows"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { ICartModuleService } from "@medusajs/types"
import { LinkModuleUtils, Modules } from "@medusajs/modules-sdk"
import { remoteQueryObjectFromString } from "@medusajs/utils"
import { MedusaRequest, MedusaResponse } from "../../../../../types/routing"
import { defaultStoreCartFields } from "../../query-config"
import { StorePostCartsCartLineItemsReq } from "./validators"
export const POST = async (req: MedusaRequest, res: MedusaResponse) => {
const cartModuleService = req.scope.resolve<ICartModuleService>(
ModuleRegistrationName.CART
)
const remoteQuery = req.scope.resolve(LinkModuleUtils.REMOTE_QUERY)
const cart = await cartModuleService.retrieve(req.params.id, {
select: ["id", "region_id", "currency_code"],
const query = remoteQueryObjectFromString({
entryPoint: Modules.CART,
fields: defaultStoreCartFields,
})
const [cart] = await remoteQuery(query, {
cart: { id: req.params.id },
})
const workflowInput = {
@@ -29,13 +31,6 @@ export const POST = async (req: MedusaRequest, res: MedusaResponse) => {
throw errors[0].error
}
const remoteQuery = req.scope.resolve("remoteQuery")
const query = remoteQueryObjectFromString({
entryPoint: "cart",
fields: defaultStoreCartFields,
})
const [updatedCart] = await remoteQuery(query, {
cart: { id: req.params.id },
})
@@ -1,4 +1,5 @@
import { updateCartWorkflow } from "@medusajs/core-flows"
import { LinkModuleUtils, Modules } from "@medusajs/modules-sdk"
import { UpdateCartDataDTO } from "@medusajs/types"
import { remoteQueryObjectFromString } from "@medusajs/utils"
@@ -6,12 +7,11 @@ import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
import { defaultStoreCartFields } from "../query-config"
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
const remoteQuery = req.scope.resolve("remoteQuery")
const remoteQuery = req.scope.resolve(LinkModuleUtils.REMOTE_QUERY)
const variables = { id: req.params.id }
const query = remoteQueryObjectFromString({
entryPoint: "cart",
entryPoint: Modules.CART,
fields: defaultStoreCartFields,
})
@@ -38,16 +38,16 @@ export const POST = async (
throw errors[0].error
}
const remoteQuery = req.scope.resolve("remoteQuery")
const remoteQuery = req.scope.resolve(LinkModuleUtils.REMOTE_QUERY)
const query = remoteQueryObjectFromString({
entryPoint: "cart",
entryPoint: Modules.CART,
fields: defaultStoreCartFields,
})
const [updatedCart] = await remoteQuery(query, {
const [cart] = await remoteQuery(query, {
cart: { id: req.params.id },
})
res.status(200).json({ cart: updatedCart })
res.status(200).json({ cart })
}
@@ -5,16 +5,40 @@ export const defaultStoreCartFields = [
"created_at",
"updated_at",
"items.id",
"items.variant_id",
"items.product_id",
"items.product_title",
"items.product_description",
"items.product_subtitle",
"items.product_type",
"items.product_collection",
"items.product_handle",
"items.variant_sku",
"items.variant_barcode",
"items.variant_title",
"items.created_at",
"items.updated_at",
"items.title",
"items.quantity",
"items.unit_price",
"items.tax_lines.id",
"items.tax_lines.description",
"items.tax_lines.code",
"items.tax_lines.rate",
"items.tax_lines.provider_id",
"items.adjustments.id",
"items.adjustments.code",
"items.adjustments.amount",
"customer.id",
"customer.email",
"customer.groups.id",
"shipping_methods.tax_lines.id",
"shipping_methods.tax_lines.description",
"shipping_methods.tax_lines.code",
"shipping_methods.tax_lines.rate",
"shipping_methods.tax_lines.provider_id",
"shipping_methods.shipping_option_id",
"shipping_methods.amount",
"shipping_methods.adjustments.id",
"shipping_methods.adjustments.code",
"shipping_methods.adjustments.amount",
@@ -27,6 +51,7 @@ export const defaultStoreCartFields = [
"shipping_address.postal_code",
"shipping_address.country_code",
"shipping_address.region_code",
"shipping_address.province",
"shipping_address.phone",
"billing_address.id",
"billing_address.first_name",
@@ -51,23 +76,29 @@ export const defaultStoreCartFields = [
export const defaultStoreCartRelations = [
"items",
"items.tax_lines",
"items.adjustments",
"region",
"customer",
"customer.groups",
"shipping_address",
"billing_address",
"shipping_methods",
"shipping_methods.tax_lines",
"shipping_methods.adjustments",
]
export const allowedRelations = [
"items",
"items.tax_lines",
"items.adjustments",
"region",
"customer",
"customer.groups",
"shipping_address",
"billing_address",
"shipping_methods",
"shipping_methods.tax_lines",
"shipping_methods.adjustments",
"sales_channel",
]
@@ -1,4 +1,5 @@
import { createCartWorkflow } from "@medusajs/core-flows"
import { LinkModuleUtils, Modules } from "@medusajs/modules-sdk"
import { CreateCartWorkflowInputDTO } from "@medusajs/types"
import { remoteQueryObjectFromString } from "@medusajs/utils"
import {
@@ -25,16 +26,13 @@ export const POST = async (
throw errors[0].error
}
const remoteQuery = req.scope.resolve("remoteQuery")
const variables = { id: result.id }
const remoteQuery = req.scope.resolve(LinkModuleUtils.REMOTE_QUERY)
const query = remoteQueryObjectFromString({
entryPoint: "cart",
entryPoint: Modules.CART,
fields: defaultStoreCartFields,
})
const [cart] = await remoteQuery(query, { cart: variables })
const [cart] = await remoteQuery(query, { cart: { id: result.id } })
res.status(200).json({ cart })
}
@@ -29,6 +29,14 @@ export class StorePostCartReq {
@IsString()
region_id?: string
@IsOptional()
@IsType([AddressPayload, String])
shipping_address?: AddressPayload | string
@IsOptional()
@IsType([AddressPayload, String])
billing_address?: AddressPayload | string
@IsOptional()
@IsString()
email?: string