Prestashop 订购产品 sql
Prestashop order products sql
我在哪里可以找到 Prestashop SQL 查询他们显示按顺序购买的产品的位置。
像这样:
我正在创建一个显示 table 中 100 个订单的自定义页面。如果点击订单,它会显示已订购的产品。我做了一个 sql 查询:
SELECT product_id, product_reference AS kood,product_name AS nimetus,product_quantity AS nr, pl.link_rewrite,psa.quantity as kogukogus,group_concat(ps.product_supplier_reference) as supp_ref, p.location AS asukoht,
CONCAT(c.link_rewrite,'/',p.id_product,'-',pl.link_rewrite,'.html') link
FROM ps_order_detail o
LEFT JOIN ps_product_lang pl on o.product_id = pl.id_product
LEFT JOIN ps_product p on p.id_product = pl.id_product
LEFT JOIN ps_stock_available psa on p.id_product = psa.id_product
LEFT JOIN ps_category_lang c on c.id_category = p.id_category_default
LEFT JOIN ps_product_supplier ps on p.id_product = ps.id_product
WHERE pl.id_lang=2 AND c.id_lang=2 AND id_order= '".$q."'
GROUP BY product_id, kood,nimetus,nr,pl.link_rewrite, kogukogus,asukoht, link
但是当产品有属性时它会复制产品。
在本例中,iButton 有黑色和红色两种颜色(属性)。这个订单只买了一个黑色的iButton,数量是20个,但是显示三排。
我试图解决这个问题,但是我的 sql 查询出现了另一个问题,即当它没有属性时它不会显示任何内容。
SELECT product_id, product_reference AS kood,product_name AS nimetus,product_quantity AS nr, pl.link_rewrite,psa.quantity as kogukogus,group_concat(ps.product_supplier_reference) as supp_ref, p.location AS asukoht,
CONCAT(c.link_rewrite,'/',p.id_product,'-',pl.link_rewrite,'.html') link
FROM ps_order_detail o
JOIN ps_product_lang pl on o.product_id = pl.id_product
JOIN ps_product p on p.id_product = pl.id_product
JOIN ps_stock_available psa on p.id_product = psa.id_product
JOIN ps_category_lang c on c.id_category = p.id_category_default
JOIN ps_product_supplier ps on p.id_product = ps.id_product
LEFT JOIN ps_product_attribute pa on p.id_product=pa.id_product
WHERE pl.id_lang=2 AND pa.id_product_attribute = psa.id_product_attribute AND pa.id_product_attribute =o.product_attribute_id AND c.id_lang=2 AND id_order= '".$q."'
GROUP BY product_id, kood,nimetus,nr,pl.link_rewrite, kogukogus,asukoht, link
我该如何解决这个问题?
如果您对结果的特定产品属性不感兴趣,请在查询中使用 SELECT DISTINCT 而不是简单 SELECT
我认为您必须将 2 个 WHERE
条件移动到 JOIN
条件。可能只移动 LEFT JOIN
上的条件就足够了。
这应该是结果:
SELECT DISTINCT product_id, product_reference AS kood,product_name AS nimetus,product_quantity AS nr, pl.link_rewrite,psa.quantity as kogukogus,group_concat(ps.product_supplier_reference) as supp_ref, p.location AS asukoht,
CONCAT(c.link_rewrite,'/',p.id_product,'-',pl.link_rewrite,'.html') link
FROM ps_order_detail o
JOIN ps_product_lang pl on o.product_id = pl.id_product
JOIN ps_product p on p.id_product = pl.id_product
JOIN ps_stock_available psa on p.id_product = psa.id_product
JOIN ps_category_lang c on c.id_category = p.id_category_default
JOIN ps_product_supplier ps on p.id_product = ps.id_product
LEFT JOIN ps_product_attribute pa on p.id_product=pa.id_product
AND psa.id_product_attribute = pa.id_product_attribute
WHERE pl.id_lang=2 AND c.id_lang=2 AND id_order= '".$q."'
感谢您的回答,这确实很愚蠢,但是当从分组依据中删除 kogukogus 时,结果如下:
SELECT product_id, product_reference AS kood,product_name AS nimetus,product_quantity AS nr, pl.link_rewrite,psa.quantity as kogukogus,group_concat(ps.product_supplier_reference) as supp_ref, p.location AS asukoht,
CONCAT(c.link_rewrite,'/',p.id_product,'-',pl.link_rewrite,'.html') link
FROM ps_order_detail o
LEFT JOIN ps_product_lang pl on o.product_id = pl.id_product
LEFT JOIN ps_product p on p.id_product = pl.id_product
LEFT JOIN ps_stock_available psa on p.id_product = psa.id_product
LEFT JOIN ps_category_lang c on c.id_category = p.id_category_default
LEFT JOIN ps_product_supplier ps on p.id_product = ps.id_product
WHERE pl.id_lang=2 AND c.id_lang=2 AND id_order= '".$q."'
GROUP BY product_id, kood,nimetus,nr,pl.link_rewrite,asukoht, link
我以某种方式让它工作了。谢谢@kiks73,您的代码不起作用,但是当我尝试将 group by 添加到您的代码时,我意识到问题出在 group by 上。所以赏金给了你,因为没有人回答任何严肃的问题
我在哪里可以找到 Prestashop SQL 查询他们显示按顺序购买的产品的位置。
像这样:
我正在创建一个显示 table 中 100 个订单的自定义页面。如果点击订单,它会显示已订购的产品。我做了一个 sql 查询:
SELECT product_id, product_reference AS kood,product_name AS nimetus,product_quantity AS nr, pl.link_rewrite,psa.quantity as kogukogus,group_concat(ps.product_supplier_reference) as supp_ref, p.location AS asukoht,
CONCAT(c.link_rewrite,'/',p.id_product,'-',pl.link_rewrite,'.html') link
FROM ps_order_detail o
LEFT JOIN ps_product_lang pl on o.product_id = pl.id_product
LEFT JOIN ps_product p on p.id_product = pl.id_product
LEFT JOIN ps_stock_available psa on p.id_product = psa.id_product
LEFT JOIN ps_category_lang c on c.id_category = p.id_category_default
LEFT JOIN ps_product_supplier ps on p.id_product = ps.id_product
WHERE pl.id_lang=2 AND c.id_lang=2 AND id_order= '".$q."'
GROUP BY product_id, kood,nimetus,nr,pl.link_rewrite, kogukogus,asukoht, link
但是当产品有属性时它会复制产品。
在本例中,iButton 有黑色和红色两种颜色(属性)。这个订单只买了一个黑色的iButton,数量是20个,但是显示三排。
我试图解决这个问题,但是我的 sql 查询出现了另一个问题,即当它没有属性时它不会显示任何内容。
SELECT product_id, product_reference AS kood,product_name AS nimetus,product_quantity AS nr, pl.link_rewrite,psa.quantity as kogukogus,group_concat(ps.product_supplier_reference) as supp_ref, p.location AS asukoht,
CONCAT(c.link_rewrite,'/',p.id_product,'-',pl.link_rewrite,'.html') link
FROM ps_order_detail o
JOIN ps_product_lang pl on o.product_id = pl.id_product
JOIN ps_product p on p.id_product = pl.id_product
JOIN ps_stock_available psa on p.id_product = psa.id_product
JOIN ps_category_lang c on c.id_category = p.id_category_default
JOIN ps_product_supplier ps on p.id_product = ps.id_product
LEFT JOIN ps_product_attribute pa on p.id_product=pa.id_product
WHERE pl.id_lang=2 AND pa.id_product_attribute = psa.id_product_attribute AND pa.id_product_attribute =o.product_attribute_id AND c.id_lang=2 AND id_order= '".$q."'
GROUP BY product_id, kood,nimetus,nr,pl.link_rewrite, kogukogus,asukoht, link
我该如何解决这个问题?
如果您对结果的特定产品属性不感兴趣,请在查询中使用 SELECT DISTINCT 而不是简单 SELECT
我认为您必须将 2 个 WHERE
条件移动到 JOIN
条件。可能只移动 LEFT JOIN
上的条件就足够了。
这应该是结果:
SELECT DISTINCT product_id, product_reference AS kood,product_name AS nimetus,product_quantity AS nr, pl.link_rewrite,psa.quantity as kogukogus,group_concat(ps.product_supplier_reference) as supp_ref, p.location AS asukoht,
CONCAT(c.link_rewrite,'/',p.id_product,'-',pl.link_rewrite,'.html') link
FROM ps_order_detail o
JOIN ps_product_lang pl on o.product_id = pl.id_product
JOIN ps_product p on p.id_product = pl.id_product
JOIN ps_stock_available psa on p.id_product = psa.id_product
JOIN ps_category_lang c on c.id_category = p.id_category_default
JOIN ps_product_supplier ps on p.id_product = ps.id_product
LEFT JOIN ps_product_attribute pa on p.id_product=pa.id_product
AND psa.id_product_attribute = pa.id_product_attribute
WHERE pl.id_lang=2 AND c.id_lang=2 AND id_order= '".$q."'
感谢您的回答,这确实很愚蠢,但是当从分组依据中删除 kogukogus 时,结果如下:
SELECT product_id, product_reference AS kood,product_name AS nimetus,product_quantity AS nr, pl.link_rewrite,psa.quantity as kogukogus,group_concat(ps.product_supplier_reference) as supp_ref, p.location AS asukoht,
CONCAT(c.link_rewrite,'/',p.id_product,'-',pl.link_rewrite,'.html') link
FROM ps_order_detail o
LEFT JOIN ps_product_lang pl on o.product_id = pl.id_product
LEFT JOIN ps_product p on p.id_product = pl.id_product
LEFT JOIN ps_stock_available psa on p.id_product = psa.id_product
LEFT JOIN ps_category_lang c on c.id_category = p.id_category_default
LEFT JOIN ps_product_supplier ps on p.id_product = ps.id_product
WHERE pl.id_lang=2 AND c.id_lang=2 AND id_order= '".$q."'
GROUP BY product_id, kood,nimetus,nr,pl.link_rewrite,asukoht, link
我以某种方式让它工作了。谢谢@kiks73,您的代码不起作用,但是当我尝试将 group by 添加到您的代码时,我意识到问题出在 group by 上。所以赏金给了你,因为没有人回答任何严肃的问题