This commit is contained in:
seb
2026-09-29 18:26:42 +02:00
parent 30820ba8c7
commit 69bd0935cc
14 changed files with 710 additions and 20 deletions

View File

@@ -102,6 +102,50 @@ SET is_father = 1
WHERE id = @articleId
`;
export const TOGGLE_FATHER = `
UPDATE article
SET is_father = @isFather,
fatherattributename_id = @fatherAttributeNameId
WHERE id = @articleId
`;
export const CREATE_CHILD = `
INSERT INTO article (
company_id, sku, unit_id, unitamount, weight, track_stock, brand_id, is_father, fatherarticle_id, fathersort
)
OUTPUT INSERTED.id
VALUES (
@companyId, @sku, @unitId, @unitamount, @weight, @trackStock, @brandId, 0, @fatherArticleId, @fathersort
)
`;
export const UNLINK_CHILD = `
UPDATE article
SET fatherarticle_id = NULL,
fathersort = 0
WHERE id = @articleId AND fatherarticle_id = @fatherArticleId
`;
export const LIST_CHILDREN_BY_FATHER_ID = `
SELECT
child.id,
child.sku,
child.fathersort,
child.track_stock AS trackStock,
child.unitamount,
child.weight,
at_child.name,
at_child.slug,
av.id AS attributeValueId,
av.value AS attributeValue
FROM article child
LEFT JOIN articletext at_child ON at_child.article_id = child.id AND at_child.language_id = @languageId
LEFT JOIN articleattributevalue aav ON aav.article_id = child.id
LEFT JOIN attributevalue av ON av.id = aav.attributevalue_id AND av.attribute_id = @attributeId
WHERE child.fatherarticle_id = @fatherArticleId
ORDER BY child.fathersort ASC, child.id ASC
`;
export const SET_FATHER_SORT = `
UPDATE article
SET fathersort = @fathersort
@@ -406,8 +450,28 @@ SELECT
FROM article child
WHERE child.fatherarticle_id = a.id
) AS childCount,
a.is_father AS isFather,
a.fatherattributename_id AS fatherAttributeNameId,
fan.name AS fatherAttributeName,
fan.exclusive AS fatherAttributeExclusive,
a.fatherarticle_id AS fatherArticleId,
fa.sku AS fatherSku,
(
SELECT
child.id,
child.sku,
child.fathersort,
at_child.name,
av.id AS attributeValueId,
av.value AS attributeValue
FROM article child
LEFT JOIN articletext at_child ON at_child.article_id = child.id AND at_child.language_id = auth.languageId
LEFT JOIN articleattributevalue aav ON aav.article_id = child.id
LEFT JOIN attributevalue av ON av.id = aav.attributevalue_id AND av.attribute_id = a.fatherattributename_id
WHERE child.fatherarticle_id = a.id
ORDER BY child.fathersort ASC, child.id ASC
FOR JSON PATH
) AS childrenJson,
(
SELECT ca2.category_id
FROM categoryarticle ca2
@@ -510,6 +574,7 @@ SELECT
) first_brand_pic
LEFT JOIN pic bp ON bp.id = first_brand_pic.pic_id
LEFT JOIN article fa ON fa.id = a.fatherarticle_id
LEFT JOIN attributename fan ON fan.id = a.fatherattributename_id
WHERE a.id = auth.articleId
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER
) AS articleJson