Assign guest order to customer Magento 1.9
-
07-02-2021 - |
سؤال
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.
لا تنتمي إلى magento.stackexchange