3

My main question is to convert guest to customer

Here is the case: Assumption: a guest placed an order, he successfully paid for that, when he is on the success page then I want to ask him

Do you want to register

If yes please enter your password. Then he clicks create account

Now I want convert this guest to customer and assign the orders to his new customer id

Please let me know if there is an easy way than using plugins

1

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();
  • Hi Amit , thanks almost done , one thing i didnt understand id customer_address_id, where would i get this – Sree Apr 1 '15 at 12:22
  • If customer have address in his/her account dashboard..... you need put customer address id. – Amit Bera Apr 1 '15 at 12:26
  • Hi Amit , as i am converting guest to customer , there is no address linked to his account , so how can i get customer_address_id .. (bit urgent , i need to fix asap ..) – Sree May 15 '15 at 10:40

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.