feat(medusa,orchestration): Decouple Product in Cart domain (#4945)
This commit is contained in:
committed by
GitHub
parent
1958809fa9
commit
4b0e3fb2a7
@@ -1,19 +1,19 @@
|
||||
import {
|
||||
CartService,
|
||||
DraftOrderService,
|
||||
LineItemService,
|
||||
} from "../../../../services"
|
||||
import { IsInt, IsObject, IsOptional, IsString } from "class-validator"
|
||||
import {
|
||||
defaultAdminDraftOrdersCartFields,
|
||||
defaultAdminDraftOrdersCartRelations,
|
||||
defaultAdminDraftOrdersFields,
|
||||
} from "."
|
||||
import {
|
||||
CartService,
|
||||
DraftOrderService,
|
||||
LineItemService,
|
||||
} from "../../../../services"
|
||||
|
||||
import { EntityManager } from "typeorm"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { cleanResponseData } from "../../../../utils/clean-response-data"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
|
||||
/**
|
||||
* @oas [post] /admin/draft-orders/{id}/line-items
|
||||
@@ -119,7 +119,9 @@ export default async (req, res) => {
|
||||
|
||||
await cartService
|
||||
.withTransaction(manager)
|
||||
.addLineItem(draftOrder.cart_id, line, { validateSalesChannels: false })
|
||||
.addOrUpdateLineItems(draftOrder.cart_id, line, {
|
||||
validateSalesChannels: false,
|
||||
})
|
||||
} else {
|
||||
// custom line items can be added to a draft order
|
||||
await lineItemService.withTransaction(manager).create({
|
||||
|
||||
@@ -39,7 +39,7 @@ export async function handleAddOrUpdateLineItem(
|
||||
metadata: data.metadata,
|
||||
})
|
||||
|
||||
await txCartService.addLineItem(cart.id, line, {
|
||||
await txCartService.addOrUpdateLineItems(cart.id, line, {
|
||||
validateSalesChannels: featureFlagRouter.isFeatureEnabled("sales_channels"),
|
||||
})
|
||||
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import { FlagRouter } from "@medusajs/utils"
|
||||
import { IsBooleanString, IsOptional, IsString } from "class-validator"
|
||||
import { PricingService, ProductService } from "../../../../services"
|
||||
import { defaultRelations } from "."
|
||||
import IsolateProductDomainFeatureFlag from "../../../../loaders/feature-flags/isolate-product-domain"
|
||||
import {
|
||||
PricingService,
|
||||
ProductService,
|
||||
ShippingProfileService,
|
||||
} from "../../../../services"
|
||||
import ShippingOptionService from "../../../../services/shipping-option"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
import { defaultRelations } from "."
|
||||
|
||||
/**
|
||||
* @oas [get] /store/shipping-options
|
||||
@@ -61,6 +67,10 @@ export default async (req, res) => {
|
||||
const shippingOptionService: ShippingOptionService = req.scope.resolve(
|
||||
"shippingOptionService"
|
||||
)
|
||||
const shippingProfileService: ShippingProfileService = req.scope.resolve(
|
||||
"shippingProfileService"
|
||||
)
|
||||
const featureFlagRouter: FlagRouter = req.scope.resolve("featureFlagRouter")
|
||||
|
||||
// should be selector
|
||||
const query: Record<string, unknown> = {}
|
||||
@@ -76,8 +86,17 @@ export default async (req, res) => {
|
||||
query.admin_only = false
|
||||
|
||||
if (productIds.length) {
|
||||
const prods = await productService.list({ id: productIds })
|
||||
query.profile_id = prods.map((p) => p.profile_id)
|
||||
if (
|
||||
featureFlagRouter.isFeatureEnabled(IsolateProductDomainFeatureFlag.key)
|
||||
) {
|
||||
const productShippinProfileMap =
|
||||
await shippingProfileService.getMapProfileIdsByProductIds(productIds)
|
||||
|
||||
query.profile_id = [...productShippinProfileMap.values()]
|
||||
} else {
|
||||
const prods = await productService.list({ id: productIds })
|
||||
query.profile_id = prods.map((p) => p.profile_id)
|
||||
}
|
||||
}
|
||||
|
||||
const options = await shippingOptionService.list(query, {
|
||||
|
||||
Reference in New Issue
Block a user