문제

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(); 
?>
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top