How can I see full order details for each time a c

2019-09-01 03:05发布

问题:

We are trying to collect data on each person that used a certain coupon code "NEWCUSTOMER". We are trying to get the order details including their name, email address, and what they ordered.

Is the rule_id connected to an order in any way in the database? The magento databases don't seem to be all that friendly when you are trying to write your own mySQL statement to figure this information out.

Thanks!

回答1:

This is similar to your previous question which i have also answered for you: Find the name and email address of non-members who used coupon code in Magento

The coupon code used on an order is actually a property of the order: coupon_code

It sounds from your question that you are directly querying the db, if so then you are looking for the coupon_code field in the sales_flat_order table.

Here is the sql:

SELECT `customer_firstname`, `customer_lastname`, `customer_email` FROM `sales_flat_order` WHERE  `coupon_code` = 'your_awesome_coupon_code' AND `customer_group_id` = 0

Or, via magento...

 $orderCollection = Mage::getModel('sales/order')->getCollection()
        ->addAttributeToSelect('customer_firstname')
        ->addAttributeToSelect('customer_lastname')
        ->addAttributeToSelect('customer_email')
        ->addAttributeToSelect('customer_group_id')
        ->addAttributeToSelect('coupon_code')
        ->addAttributeToFilter('customer_group_id', Mage_Customer_Model_Group::NOT_LOGGED_IN_ID)
        ->addAttributeToFilter('coupon_code', 'NEWCUSTOMER');


标签: mysql magento