0

I was having guest checkout enabled on my magento store, But later regular customers started orders using registering themselves to the store.

So Now i want to link their old orders(they ordered as guest) to their created accounts, They are using same email id they used previously when they ordered as guest.

I want this functionality because i want customers can see there all order history by their accounts.

2 Answers 2

2
  1. To show guest orders in Account Dashboard -> RECENT ORDERS you have to change app/code/core/Mage/Sales/Block/Order/Recent.php -> public function __construct(). Replace this:

    ->addAttributeToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId())
    

    with this:

    ->addAttributeToFilter('customer_email', Mage::getSingleton('customer/session')->getCustomer()->getEmail())
    
  2. To show guest orders in My Orders change app/code/core/Mage/Sales/Block/Order/History.php -> public function __construct(). Replace this:

    ->addFieldToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId())
    

    with this:

    ->addFieldToFilter('customer_email', Mage::getSingleton('customer/session')->getCustomer()->getEmail())
    
  3. To be able to View these orders you have to modify the controller too -> app/code/core/Mage/Sales/Controller/Abstract.php -> protected function _canViewOrder - change this:

    $customerId = Mage::getSingleton('customer/session')->getCustomerId();
    

    with this:

    $customerEmail = Mage::getSingleton('customer/session')->getCustomer()->getEmail();
    

    and this:

    if ($order->getId() && $order->getCustomerId() && ($order->getCustomerId() == $customerId)
    

    with this:

    if ($order->getId() && $order->getCustomerEmail() && ($order->getCustomerEmail() == $customerEmail)
    

It's not good to edit these files directly in core, at least you can copy them in local. Also there are other places that have to be changed if you want all functions to be available for there orders, like reorder and others, but it's a good start.

4
  • Thanks Michael, Let me try those solutions provided by you and will get back to you.
    – K T
    Dec 29, 2014 at 13:24
  • Thanks michael. Its working for me. It is showing orders to the customer but from admin it doesn't show order for that customer.
    – K T
    Dec 31, 2014 at 11:44
  • In the admin panel is more complicated. The file for tab Customer View - Recent Orders is app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Orders.php -> protected function _prepareCollection() and for tab Orders -> app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Orders.php -> protected function _prepareCollection() which are using Mage::getResourceModel('sales/order_grid_collection') which is using database table sales_flat_order_grid which doesn't have column email. That's why you have to make some joins or to change the table.
    – michael
    Jan 1, 2015 at 15:32
  • Your solution worked for me, no need for admin edits. Thanks again
    – K T
    Jan 2, 2015 at 11:47
1

I agree with @michael, but for those who wants easy way, I have developed an extension for you.

Check this link.

Hope it helps someone.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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