Magento – Find customer who have purchased only one time

Tech Bandhu

Once I had to find out the list of all costume who have purchased one one or have only one order placed.
Bellow query would be that list,

SELECT * FROM sales_flat_order GROUP BY customer_id HAVING COUNT(customer_id) = 1

One of my friend need the same with magento module only, I had given bellow solution.

$collection = Mage::getModel('customer/customer')->getCollection();
foreach ($collection as $user){
    $orders = Mage::getModel('sales/order')
    if($orders->getSize() == 1){
        echo $user->getId();

If you found some alternate solution you can suggest me, post your valuable comments.

View original post

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s