fix(variants): inherit parent SKU/price by default and load variantAxes optionsList in catalog repository
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user