2012-11-05 2 views
3

Magneto 시스템에 게스트 주문서가있어서 이메일 주소를 수정해야합니다. 언급 한 고객은 계정을 만들지 않았으므로 MySQL 테이블을 직접 수정해야한다고 생각합니다. 누구든지 수정할 필요가있는 테이블의 올바른 방향으로 나를 가리킬 수 있습니까?게스트 주문 전자 메일 주소 수정

"sales_flat_order", "sales_flat_order_address"및 "sales_flat_quote"등의 이메일 주소가 표시되지만 수정해야 할 항목이 확실하지 않습니다. 이러한 종류의 편집을 할 때주의해야 할 사항이 있습니까?

감사합니다.

Magneto Community 1.7.0.2를 사용하고 있습니다.

답변

6

데이터 일관성을 위해 sales_flat_order는 admin의 주문 세부 정보 페이지에 표시되어야합니다.

또한`사용하여 내가해야 할 일을했을

$order = Mage::getModel('sales/order')->load($order_id); 
$order->setCustomerEmail($email_address)->save(); 
+0

주문 번호하여 변경할 수 마법사 ::을 getModel ('판매/주문) -> loadByIncrementId ('10000001 ');' – FosAvance

+0

@FosAvance ... magento에는 increment_id와 order_id (entity_id)가 있습니다. 따라서 ID가있는 ID에 따라로드해야합니다. –

0
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

답변을 제공하는 이유에 대한 간략한 설명을 추가하는 것이 도움이 될 수 있습니다. 질문자 배경 정보. –

관련 문제