Skip to content

Instantly share code, notes, and snippets.

@mehh
Created June 2, 2016 15:38
Show Gist options
  • Save mehh/d2a9420ce41a41a7e6ef448d84c031d8 to your computer and use it in GitHub Desktop.
Save mehh/d2a9420ce41a41a7e6ef448d84c031d8 to your computer and use it in GitHub Desktop.
Export list of transaction IDs, Customer IDs and coupon codes used for Magento Orders
SELECT sfo.customer_id AS customer, ce.email, GROUP_CONCAT(cev.value SEPARATOR ' ') as name,
sfo.entity_id, sfo.increment_id,scu.times_used,sc.coupon_id,sc.rule_id,sc.code FROM sales_flat_order sfo
LEFT JOIN salesrule_coupon_usage scu ON sfo.customer_id = scu.customer_id LEFT JOIN salesrule_coupon sc
ON sc.coupon_id = scu.coupon_id LEFT JOIN customer_entity ce ON ce.entity_id = sfo.customer_id
LEFT JOIN customer_entity_varchar cev ON cev.entity_id = sfo.customer_id WHERE (cev.attribute_id IN (5,7)
OR cev.attribute_id IS NULL) GROUP BY sfo.increment_id ORDER BY sfo.increment_id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment