According magento,there are 3 sales table where magento is save customer related
sales_flat_order
sales_flat_order_address
sales_flat_order_grid
sales_flat_order table
customer_id: here customer id save
.for guest user
it save as NULL
.You need to update this column by customer id
.
customer_is_guest: it save as 1 when guest
is saved an order and it value should be 0 when customer is register
.
customer_group_id: Need update customer group by customer group id .
sales_flat_order_grid table
customer_id: here customer id save
.for guest user
it save as NULL
.You need to update this column by customer id
.
sales_flat_order_address
customer_address_id: for guest user
it value is Null. You need update by customer address id whenever try transfer order
customer_id: here customer id save
.for guest user
it save as NULL
.You need to update this column by customer id
.
Code like:
$CustomerId=5;
$customerAddId=20;
$custommergrop=3;
$orderIncrementId=$this->getLastOrderId();
$orderObject=Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
$billingId = $orderObject->getBillingAddress()->getId();
$shipping = $orderObject->isVirtual() ? null : $orderObject->getShippingAddress();
$billingObjct=Mage::getModel('sales/order_address')->load($billingId);
$billingObjct->setData('customer_id',$CustomerId);
$billingObjct->setData('customer_address_id',$customerAddId);
$billingObjct->save();
if($shipping){
$shippingAddressid=$orderObject->getShippingAddress()->getId();
$shippingAddressObject=Mage::getModel('sales/order_address')->load($shippingAddressid);
$shippingAddressObject->setData('customer_id',$CustomerId);
$shippingAddressObject->setData('customer_address_id',$customerAddId);
$shippingAddressObject->save();
}
$orderObject->setData('customer_id',$CustomerId);
$orderObject->setData('customer_is_guest',NULL); /*if null not work then try 0 instead of NULL*/
$orderObject->setData('customer_group_id',$custommergrop);
$orderObject->save();
To get the order details on the checkout success page, use this
$order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
and then retrieve the customer info from the order object like this
//If they have no customer id, they're a guest.
if($order->getCustomerId() === NULL){
echo $order->getBillingAddress()->getFirstname();
echo "<br/>";
echo $order->getBillingAddress()->getLastname();
} else {
//else, they're a normal registered user.
$customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
echo $customer->getDefaultBillingAddress()->getFirstname();
echo "<br/>";
echo $customer->getDefaultBillingAddress()->getLastname();
}
Best Answer
Judging by your screenshot, you are using custom theme. That’s why you need to localize this page (success page) first. Make sure that it has the call
getChildHtml
. If there is not such a call, then you should add it for the block that we gonna create. I’ve taken rwd theme as basis.If you don’t have a module for customizations, then create it. In my case, this is
Test_Module
. There are plenty of articles in the web, where you could find how to create modules.We need one new block
Test_Module_Block_Checkout_Success_Register
where we place the main logic that could be expanded later.In this block we are using method
_beforeTOHtml
where the check for block drawing is held and the order with all required customers’ information is loaded. If you are a perfectionist, you can separate this part for different methods, but the overall way is clear. We are receiving the ordericrement_id
from the parental block where it should be.Note! If your theme is using another system of order receiving, simple replace it in the block with your own.
Then, we need a copy of
customer/form/register.phtml
template that we will edit to get the desired result. Copy the file to the templates folder of your module. In my case this isapp/design/frontend/base/default/template/test/customer/form/register.phtml
. Next, delete all the unnecessary information from the template, but leave all the input fields and widget calls. This is my template:For the fieldsets that shouldn’t be displayed, but will be filled from the block by default, we should set the attribute
hidden="hidden"
. If you delete them completely, the registration won’t be able to complete. Only the fieldset with a password and field with subscription stay visible.Thus, we are using standard registration block for this form, then we need one intermediate template for our block, where this standard block with our template
app/design/frontend/base/default/template/test/checkout/register.phtml
will be called.Finally, we need a layout, where we mark all changes in
app/design/frontend/base/default/layout/test.xml
:The result in the rwd theme should be the following:
All hidden fields are here with the values from the order:
Registration completed successfully:
Pay attention, that this is only a model, that you should customize to suit your theme and correct according to the desired result.
I hope this information will be useful. If you have any question – feel free to ask them.