2

Hi I would like to know how to track the total amount spent by 1 individual customer? As in a customer might have made many transactions and the total amount spend for that customer.

Main reason is I need to find out my top spending customer from 1st transactions till present.

Berlinda
  • 21
  • 1
  • 2

2 Answers2

5

Here is the query to get life time sales of particular customer,

SELECT DISTINCT customer_email, customer_firstname, customer_lastname, SUM( subtotal_invoiced ) AS Total
FROM `sales_flat_order` AS a
WHERE customer_email = 'customer_email'
GROUP BY customer_email
ORDER BY SUM( subtotal_invoiced ) DESC
LIMIT 0 , 30

Here replace customer_email with user's email.

Update:

I wrote a simple module for you, In your controller, add this method,

 public function IndexAction() {

     $orders = Mage::getModel('sales/order')->getCollection()
     ->addAttributeToFilter('customer_email', 'yourmail@gmail.com');

foreach ($orders as $order) {
    $total = $order->getGrandTotal();
     $sum+= $total;

}
   echo $sum ;

    }

If you want filter order status,then

    ->addFieldToFilter('status', 'complete')

Add this filter option in your order collection like this,

$orders = Mage::getModel('sales/order')->getCollection()
     ->addAttributeToFilter('customer_email', 'yourmail@gmail.com')
     ->addFieldToFilter('status', 'complete'); 

Cheers..!

Elavarasan
  • 888
  • 1
  • 11
  • 27
0

Or you could go to Customers >Manage Customers > Select the customer you want .... Here you will see a lifetime sales figure.

Max Smith
  • 145
  • 11