hotfix(medusa): Temporary multi-warehouse support for draft orders (#3665)

* remove reservations from draft order creation and show correct inventory

* add changeset

* add integration tests

* adjust inventory on payment if no inventory service is installed
This commit is contained in:
Philip Korsholm authored and GitHub committed 2023-04-04 11:36:51 +02:00
1 parent bb9df09e37
commit 748833383f
6 files changed
+340 -15

No files matched your search

@@ -5,14 +5,14 @@ import {
PaymentProviderService,
ProductVariantInventoryService,
} from "../../../../services"
import { MedusaError } from "medusa-core-utils"
import { EntityManager } from "typeorm"
import { Order } from "../../../../models"
import {
defaultAdminOrdersFields as defaultOrderFields,
defaultAdminOrdersRelations as defaultOrderRelations,
} from "../../../../types/orders"
import { EntityManager } from "typeorm"
import { MedusaError } from "medusa-core-utils"
import { Order } from "../../../../models"
import { cleanResponseData } from "../../../../utils/clean-response-data"
/**
@@ -76,6 +76,7 @@ export default async (req, res) => {
"paymentProviderService"
)
const orderService: OrderService = req.scope.resolve("orderService")
const inventoryService: OrderService = req.scope.resolve("inventoryService")
const cartService: CartService = req.scope.resolve("cartService")
const productVariantInventoryService: ProductVariantInventoryService =
req.scope.resolve("productVariantInventoryService")
@@ -113,9 +114,12 @@ export default async (req, res) => {
select: defaultOrderFields,
})
await reserveQuantityForDraftOrder(order, {
productVariantInventoryService,
})
// TODO: Re-enable when we have a way to handle inventory for draft orders on creation
if (!inventoryService) {
await reserveQuantityForDraftOrder(order, {
productVariantInventoryService,
})
}
return order
})
@@ -1,16 +1,20 @@
import { IsInt, IsOptional, IsString } from "class-validator"
import { Type } from "class-transformer"
import { omit } from "lodash"
import {
CartService,
PricingService,
ProductVariantInventoryService,
RegionService,
SalesChannelService,
} from "../../../../services"
import ProductVariantService from "../../../../services/product-variant"
import { NumericalComparisonOperator } from "../../../../types/common"
import { IsInt, IsOptional, IsString } from "class-validator"
import { AdminPriceSelectionParams } from "../../../../types/price-selection"
import { IInventoryService } from "@medusajs/types"
import { IsType } from "../../../../utils/validators/is-type"
import { NumericalComparisonOperator } from "../../../../types/common"
import { PricedVariant } from "../../../../types/pricing"
import ProductVariantService from "../../../../services/product-variant"
import { Type } from "class-transformer"
import { omit } from "lodash"
/**
* @oas [get] /admin/variants
@@ -143,7 +147,7 @@ export default async (req, res) => {
currencyCode = region.currency_code
}
const variants = await pricingService.setVariantPrices(rawVariants, {
let variants = await pricingService.setVariantPrices(rawVariants, {
cart_id: req.validatedQuery.cart_id,
region_id: regionId,
currency_code: currencyCode,
@@ -152,6 +156,27 @@ export default async (req, res) => {
ignore_cache: true,
})
const inventoryService: IInventoryService | undefined =
req.scope.resolve("inventoryService")
const salesChannelService: SalesChannelService = req.scope.resolve(
"salesChannelService"
)
const productVariantInventoryService: ProductVariantInventoryService =
req.scope.resolve("productVariantInventoryService")
if (inventoryService) {
const [salesChannelsIds] = await salesChannelService.listAndCount(
{},
{ select: ["id"] }
)
variants = (await productVariantInventoryService.setVariantAvailability(
variants,
salesChannelsIds.map((salesChannel) => salesChannel.id)
)) as PricedVariant[]
}
res.json({
variants,
count,