127 lines
3.3 KiB
JavaScript
127 lines
3.3 KiB
JavaScript
export const ARTICLE_DETAIL_COLUMNS = `
|
|
a.id,
|
|
a.sku,
|
|
at.name,
|
|
at.slug,
|
|
a.unitamount,
|
|
a.weight,
|
|
u.si AS unitSi,
|
|
u.basesi AS unitBasesi,
|
|
u.basesifactor AS unitBasesifactor,
|
|
ut.symbol AS unitSymbol,
|
|
ut.name AS unitName,
|
|
b.id AS brandId,
|
|
b.name AS brandName,
|
|
brand_pic.hash AS brandFullHash,
|
|
brand_pic.thumbw AS brandThumbW,
|
|
brand_pic.thumbh AS brandThumbH,
|
|
brand_pic.thumbhash AS brandThumbHash,
|
|
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,
|
|
a.fatherarticle_id AS fatherArticleId,
|
|
father.sku AS fatherSku
|
|
`;
|
|
|
|
export const GET_DETAIL_BY_SKU = `
|
|
SELECT
|
|
${ARTICLE_DETAIL_COLUMNS}
|
|
FROM article a
|
|
LEFT JOIN articletext at
|
|
ON at.article_id = a.id AND at.language_id = @languageId
|
|
LEFT JOIN unit u ON u.id = a.unit_id
|
|
LEFT JOIN unittext ut
|
|
ON ut.unit_id = u.id AND ut.language_id = @languageId
|
|
LEFT JOIN brand b ON b.id = a.brand_id
|
|
OUTER APPLY (
|
|
SELECT TOP 1 bp.pic_id
|
|
FROM brandpic bp
|
|
WHERE bp.brand_id = b.id
|
|
ORDER BY bp.sort ASC, bp.id ASC
|
|
) first_brand_pic
|
|
LEFT JOIN pic brand_pic ON brand_pic.id = first_brand_pic.pic_id
|
|
LEFT JOIN article father ON father.id = a.fatherarticle_id
|
|
WHERE a.sku = @sku AND (@companyId IS NULL OR a.company_id = @companyId)
|
|
`;
|
|
|
|
export const GET_DETAIL_BY_ARTICLE_ID = `
|
|
SELECT
|
|
${ARTICLE_DETAIL_COLUMNS}
|
|
FROM article a
|
|
LEFT JOIN articletext at
|
|
ON at.article_id = a.id AND at.language_id = @languageId
|
|
LEFT JOIN unit u ON u.id = a.unit_id
|
|
LEFT JOIN unittext ut
|
|
ON ut.unit_id = u.id AND ut.language_id = @languageId
|
|
LEFT JOIN brand b ON b.id = a.brand_id
|
|
OUTER APPLY (
|
|
SELECT TOP 1 bp.pic_id
|
|
FROM brandpic bp
|
|
WHERE bp.brand_id = b.id
|
|
ORDER BY bp.sort ASC, bp.id ASC
|
|
) first_brand_pic
|
|
LEFT JOIN pic brand_pic ON brand_pic.id = first_brand_pic.pic_id
|
|
LEFT JOIN article father ON father.id = a.fatherarticle_id
|
|
WHERE a.id = @articleId
|
|
`;
|
|
|
|
export const GET_CATEGORY_IDS_BY_ARTICLE_ID = `
|
|
SELECT ca.category_id AS categoryId
|
|
FROM categoryarticle ca
|
|
WHERE ca.article_id = @articleId
|
|
ORDER BY ca.category_id
|
|
`;
|
|
|
|
export const GET_PHOTOS_BY_ARTICLE_ID = `
|
|
SELECT
|
|
ap.sort,
|
|
p.hash AS fullHash,
|
|
p.w AS fullW,
|
|
p.h AS fullH,
|
|
p.size AS fullSize,
|
|
p.thumbw AS thumbW,
|
|
p.thumbh AS thumbH,
|
|
p.thumbhash AS thumbHash
|
|
FROM articlepic ap
|
|
INNER JOIN pic p ON p.id = ap.pic_id
|
|
WHERE ap.article_id = @articleId
|
|
ORDER BY ap.sort ASC, ap.id ASC
|
|
`;
|
|
|
|
export const GET_EANS_BY_ARTICLE_ID = `
|
|
SELECT ae.ean
|
|
FROM articleean ae
|
|
WHERE ae.article_id = @articleId
|
|
ORDER BY ae.ean
|
|
`;
|
|
|
|
export const GET_PRICES_BY_ARTICLE_ID = `
|
|
SELECT
|
|
pr.minmultiplier AS minmultiplier,
|
|
pr.net,
|
|
t.rate AS taxRate,
|
|
pr.customergroup_id AS customergroupId
|
|
FROM price pr
|
|
INNER JOIN tax t ON t.id = pr.tax_id
|
|
WHERE pr.article_id = @articleId
|
|
ORDER BY pr.customergroup_id, pr.minmultiplier
|
|
`;
|