Изменить Адрес Электронной Почты Для Заказа Гостя


У меня есть гостевой заказ в моей системе Magneto, и теперь мне нужно изменить адрес электронной почты в файле. Клиент, как уже упоминалось, не создавал учетную запись, поэтому я считаю, что мне нужно будет напрямую изменить таблицы MySQL. Может ли кто-нибудь указать мне в правильном направлении, какие таблицы мне нужно изменить?

Я вижу адрес электронной почты в "sales_flat_order", "sales_flat_order_address" и "sales_flat_quote" и т. Д., Но я не уверен, что нужно редактировать. Есть ли какие-либо последствия, о которых мне нужно знать при выполнении такого рода редактирования?

Спасибо!

Я использую сообщество Магнето 1.7.0.2.

Author: stitz, 2012-11-06

2 answers

Для согласованности данных вы можете изменить все 3, sales_flat_order должен отображаться на странице сведений о заказе в admin.

Вы также можете изменить его по номеру заказа

$order = Mage::getModel('sales/order')->load($order_id);
$order->setCustomerEmail($email_address)->save();
 6
Author: Renon Stewart, 2012-11-12 04:00:16
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)));
}
 0
Author: Muhammad Akram Abbasi, 2014-02-24 14:37:22