Magento报告客户愿望清单

时间:2015-01-19 07:53:24

标签: mysql sql magento

我正在尝试报告客户心愿单中的内容,我已经通过此查询并需要更多帮助:

   SELECT b.email, c.value AS name, a.updated_at, d.added_at, d.product_id, e.name, SUM(g.qty_ordered) AS purchased
FROM `wishlist` AS a
INNER JOIN customer_entity AS b ON a.customer_id = b.entity_id
INNER JOIN customer_entity_varchar AS c ON a.customer_id = c.entity_id AND c.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'firstname' AND entity_type_id = b.entity_type_id)
INNER JOIN wishlist_item AS d ON a.wishlist_id = d.wishlist_id
INNER JOIN catalog_product_flat_1 AS e ON d.product_id = e.entity_id
LEFT JOIN sales_flat_order AS f ON f.customer_email = b.email
LEFT JOIN sales_flat_order_item AS g ON (f.entity_id = g.order_id AND g.sku LIKE CONCAT(e.sku,'%') AND g.product_type = 'simple')
GROUP BY b.email, c.value, a.updated_at, d.added_at, d.product_id, e.name

我试图从某事开始,所以我在phpmyadmin中执行此查询,但我没有得到任何结果。 有人可以至少在一开始就指出如何在模板文件中获取此集合或至少看到第一个结果并开始了解它是如何工作的 我明白我应该制作一个管理模块并在Mage_Adminhtml_Block_Widget_Grid

中过滤报告

编辑:此查询将起作用,问题是catalog_product_flat_1在我现在工作的Magento中是空的,我已经在管理员中启用了产品平台表,现在还可以。
与这个模块一起,可以非常轻松地完成https://github.com/kalenjordan/custom-reports工作,以满足任何其他人的兴趣 现在我有另一个问题,实际上这就是我需要做的事情:
如何使用确切的查询过滤指定产品?例如,检查产品SKU(或product_id或名称等)并过滤其愿望清单中仅包含此产品的客户的结果。
现在它将显示每个独特客户在wishlist(巨大查询)中的所有产品

1 个答案:

答案 0 :(得分:0)

找到答案:) 最终查询包括针对特定产品(没有扁平产品数据):

SELECT b.email, c.value AS firstname, a.updated_at, d.added_at, d.product_id, e.sku, SUM( g.qty_ordered ) AS purchased
FROM  `wishlist` AS a
INNER JOIN customer_entity AS b ON a.customer_id = b.entity_id
INNER JOIN customer_entity_varchar AS c ON a.customer_id = c.entity_id
AND c.attribute_id = ( 
SELECT attribute_id
FROM eav_attribute
WHERE attribute_code =  'firstname'
AND entity_type_id = b.entity_type_id ) 
INNER JOIN wishlist_item AS d ON a.wishlist_id = d.wishlist_id
INNER JOIN catalog_product_entity AS e ON d.product_id = e.entity_id
LEFT JOIN sales_flat_order AS f ON f.customer_email = b.email
LEFT JOIN sales_flat_order_item AS g ON ( f.entity_id = g.order_id
AND g.sku LIKE CONCAT( e.sku,  '%' ) 
AND g.product_type =  'simple' ) 
WHERE e.sku =  'api_75019'
GROUP BY b.email, c.value, a.updated_at, d.added_at, d.product_id, e.sku

这对于启用平面数据:

SELECT b.email, c.value AS firstname, a.updated_at, d.added_at, d.product_id, e.name, SUM( g.qty_ordered ) AS purchased
FROM  `wishlist` AS a
INNER JOIN customer_entity AS b ON a.customer_id = b.entity_id
INNER JOIN customer_entity_varchar AS c ON a.customer_id = c.entity_id
AND c.attribute_id = ( 
SELECT attribute_id
FROM eav_attribute
WHERE attribute_code =  'firstname'
AND entity_type_id = b.entity_type_id ) 
INNER JOIN wishlist_item AS d ON a.wishlist_id = d.wishlist_id
INNER JOIN catalog_product_flat_1 AS e ON d.product_id = e.entity_id
LEFT JOIN sales_flat_order AS f ON f.customer_email = b.email
LEFT JOIN sales_flat_order_item AS g ON ( f.entity_id = g.order_id
AND g.sku LIKE CONCAT( e.sku,  '%' ) 
AND g.product_type =  'simple' ) 
WHERE e.sku =  'api_75019'
GROUP BY b.email, c.value, a.updated_at, d.added_at, d.product_id, e.name