在Prestashop中导出具有属性的产品库存

时间:2015-07-29 03:21:01

标签: mysql prestashop

在我的商店中,产品A具有不同的属性,让它们成为:
白色(左12个),黑色(左10个)和红色(左6个)
我已设法将所有产品的类别,数量和属性导出到csv,但我希望该表格如下:
产品A /白色/ 12
产品A /黑色/ 10
产品A /红/ 6
产品B /尺寸S / 5
产品B /尺寸M / 6

因此,每种产品组合的所有可用数量。 我现在的查询如下:



SELECT 
    p.id_product,
    p.id_category_default,
    GROUP_CONCAT(DISTINCT(cl.name) SEPARATOR ";") as categories,
    pa.reference,
    pl.name, 
    GROUP_CONCAT(DISTINCT(pal.name) SEPARATOR "; ") as combination, 
    p.price, 
    pq.quantity
FROM 7_ps_product p 
LEFT JOIN 7_ps_product_attribute pa ON (p.id_product = pa.id_product) 
LEFT JOIN 7_ps_stock_available pq ON (p.id_product = pq.id_product AND pa.id_product_attribute = pq.id_product_attribute) 
LEFT JOIN 7_ps_product_lang pl ON (p.id_product = pl.id_product) 
LEFT JOIN 7_ps_product_attribute_combination pac ON (pa.id_product_attribute = pac.id_product_attribute)
LEFT JOIN 7_ps_attribute_lang pal ON (pac.id_attribute = pal.id_attribute)
LEFT JOIN 7_ps_category_product cp ON (p.id_product = cp.id_product)
LEFT JOIN 7_ps_category_lang cl ON (cp.id_category = cl.id_category)
LEFT JOIN 7_ps_category c ON (cp.id_category = c.id_category)
WHERE pl.id_lang = 1 
AND pal.id_lang = 1 
GROUP BY pa.reference
ORDER BY p.id_product, pac.id_attribute




感谢帮助像我这样的人做出的巨大贡献!!

1 个答案:

答案 0 :(得分:1)

我已经改变了你的查询,所以要获得你需要的输出

SELECT 
   CONCAT(pl.name,' / ',pal.name,' / ', pq.quantity) AS required
FROM ps_product p 
LEFT JOIN ps_product_attribute pa ON (p.id_product = pa.id_product) 
LEFT JOIN ps_stock_available pq ON (p.id_product = pq.id_product AND pa.id_product_attribute = pq.id_product_attribute) 
LEFT JOIN ps_product_lang pl ON (p.id_product = pl.id_product) 
LEFT JOIN ps_product_attribute_combination pac ON (pa.id_product_attribute = pac.id_product_attribute)
LEFT JOIN ps_attribute_lang pal ON (pac.id_attribute = pal.id_attribute)
LEFT JOIN ps_category_product cp ON (p.id_product = cp.id_product)
LEFT JOIN ps_category_lang cl ON (cp.id_category = cl.id_category)
LEFT JOIN ps_category c ON (cp.id_category = c.id_category)
WHERE pl.id_lang = 1 
      AND pal.id_lang = 1 
GROUP BY p.id_product,pal.name
ORDER BY p.id_product, pac.id_attribute

我更改了GROUP BY和SELECT字段。我认为这是你需要的答案。