I am using magento version 1.9 and its soap api to create order. In case of guest checkout(customer mode is guest), the email address is not getting saved or shown in admin sales orders. This is working fine for customer in "customer" mode. In the api, it is working fine because "customer_is_guest" is 1 and customer_email is correctly set when we check cart.info api call. Please help to resolve this magento bug.
2 Answers
Fixed and tested: add to your existing module or add a new module:
config.xml
// src/app/code/local/Your/Module/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Your_Module>
<version>1.0.0</version>
</Your_Module>
</modules>
<global>
<models>
<your_module_alias>
<class>Your_Module_Model</class>
</your_module_alias>
<checkout>
<rewrite>
<api_resource_customer>Your_Module_Model_Api_Resource_Customer</api_resource_customer>
</rewrite>
</checkout>
</models>
</global>
</config>
Customer.php
// src/app/code/local/Your/Module/Model/Api/Resource/Customer.php
/**
* Class Your_Module_Model_Api_Resource_Customer
*/
class Your_Module_Model_Api_Resource_Customer
extends Mage_Checkout_Model_Api_Resource_Customer
{
/**
* FIX guest order email blank.
*
* Mage using billing address email as customer email on guest orders.
*
* see http://magento.stackexchange.com/questions/90380/magento-customer-email-missing-in-guest-checkout-when-using-soap-api
*
* @param Mage_Sales_Model_Quote $quote
*
* @return $this
*/
protected function _prepareGuestQuote(Mage_Sales_Model_Quote $quote)
{
$quote->setCustomerId(null)
// ORIG: email always empty ->setCustomerEmail($quote->getBillingAddress()->getEmail())
->setCustomerEmail($quote->getCustomerEmail()) // fix
->setCustomerIsGuest(true)
->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
return $this;
}
}
I had the same problem, on this file:
app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php #114
I found this code
protected function _prepareGuestQuote(Mage_Sales_Model_Quote $quote)
{
$quote->setCustomerId(null)
->setCustomerEmail($quote->getBillingAddress()->getEmail())
->setCustomerIsGuest(true)
->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
return $this;
}
Basically the "email" address is overridden by the "email" address of the billing address. I changed the code to:
protected function _prepareGuestQuote(Mage_Sales_Model_Quote $quote)
{
$quote->setCustomerId(null)
->setCustomerIsGuest(true)
->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
return $this;
}