1

I am working on magento1.7.
Every single order has a customer name and email address saved within it.
However I guess, Magento only shows these details in the Customers > Manage Customers section if that person has created an account.

If the customer checked out as a guest then their name and email address are only saved within the order in the database.

so I am unable to find the list of all customer.

Is it possible to have a query that will scan every single order within the back end and get the customer's full name, their email address and order date ?

I want to find all the customer who has made orders (both as a registered user or guest) from the beginning of the store..

Could any one suggest some query ?

2
  • It's incredible you've accepted an answer that retrieves just the guest users and that is loading the entire order collection just to use a few fields... Commented Jan 19, 2016 at 10:16
  • @MauroNigrele Well I have modified that a little bit..from ' * ' to specific columns in array format.. Commented Jan 19, 2016 at 10:30

2 Answers 2

2

You can write the below query for guest customer..

    $orderCollection = Mage::getModel("sales/order")->getCollection()
                      ->addFieldToSelect('*')
                      ->addFieldToFilter('customer_is_guest',1) ;
    foreach( $orderCollection  as $order){

             echo $order->getCustomerFirstname()." ";
             echo $order->getCustomerLastname()."<br>";

    }  

if you put "customer_is_guest" to 0 then you can get the registered customers..

This comes directly from the "sales_flat_order" table .

Hope this helps..

2

Absolutely! You can get these fields from the sales_flat_order table or simply using order collection resource that way:

    $statuses = array('completed','processing');
    $fields = array('customer_email','customer_firstname','customer_lastname');

    $collection = Mage::getResourceModel('sales/order_collection');
    /** @var $collection Mage_Sales_Model_Resource_Order_Collection */

    // - you can use Collection to filter status (if you want)
    $collection->addFieldToFilter('status', array('in' => $statuses));

    // - Use the standard zend select to get just what you need
    $select = $collection->getSelect()
        ->reset(Zend_Db_Select::COLUMNS)
        ->columns($fields)
        // group by email to avoid repetitions 
        ->group('customer_email');

    $data = $select->getAdapter()->fetchAll($select);

You can achieve this in many different ways but I'm pretty shure that this is the most clean and performant.

If you need to differentiate between guest and customers can use the field customer_is_guest or customer_id but since the query it's grouping by email if an user's placed on order as guest an other as customer you'll never know (at least with this query)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.