This commit is contained in:
seb
2026-10-04 21:22:05 +02:00
parent 0268583ae3
commit 4718cb5726
48 changed files with 758 additions and 758 deletions

View File

@@ -123,39 +123,39 @@ export default function setByArticleSku(provider) {
});
}
// Check father / child constraints
// Check parent / child constraints
const artRes = await runner.query(
'SELECT id, is_father, fatherarticle_id, fatherattributename_id FROM article WHERE id = @articleId',
'SELECT id, is_parent, parentarticle_id, parentattributename_id FROM article WHERE id = @articleId',
{ articleId },
);
const article = artRes.rows[0];
if (article?.is_father && article.fatherattributename_id) {
const hasFatherAttr = validated.some((v) => v.attributeId === article.fatherattributename_id);
if (hasFatherAttr) {
throw new Error('A father article cannot have attribute values for its variant attribute');
if (article?.is_parent && article.parentattributename_id) {
const hasParentAttr = validated.some((v) => v.attributeId === article.parentattributename_id);
if (hasParentAttr) {
throw new Error('A parent article cannot have attribute values for its variant attribute');
}
}
if (article?.fatherarticle_id != null) {
let currentFatherId = article.fatherarticle_id;
if (article?.parentarticle_id != null) {
let currentParentId = article.parentarticle_id;
const visited = new Set();
while (currentFatherId != null && !visited.has(currentFatherId)) {
visited.add(currentFatherId);
const fatherRes = await runner.query(
'SELECT a.fatherarticle_id, a.fatherattributename_id, an.name AS fatherAttributeName FROM article a LEFT JOIN attributename an ON an.id = a.fatherattributename_id WHERE a.id = @currentFatherId',
{ currentFatherId },
while (currentParentId != null && !visited.has(currentParentId)) {
visited.add(currentParentId);
const parentRes = await runner.query(
'SELECT a.parentarticle_id, a.parentattributename_id, an.name AS parentAttributeName FROM article a LEFT JOIN attributename an ON an.id = a.parentattributename_id WHERE a.id = @currentParentId',
{ currentParentId },
);
const fRow = fatherRes.rows[0];
const fRow = parentRes.rows[0];
if (!fRow) break;
if (fRow.fatherattributename_id != null) {
const hasFatherAttr = validated.some((v) => v.attributeId === fRow.fatherattributename_id);
if (!hasFatherAttr) {
const fatherAttrName = fRow.fatherAttributeName || 'ancestor variant attribute';
throw new Error(`Child article must have an attribute value for the father attribute "${fatherAttrName}"`);
if (fRow.parentattributename_id != null) {
const hasParentAttr = validated.some((v) => v.attributeId === fRow.parentattributename_id);
if (!hasParentAttr) {
const parentAttrName = fRow.parentAttributeName || 'ancestor variant attribute';
throw new Error(`Child article must have an attribute value for the parent attribute "${parentAttrName}"`);
}
}
currentFatherId = fRow.fatherarticle_id;
currentParentId = fRow.parentarticle_id;
}
}