feat(medusa): enable price list prices for product endpoints (#10197)

This commit is contained in:
Riqwan Thamir
2024-11-21 14:08:42 +01:00
committed by GitHub
parent 35afa04a93
commit d91da7b418
3 changed files with 412 additions and 24 deletions
@@ -1,19 +1,20 @@
import { isPresent, ProductStatus } from "@medusajs/framework/utils"
import { validateAndTransformQuery } from "@medusajs/framework"
import {
applyDefaultFilters,
applyParamsAsFilters,
authenticate,
clearFiltersByKey,
maybeApplyLinkFilter,
MiddlewareRoute,
setContext,
} from "@medusajs/framework/http"
import { isPresent, ProductStatus } from "@medusajs/framework/utils"
import {
filterByValidSalesChannels,
normalizeDataForContext,
setPricingContext,
setTaxContext,
} from "../../utils/middlewares"
import { validateAndTransformQuery } from "@medusajs/framework"
import { maybeApplyStockLocationId } from "./helpers"
import * as QueryConfig from "./query-config"
import { StoreGetProductsParams } from "./validators"
@@ -23,6 +24,9 @@ export const storeProductRoutesMiddlewares: MiddlewareRoute[] = [
method: ["GET"],
matcher: "/store/products",
middlewares: [
authenticate("customer", ["session", "bearer"], {
allowUnauthenticated: true,
}),
validateAndTransformQuery(
StoreGetProductsParams,
QueryConfig.listProductQueryConfig
@@ -60,6 +64,9 @@ export const storeProductRoutesMiddlewares: MiddlewareRoute[] = [
method: ["GET"],
matcher: "/store/products/:id",
middlewares: [
authenticate("customer", ["session", "bearer"], {
allowUnauthenticated: true,
}),
validateAndTransformQuery(
StoreGetProductsParams,
QueryConfig.retrieveProductQueryConfig
@@ -1,11 +1,11 @@
import { MedusaPricingContext } from "@medusajs/framework/types"
import { MedusaError } from "@medusajs/framework/utils"
import { NextFunction } from "express"
import {
AuthenticatedMedusaRequest,
refetchEntities,
refetchEntity,
} from "@medusajs/framework/http"
import { MedusaPricingContext } from "@medusajs/framework/types"
import { MedusaError } from "@medusajs/framework/utils"
import { NextFunction } from "express"
export function setPricingContext() {
return async (req: AuthenticatedMedusaRequest, _, next: NextFunction) => {
@@ -41,10 +41,10 @@ export function setPricingContext() {
}
// Find all the customer groups the customer is a part of and set
if (req.user?.customer_id) {
if (req.auth_context?.actor_id) {
const customerGroups = await refetchEntities(
"customer_group",
{ customer_id: req.user?.customer_id },
{ customers: { id: req.auth_context.actor_id } },
req.scope,
["id"]
)