Skip to content

Instantly share code, notes, and snippets.

@webdawe
Created October 12, 2016 00:31
Show Gist options
  • Save webdawe/ce53bfbead4c3b3a02698ded6e4d005d to your computer and use it in GitHub Desktop.
Save webdawe/ce53bfbead4c3b3a02698ded6e4d005d to your computer and use it in GitHub Desktop.
Magento Store wise Month wise Price wise Qty Sales Report for a given categrory ID
SET @entityTypeId := (SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_product');
SET @nameAttributeId := (select attribute_id FROM eav_attribute where attribute_code = 'name' and entity_type_id = @entityTypeId);
SET @categoryId =5;
select w.name as website,name.value as product_name,oi.product_id,DATE_FORMAT(oi.created_at, '%b %Y'), oi.price,SUM(oi.qty_ordered) FROM sales_flat_order_item oi
INNER JOIN catalog_product_entity_varchar name ON name.entity_id = oi.product_id AND name.store_id = 0 AND name.attribute_id = @nameAttributeId
INNER JOIN core_store s ON s.store_id = oi.store_id
INNER JOIN core_website w ON w.website_id = s.website_id
WHERE product_id in (SELECT product_id FROM catalog_category_product where category_id = @categoryId)
AND created_at > DATE_SUB(NOW(), INTERVAL 12 MONTH)
GROUP BY oi.product_id,oi.price,DATE_FORMAT(oi.created_at, '%b %Y'),oi.store_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment