我的 Magneto 系统中有一个客人订单,我现在需要修改存档的电子邮件地址。提到的客户没有创建帐户,所以我相信我需要直接修改 MySQL 表。谁能指出我需要修改哪些表格的正确方向?
我在“sales_flat_order”、“sales_flat_order_address”和“sales_flat_quote”等中看到了一个电子邮件地址,但我不确定要编辑什么。在进行此类编辑时,我需要注意什么后果吗?
谢谢!
我正在使用 Magneto 社区 1.7.0.2。
我的 Magneto 系统中有一个客人订单,我现在需要修改存档的电子邮件地址。提到的客户没有创建帐户,所以我相信我需要直接修改 MySQL 表。谁能指出我需要修改哪些表格的正确方向?
我在“sales_flat_order”、“sales_flat_order_address”和“sales_flat_quote”等中看到了一个电子邮件地址,但我不确定要编辑什么。在进行此类编辑时,我需要注意什么后果吗?
谢谢!
我正在使用 Magneto 社区 1.7.0.2。
为了数据一致性,您可以更改所有 3 个,sales_flat_order 应该是显示在管理员订单详细信息页面上的那个。
您也可以通过订单号更改它
$order = Mage::getModel('sales/order')->load($order_id);
$order->setCustomerEmail($email_address)->save();
Update Customer customerwhole account : Akram Abbasi
/**
* Create customer corporate account action
*/
public function updatePostAction()
{
$session = $this->_getSession();
if ($session->isLoggedIn()) {
$this->_redirect('*/*/');
return;
}
$session->setEscapeMessages(true); // prevent XSS injection in user input
if ($this->getRequest()->isPost()) {
$errors = array();
if (!$customer = Mage::registry('current_customer')) {
$customer = Mage::getModel('customer/customer')->setId(null);
}
/* @var $customerForm Mage_Customer_Model_Form */
$customerForm = Mage::getModel('customer/form');
// $customerForm->setFormCode('customer_account_create')->setEntity($customer);
$customerForm->setFormCode('customer_account_edit')->setEntity($customer);
$customerData = $customerForm->extractData($this->getRequest());
$customerErrors = $customerForm->validateData($customerData);
// get customer form value
$firstname = $customerData['firstname'];
$lastname = $customerData['lastname'];
$email = $customerData['email'];
$password = (string) $this->getRequest()->getPost('password');
$passwordConfirmation = (string) $this->getRequest()->getPost('confirmation');
$customer_id = Mage::getModel('customer/customer')->getCollection()->addAttributeToFilter('customer_id',$this->getRequest()->getPost('customer_id'))->load();
$customerprimaryid = Mage::getModel('customer/customer')->getCollection()->addAttributeToFilter('customer_id',$this->getRequest()->getPost('customer_id'))->load();
$invoice_number = Mage::getModel('customer/customer')->getCollection()->addAttributeToFilter('invoice_number',$this->getRequest()->getPost('invoice_number'))->load();
// fetch data of invoice_number
foreach($invoice_number as $value){
$invoice_number = $value->getdata('invoice_number');
}
//fetch data from existing records
foreach($customer_id as $value){
$customer_id = $value->getdata('customer_id'); // get attribute
$customer_email = $value->getdata('email'); // get attribute
$entity_id = $value->getdata('entity_id'); // Customer table primary key
$entity_type_id = $value->getdata('entity_type_id');
}
// check customer_id and invoice_number with existing database records
if($customer_id != $this->getRequest()->getPost('customer_id') && $invoice_number != $this->getRequest()->getPost('invoice_number')) {
$message = $this->__('Customer id or Invoice Number is invalid or does not exist');
$session->setEscapeMessages(false);
$session->addError($message);
$this->_redirectError(Mage::getUrl('customer/account/createcorporate', array('_secure' => true)));
return;
}
if($password != $passwordConfirmation) {
$message = $this->__('Please make sure your passwords match');
$session->setEscapeMessages(false);
$session->addError($message);
$this->_redirectError(Mage::getUrl('customer/account/createcorporate', array('_secure' => true)));
return;
}
if ($this->getRequest()->getParam('is_subscribed', false)) {
$customer->setIsSubscribed(1);
}
// due to Magneto Limitation or dependency of email inserting/editing on identical records,Magneto customer->save() function does not allow to according We use to do it with custom
if(isset($invoice_number) && isset($customer_id)) {
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$write->query("UPDATE customer_entity set email='$email' where entity_id=$entity_id");
$write->query("UPDATE customer_entity_varchar set value='$firstname' where entity_id=$entity_id and attribute_id in (select attribute_id from eav_attribute where attribute_code='firstname' and entity_type_id=$entity_type_id)");
$write->query("UPDATE customer_entity_varchar set value='$lastname' where entity_id=$entity_id and attribute_id in (select attribute_id from eav_attribute where attribute_code='lastname' and entity_type_id=$entity_type_id)");
}
// load by new updated data to avoid email conflict
$customer = Mage::getModel("customer/customer");
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->load($entity_id); //load customer by entity id
if (strlen($password)) {
/**
* Set entered password and its confirmation - they
* will be validated later to match each other and be of right length
*/
$customer->setPassword($password);
$customer->setConfirmation($passwordConfirmation);
$customer->setConfirmation(null);
$customer->save();
} else {
$errors[] = $this->__('New password field cannot be empty.');
}
/**
* Initialize customer group id
*/
$customer->getGroupId();
if ($this->getRequest()->getPost('create_address')) {
/* @var $address Mage_Customer_Model_Address */
$address = Mage::getModel('customer/address');
/* @var $addressForm Mage_Customer_Model_Form */
$addressForm = Mage::getModel('customer/form');
$addressForm->setFormCode('customer_register_address')->setEntity($address);
$addressData = $addressForm->extractData($this->getRequest(), 'address', false);
$addressErrors = $addressForm->validateData($addressData);
if ($addressErrors === true) {
$address->setId(null)
->setIsDefaultBilling($this->getRequest()->getParam('default_billing', false))
->setIsDefaultShipping($this->getRequest()->getParam('default_shipping', false));
$addressForm->compactData($addressData);
$customer->addAddress($address);
$addressErrors = $address->validate();
if (is_array($addressErrors)) {
$errors = array_merge($errors, $addressErrors);
}
} else {
$errors = array_merge($errors, $addressErrors);
}
}
try {
$customerErrors = $customerForm->validateData($customerData);
if ($customerErrors !== true) {
$errors = array_merge($customerErrors, $errors);
} else {
$customerForm->compactData($customerData);
$customer->setPassword($this->getRequest()->getPost('password'));
$customer->setConfirmation($this->getRequest()->getPost('confirmation'));
$customerErrors = $customer->validate();
if (is_array($customerErrors)) {
$errors = array_merge($customerErrors, $errors);
}
}
$validationResult = count($errors) == 0;
if (true === $validationResult) {
$customer->save();
Mage::dispatchEvent('customer_register_success',
array('account_controller' => $this, 'customer' => $customer)
);
if ($customer->isConfirmationRequired()) {
$customer->sendNewAccountEmail(
'confirmation',
$session->getBeforeAuthUrl(),
Mage::app()->getStore()->getId()
);
$session->addSuccess($this->__('Account confirmation is required. Please, check your email for the confirmation link. To resend the confirmation email please <a href="%s">click here</a>.', Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail())));
$this->_redirectSuccess(Mage::getUrl('*/*/index', array('_secure'=>true)));
return;
} else {
$session->setCustomerAsLoggedIn($customer);
$url = $this->_welcomeCustomer($customer);
$this->_redirectSuccess($url);
return;
}
} else {
$session->setCustomerFormData($this->getRequest()->getPost());
if (is_array($errors)) {
foreach ($errors as $errorMessage) {
$session->addError($errorMessage);
}
} else {
$session->addError($this->__('Invalid customer data'));
}
}
} catch (Mage_Core_Exception $e) {
$session->setCustomerFormData($this->getRequest()->getPost());
if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) {
$url = Mage::getUrl('customer/account/forgotpassword');
$message = $this->__('There is already an account with this email address. If you are sure that it is your email address, <a href="%s">click here</a> to get your password and access your account.', $url);
$session->setEscapeMessages(false);
} else {
$message = $e->getMessage();
}
$session->addError($message);
} catch (Exception $e) {
$session->setCustomerFormData($this->getRequest()->getPost())
->addException($e, $this->__('Cannot save the customer.'));
}
}
$this->_redirectError(Mage::getUrl('*/*/createcorporate', array('_secure' => true)));
}