feat(medusa): Get product with isolated product module (#5010)
This commit is contained in:
1 parent
4fa675ec25
commit
05a32683a3
2 files changed
+136
-2
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat(medusa): Get product with isolated product module
|
||||||
@@ -8,7 +8,9 @@ import {
|
|||||||
import { IsOptional, IsString } from "class-validator"
|
import { IsOptional, IsString } from "class-validator"
|
||||||
|
|
||||||
import { PriceSelectionParams } from "../../../../types/price-selection"
|
import { PriceSelectionParams } from "../../../../types/price-selection"
|
||||||
import { cleanResponseData } from "../../../../utils/clean-response-data"
|
import { cleanResponseData } from "../../../../utils"
|
||||||
|
import IsolateProductDomain from "../../../../loaders/feature-flags/isolate-product-domain"
|
||||||
|
import { defaultStoreProductsFields } from "./index"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @oas [get] /store/products/{id}
|
* @oas [get] /store/products/{id}
|
||||||
@@ -90,7 +92,14 @@ export default async (req, res) => {
|
|||||||
const pricingService: PricingService = req.scope.resolve("pricingService")
|
const pricingService: PricingService = req.scope.resolve("pricingService")
|
||||||
const cartService: CartService = req.scope.resolve("cartService")
|
const cartService: CartService = req.scope.resolve("cartService")
|
||||||
const regionService: RegionService = req.scope.resolve("regionService")
|
const regionService: RegionService = req.scope.resolve("regionService")
|
||||||
const rawProduct = await productService.retrieve(id, req.retrieveConfig)
|
const featureFlagRouter = req.scope.resolve("featureFlagRouter")
|
||||||
|
|
||||||
|
let rawProduct
|
||||||
|
if (featureFlagRouter.isFeatureEnabled(IsolateProductDomain.key)) {
|
||||||
|
rawProduct = await getProductWithIsolatedProductModule(req, id)
|
||||||
|
} else {
|
||||||
|
rawProduct = await productService.retrieve(id, req.retrieveConfig)
|
||||||
|
}
|
||||||
|
|
||||||
let sales_channel_id = validated.sales_channel_id
|
let sales_channel_id = validated.sales_channel_id
|
||||||
if (req.publishableApiKeyScopes?.sales_channel_ids.length === 1) {
|
if (req.publishableApiKeyScopes?.sales_channel_ids.length === 1) {
|
||||||
@@ -153,6 +162,126 @@ export default async (req, res) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getProductWithIsolatedProductModule(req, id: string) {
|
||||||
|
const remoteQuery = req.scope.resolve("remoteQuery")
|
||||||
|
|
||||||
|
const variables = { id }
|
||||||
|
const commonProperties = []
|
||||||
|
|
||||||
|
const query = `
|
||||||
|
query ($id: String!) {
|
||||||
|
product (id: $id) {
|
||||||
|
${defaultStoreProductsFields.join("\n")}
|
||||||
|
|
||||||
|
images {
|
||||||
|
id
|
||||||
|
created_at
|
||||||
|
updated_at
|
||||||
|
deleted_at
|
||||||
|
url
|
||||||
|
metadata
|
||||||
|
}
|
||||||
|
|
||||||
|
tags {
|
||||||
|
id
|
||||||
|
created_at
|
||||||
|
updated_at
|
||||||
|
deleted_at
|
||||||
|
value
|
||||||
|
}
|
||||||
|
|
||||||
|
type {
|
||||||
|
id
|
||||||
|
created_at
|
||||||
|
updated_at
|
||||||
|
deleted_at
|
||||||
|
value
|
||||||
|
}
|
||||||
|
|
||||||
|
collection {
|
||||||
|
title
|
||||||
|
handle
|
||||||
|
id
|
||||||
|
created_at
|
||||||
|
updated_at
|
||||||
|
deleted_at
|
||||||
|
}
|
||||||
|
|
||||||
|
options {
|
||||||
|
id
|
||||||
|
created_at
|
||||||
|
updated_at
|
||||||
|
deleted_at
|
||||||
|
title
|
||||||
|
product_id
|
||||||
|
metadata
|
||||||
|
values {
|
||||||
|
id
|
||||||
|
created_at
|
||||||
|
updated_at
|
||||||
|
deleted_at
|
||||||
|
value
|
||||||
|
option_id
|
||||||
|
variant_id
|
||||||
|
metadata
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
variants {
|
||||||
|
id
|
||||||
|
created_at
|
||||||
|
updated_at
|
||||||
|
deleted_at
|
||||||
|
title
|
||||||
|
product_id
|
||||||
|
sku
|
||||||
|
barcode
|
||||||
|
ean
|
||||||
|
upc
|
||||||
|
variant_rank
|
||||||
|
inventory_quantity
|
||||||
|
allow_backorder
|
||||||
|
manage_inventory
|
||||||
|
hs_code
|
||||||
|
origin_country
|
||||||
|
mid_code
|
||||||
|
material
|
||||||
|
weight
|
||||||
|
length
|
||||||
|
height
|
||||||
|
width
|
||||||
|
metadata
|
||||||
|
options {
|
||||||
|
id
|
||||||
|
created_at
|
||||||
|
updated_at
|
||||||
|
deleted_at
|
||||||
|
value
|
||||||
|
option_id
|
||||||
|
variant_id
|
||||||
|
metadata
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
profile {
|
||||||
|
id
|
||||||
|
created_at
|
||||||
|
updated_at
|
||||||
|
deleted_at
|
||||||
|
name
|
||||||
|
type
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
const [product] = await remoteQuery(query, variables)
|
||||||
|
|
||||||
|
product.profile_id = product.profile?.id
|
||||||
|
|
||||||
|
return product
|
||||||
|
}
|
||||||
|
|
||||||
export class StoreGetProductsProductParams extends PriceSelectionParams {
|
export class StoreGetProductsProductParams extends PriceSelectionParams {
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
|||||||
Reference in new issue
Block a user