fix(variants): inherit parent SKU/price by default and load variantAxes optionsList in catalog repository

This commit is contained in:
Inamul-hasan-tec
2026-08-20 11:16:05 +05:30
parent 202c5280ca
commit 70ce1b9efe
2 changed files with 14 additions and 5 deletions
@@ -25,9 +25,17 @@ export class CatalogRepository {
{
model: models.Attribute,
as: 'variantAxes',
attributes: ['id', 'code', 'name'],
attributes: ['id', 'code', 'name', 'type', 'options'],
through: { attributes: [] },
required: false
required: false,
include: [
{
model: models.AttributeOption,
as: 'optionsList',
attributes: ['id', 'code', 'label', 'sort_order'],
required: false
}
]
},
{
model: models.AssetFamily,
@@ -683,8 +683,9 @@ export class VariantService {
continue;
}
// Generate SKU
const generatedSku = this._buildSku(skuTemplate, parentProduct.code, combo);
// Generate SKU using parent product SKU or code as fallback
const parentSkuVal = parentProduct.sku || parentProduct.code || 'SKU';
const generatedSku = this._buildSku(skuTemplate, parentSkuVal, combo);
// Check SKU uniqueness
const existingSku = await models.Variant.findOne({
@@ -703,7 +704,7 @@ export class VariantService {
product_id: productId,
sku: finalSku,
name: variantName,
price: 0.00,
price: parseFloat(parentProduct.price) || 0.00,
cost_price: 0.00,
currency: 'USD',
stock: 0,