fix(product): options validation if ids are same (#9622)
**What** - fix validation of existing variant with options on update if the ids are same --- FIXES CC-60 CLOSES https://github.com/medusajs/medusa/issues/9620
This commit is contained in:
@@ -380,10 +380,12 @@ export default class ProductModuleService
|
||||
productOptions
|
||||
)
|
||||
|
||||
ProductModuleService.checkIfVariantWithOptionsAlreadyExists(
|
||||
productVariantsWithOptions as any,
|
||||
allVariants
|
||||
)
|
||||
if (data.some((d) => !!d.options)) {
|
||||
ProductModuleService.checkIfVariantWithOptionsAlreadyExists(
|
||||
productVariantsWithOptions as any,
|
||||
allVariants
|
||||
)
|
||||
}
|
||||
|
||||
const { entities: productVariants, performedActions } =
|
||||
await this.productVariantService_.upsertWithReplace(
|
||||
@@ -1819,7 +1821,7 @@ export default class ProductModuleService
|
||||
protected static checkIfVariantWithOptionsAlreadyExists(
|
||||
data: ((
|
||||
| ProductTypes.CreateProductVariantDTO
|
||||
| ProductTypes.UpdateProductVariantDTO
|
||||
| UpdateProductVariantInput
|
||||
) & { options: { id: string }[]; product_id: string })[],
|
||||
variants: ProductVariant[]
|
||||
) {
|
||||
@@ -1832,6 +1834,10 @@ export default class ProductModuleService
|
||||
return false
|
||||
}
|
||||
|
||||
if ((variantData as UpdateProductVariantInput)?.id === v.id) {
|
||||
return false
|
||||
}
|
||||
|
||||
return (variantData.options as unknown as { id: string }[])!.every(
|
||||
(optionValue) => {
|
||||
const variantOptionValue = v.options.find(
|
||||
|
||||
Reference in New Issue
Block a user