This commit is contained in:
seb
2026-10-01 17:40:04 +02:00
parent 62c3e69ed4
commit 84e547660e
53 changed files with 4604 additions and 2059 deletions

View File

@@ -44,7 +44,7 @@ export default function setByArticleSku(provider) {
`SELECT aav.attributevalue_id AS attributeValueId, an.name AS attributeName, av.value
FROM articleattributevalue aav
INNER JOIN attributevalue av ON av.id = aav.attributevalue_id
INNER JOIN attributename an ON an.id = av.attributename_id
INNER JOIN attributename an ON an.id = av.attribute_id
WHERE aav.article_id = @articleId
ORDER BY aav.sort ASC, aav.id ASC`,
{ articleId },
@@ -57,7 +57,36 @@ export default function setByArticleSku(provider) {
for (let i = 0; i < values.length; i++) {
const item = values[i];
const valId = typeof item === 'object' && item !== null ? Number(item.attributeValueId) : Number(item);
let rawId;
if (typeof item === 'object' && item !== null) {
rawId = item.attributeValueId ?? item.attributevalueId ?? item.attribute_value_id ?? item.valueId ?? item.id;
} else {
rawId = item;
}
let valId = Number(rawId);
if ((!Number.isInteger(valId) || valId <= 0) && typeof item === 'object' && item !== null && typeof item.value === 'string' && item.value.trim()) {
const valStr = item.value.trim();
let targetAttrId = item.attributeId != null ? Number(item.attributeId) : null;
if (!targetAttrId && (item.attributeName || item.name)) {
const attrName = String(item.attributeName || item.name).trim();
const nameRes = await runner.query(
'SELECT id FROM attributename WHERE company_id = @companyId AND name = @attrName',
{ companyId, attrName },
);
targetAttrId = nameRes.rows[0]?.id;
}
if (targetAttrId) {
const valRes = await runner.query(
'SELECT id FROM attributevalue WHERE attribute_id = @attributeId AND value = @value',
{ attributeId: targetAttrId, value: valStr },
);
if (valRes.rows[0]?.id) {
valId = valRes.rows[0].id;
}
}
}
if (!Number.isInteger(valId) || valId <= 0) {
throw new Error('Invalid attributeValueId');
}
@@ -80,8 +109,8 @@ export default function setByArticleSku(provider) {
exclusiveAttributesSeen.set(detail.attributeId, detail.attributeName);
}
const sort = typeof item === 'object' && item !== null && item.sort != null && Number.isInteger(item.sort)
? item.sort
const sort = typeof item === 'object' && item !== null && (item.sort != null || item.sort_order != null) && Number.isInteger(Number(item.sort ?? item.sort_order))
? Number(item.sort ?? item.sort_order)
: i;
validated.push({