Magento Checkout – Associate Guest Checkout with Account if Email Matches

checkoutcustomeree-1.13.1.0email

In the admin panel under the menu item Customers > Manage Customers. When you click on a customer it shows all their customer information.

The problem is if I checkout as a guest and use the same email i use when i'm logged in the record does not get stored in my recent orders. Is this functionality standard? Is there a way to associate the emails so even if they checkout as a guest it still gets recorded in the customer information > recent orders section?

I've looked through the configuration settings for customer configuration and checkout but to no avail.

It only shows under Sales > Orders.

Are you allowed to store information if they're a guest?

Best Answer

By default when a customer check out as a register user magento will store the customer info and link the customer to existing order using:

Table : sales_flat_order
   - customer_id        : numeric customer id
   - customer_is_guest  : bool - add clickable link in sales order admin

Therefore you could create a custom module. Then using an observer you could

  1. Check if the customer is checking out as guest
  2. If there is a existing customer with the same email
  3. Update the order accordingly.

Please note this method may assign the order to wrong user if someone existing customer mistype there email

Take a look at Magento - Wiki - Customize Magento using Event/Observer

In config.xml

...
<events>
  <sales_order_place_before>
    <observers>
      <sales_order_place_after_observer>
        <type>singleton</type>
        <class>convertcustomer/observer</class>
        <method>checkCustomerRecord</method>
      </sales_order_place_after_observer>
    </observers>
  </sales_order_place_before>     
</events>
...

In observer.php

Class MagePal_Model_ConvertCustomer_Observer{
    function checkCustomerRecord($observer){
        $order = $observer->getOrder();

        // if guest
        if(!$order->getCustomerId()){
            $storeId = $order->getStoreId()
            $websiteId = Mage::getModel('core/store')->load($storeId)->getWebsiteId();

            $customer = Mage::getModel("customer/customer"); 
            $customer->setWebsiteId($websiteId); 
            $customer->loadByEmail($email);

            //if email found
            if($customer->getId()){
                $order->setCustomerId($customer->getId());
                $order->setCustomerIsGuest(0);
            }
        }
    }

}
Related Topic