Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8471033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:41:06+00:00 2026-06-10T16:41:06+00:00

I am working outside of magento store root folder (1.4) and I would like

  • 0

I am working outside of magento store root folder (1.4) and I would like to get customers order totals, and date of last order. I have started with this:

$customer = Mage::getModel('customer/customer')->load($entity_id);
         $customerTotals =Mage::getResourceModel('sales/sale_collection')
              ->setCustomerFilter($customer)
              ->load()
              ->getTotals();

         echo $customerTotals->getNumOrders();
         echo money_format('$%i',$customerTotals->getLifetime());

This seems to be giving me totals from the wrong customer… Also, can’t quite figure out how to get customers last order day.

any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:41:07+00:00Added an answer on June 10, 2026 at 4:41 pm

    This will work, giving you the total number of order, total sales and most recent order for a given customer.

    The code could be shortened a little, but for clarity it is as follows…

    $customerId = 2;
    $orderCollection = Mage::getModel('sales/order')->getCollection()
        ->addFilter('customer_id', $customerId)
        ->setOrder('created_at', Varien_Data_Collection_Db::SORT_ORDER_DESC)
    ;
    $numberOfOrders = $orderCollection->count();
    $newestOrder = $orderCollection->getFirstItem();
    
    $orderCollection->clear()->getSelect()
        ->columns(array('total_sales'=>'SUM(main_table.base_grand_total)'))
        ->group('customer_id')
    ;
    $totalSales = $orderCollection->getFirstItem()
        ->getData('total_sales');
    
    //Some output to confirm...
    echo "<p>" . $numberOfOrders . "</p>";
    echo "<p>" . Mage::helper('core')->currency($totalSales, true, false) ."</p>";
    echo "<p>" . $newestOrder->getData('increment_id') ."</p>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working over Eclipse, and I have created a res folder outside mi src
I have been working on getting my OSGi application to run outside eclipse. It
I'm working on my very first project outside the college. I have two classes.
I'm working with shindig trying to get some OAuth1 gadgets working outside any container
I've been working on a plugin for Magento, and I have one global block
I have been trying to get images rendered in Primefaces-application. This is working fine
I have been working on a legacy C++ application and am definitely outside of
I'm working with a Google Maps example code , this : http://www.wolfpil.de/v3/drag-from-outside.html which has
I don't want anything incredibly complicated. I am working on a client outside the
Working with Reporting Services 2008 r2. So here's my issue: We have 5 reports

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.