Hello All,
I am writing here a script snippet for getting the orders count for given customer
< ?php $customer_id = 5; $_orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_id',$customer_id); $_orderCnt = $_orders->count(); //orders count echo 'Customer with ID '.$customer_id.' has '.$_orderCnt.' orders'; ?>
if i want to check this for all customer id’s than how can i?
Simplest way is to fetch all the customer id using customer collection (Refer this Customer Model Magento) and than use it in order collection
You get all orders collection just for a count number.
Amazing!
Please post here if any other easy way to do it, I didn’t find any other way
hi
how do I use this piece of code to retrieve the order count and put it on the order email sent out. The order email has the Order ID and next to it I’d like to put the order count for that customer i.e.
Customer Name: John Smith
Order ID: 0000000000012340
Order Count: 8 ( this would include this particular order and the 7 before this)
Thanks guys.
You need to customize the email functionality for the same, the point where the email template HTML is generated dynamically.
I am curious about guest customer, though.
Will have to modify the code snippet to either show this only for registered user or will need to look for all orders by that particular email address
its trick to say the least… currently we do not allow guest checkout… but we’re working towards that
thanks for help
Use the above code, it will work for registered as well as guest.
Thanks, this code is very simple.
Thanks a million!
Hi,
We have started our new magento webstore recently. On the sales reports if along with the order id, customer name, customer email, order value & other attributes, we want to get the count of orders placed by that particular customer.
Is there anything that you can help us in achieving this?
Please advice
Thanks,
Ravi
Check this post Order Profit column in Magento