71 lines
1.7 KiB
JavaScript
71 lines
1.7 KiB
JavaScript
export const ARTICLE_LIST_JOINS = `
|
|
LEFT JOIN articletext at
|
|
ON at.article_id = a.id AND at.language_id = @languageId
|
|
LEFT JOIN price pr
|
|
ON pr.article_id = a.id
|
|
AND pr.customergroup_id = @posCustomerGroupId
|
|
AND pr.minmultiplier = 1
|
|
LEFT JOIN tax t ON t.id = pr.tax_id
|
|
OUTER APPLY (
|
|
SELECT TOP 1 ap.pic_id
|
|
FROM articlepic ap
|
|
WHERE ap.article_id = a.id
|
|
ORDER BY ap.sort ASC, ap.id ASC
|
|
) first_pic
|
|
LEFT JOIN pic ON pic.id = first_pic.pic_id
|
|
`;
|
|
|
|
export const ARTICLE_LIST_COLUMNS = `
|
|
a.id,
|
|
a.sku,
|
|
at.name,
|
|
at.slug,
|
|
pr.net,
|
|
t.rate AS taxRate,
|
|
CASE
|
|
WHEN a.optionslist_id IS NOT NULL THEN (
|
|
SELECT COUNT(*)
|
|
FROM optionslistarticle ola
|
|
WHERE ola.optionslist_id = a.optionslist_id
|
|
)
|
|
ELSE 0
|
|
END AS optionsCount,
|
|
CASE
|
|
WHEN a.articlelist_id IS NOT NULL THEN (
|
|
SELECT COUNT(*)
|
|
FROM articlelistarticle ala
|
|
WHERE ala.articlelist_id = a.articlelist_id
|
|
)
|
|
ELSE 0
|
|
END AS articleListCount,
|
|
(
|
|
SELECT COUNT(*)
|
|
FROM article child
|
|
WHERE child.fatherarticle_id = a.id
|
|
) AS childCount,
|
|
pic.thumbw AS thumbW,
|
|
pic.thumbh AS thumbH,
|
|
pic.thumbhash AS thumbHash
|
|
`;
|
|
|
|
export const GET_CATEGORY_ID_BY_SKU = `
|
|
SELECT TOP 1 ca.category_id AS categoryId
|
|
FROM article a
|
|
INNER JOIN categoryarticle ca ON ca.article_id = a.id
|
|
WHERE a.sku = @sku
|
|
`;
|
|
|
|
export const GET_BY_SKU = `
|
|
SELECT
|
|
${ARTICLE_LIST_COLUMNS}
|
|
FROM article a
|
|
${ARTICLE_LIST_JOINS}
|
|
WHERE a.sku = @sku
|
|
`;
|
|
|
|
export const CREATE = `
|
|
INSERT INTO article (sku, unit_id, unitamount, weight)
|
|
OUTPUT INSERTED.id
|
|
VALUES (@sku, @unitId, @unitamount, @weight)
|
|
`;
|