fix: Correctly fetch cart when updating a line item (#7196)
This commit is contained in:
1 parent
ba71903e12
commit
8387d03370
1 file changed
+17
-10
@@ -2,28 +2,35 @@ import {
|
|||||||
deleteLineItemsWorkflow,
|
deleteLineItemsWorkflow,
|
||||||
updateLineItemInCartWorkflow,
|
updateLineItemInCartWorkflow,
|
||||||
} from "@medusajs/core-flows"
|
} from "@medusajs/core-flows"
|
||||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
|
||||||
import { ICartModuleService } from "@medusajs/types"
|
|
||||||
import { MedusaError } from "@medusajs/utils"
|
import { MedusaError } from "@medusajs/utils"
|
||||||
import { MedusaRequest, MedusaResponse } from "../../../../../../types/routing"
|
import { MedusaRequest, MedusaResponse } from "../../../../../../types/routing"
|
||||||
import { refetchCart } from "../../../helpers"
|
import { refetchCart } from "../../../helpers"
|
||||||
import { StoreUpdateCartLineItemType } from "../../../validators"
|
import { StoreUpdateCartLineItemType } from "../../../validators"
|
||||||
|
import { prepareListQuery } from "../../../../../../utils/get-query-config"
|
||||||
|
|
||||||
export const POST = async (
|
export const POST = async (
|
||||||
req: MedusaRequest<StoreUpdateCartLineItemType>,
|
req: MedusaRequest<StoreUpdateCartLineItemType>,
|
||||||
res: MedusaResponse
|
res: MedusaResponse
|
||||||
) => {
|
) => {
|
||||||
const cartModuleService = req.scope.resolve<ICartModuleService>(
|
const cart = await refetchCart(
|
||||||
ModuleRegistrationName.CART
|
req.params.id,
|
||||||
|
req.scope,
|
||||||
|
prepareListQuery(
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
defaults: [
|
||||||
|
"id",
|
||||||
|
"region_id",
|
||||||
|
"customer_id",
|
||||||
|
"sales_channel_id",
|
||||||
|
"currency_code",
|
||||||
|
"*items",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
).remoteQueryConfig.fields
|
||||||
)
|
)
|
||||||
|
|
||||||
const cart = await cartModuleService.retrieve(req.params.id, {
|
|
||||||
select: ["id", "region_id", "currency_code"],
|
|
||||||
relations: ["region", "items", "items.variant_id"],
|
|
||||||
})
|
|
||||||
|
|
||||||
const item = cart.items?.find((i) => i.id === req.params.line_id)
|
const item = cart.items?.find((i) => i.id === req.params.line_id)
|
||||||
|
|
||||||
if (!item) {
|
if (!item) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
MedusaError.Types.NOT_FOUND,
|
MedusaError.Types.NOT_FOUND,
|
||||||
|
|||||||
Reference in new issue
Block a user