1

I want to assign a quest order to a customer, using a custom script. I tried the following, do not get any error, but it is not assigned.

What am I missing?

CODE:

<?php 
ini_set('display_errors', 'On');
error_reporting(E_ALL); 

require('../app/Mage.php'); // this is assuming your script is located in the Magento root dir
Mage::app();

$toCustomer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail($customerEmail);
$orderbyid = Mage::getModel('sales/order')->loadByIncrementId('123456');

$orderbyid->setCustomerId($toCustomer->getId()); 
$orderbyid->setCustomerFirstname($toCustomer->getFirstname()); 
$orderbyid->setCustomerLastname($toCustomer->getLastname()); 
$orderbyid->setCustomerEmail($toCustomer->getEmail());
$orderbyid->save(); 
?>
  • $toCustomer->getId() returns a valid number? – Marius Dec 19 '18 at 13:55
2

Try the below code to assign customer to orders:

<?php 
ini_set('display_errors', 'On');
error_reporting(E_ALL); 

require('../app/Mage.php'); // this is assuming your script is located in the Magento root dir
Mage::app();

$toCustomer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail($customerEmail);
$orderbyid = Mage::getModel('sales/order')->loadByIncrementId('123456');

$orderbyid->setCustomerId($toCustomer->getId()); 
$orderbyid->setCustomerFirstname($toCustomer->getFirstname()); 
$orderbyid->setCustomerLastname($toCustomer->getLastname()); 
$orderbyid->setCustomerEmail($toCustomer->getEmail());
$orderbyid->setCustomerIsGuest(0); //Added by Sukumar
$orderbyid->save(); 
?>

Assume $orderbyid and $toCustomer->getId() getting correct values.

| improve this answer | |

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.