0

我正在验证手机号码并检索客户电子邮件地址并允许客户更改该表单中的电子邮件地址,现在我需要更新电子邮件地址如何从我的自定义控制器执行此操作,即如何调用客户类并更新我的电子邮件prestashop 中的地址

elseif (Tools::isSubmit('update_email')) {
    $otp_mobile_num = trim(Tools::getValue('otp_mobile_num'));
    $update_email = Tools::getValue('update_email_address');
    $old_email = Tools::getValue('old_email_address');  
    //d($otp_mobile_num);
    if($old_email!= $update_email) {
        //d($update_email);
        // Checked the email address is already in use, in case he changed his email address
        if (Validate::isEmail($update_email) && !empty($update_email)) {
            if (Customer::customerExists($update_email)) {
                $this->errors[] = Tools::displayError('An account using this email address :('.$update_email.') has already been registered.', false);
            }
        }
    } else {
         $this->errors[] = Tools::displayError('You must change the email address!');
    }
}

以下是我的单独表格:

在此处输入图像描述

4

1 回答 1

0

您可以尝试直接更新上下文客户:

elseif (Tools::isSubmit('update_email')) {
    $otp_mobile_num = trim(Tools::getValue('otp_mobile_num'));
    $update_email = Tools::getValue('update_email_address');
    $old_email = Tools::getValue('old_email_address');  
    //d($otp_mobile_num);
    if($old_email!= $update_email){
        //d($update_email);
        // Checked the email address is already in use, in case he changed his email address
        if (Validate::isEmail($update_email) && !empty($update_email)) {
            if (Customer::customerExists($update_email)) {
                $this->errors[] = Tools::displayError('An account using this email address :('.$update_email.') has already been registered.', false);
            } elseif(Context::getContext()->customer->id == null) {
                $this->errors[] = Tools::displayError('You must be logged in');
            } else {
                Context::getContext()->customer->email = $update_email
                if(Context::getContext()->customer->save()) {
                    // Customer updated correctly
                } else {
                    $this->errors[] = Tools::displayError('An error occured');
                }
            }
        }
    }else{
         $this->errors[] = Tools::displayError('You must change the email address!');
    }
}
于 2016-06-13T12:20:20.883 回答