当客户或用户注册时,我想一键捕获地址详细信息并将其保存在 ps_address 表中,即当他点击注册按钮时,他的地址详细信息也必须保存到 ps_address 表中,如何做到这一点?
我已设法自定义注册表单,并能够将地址详细信息表插入我的注册表单,如附图所示:
现在我坚持的是:当我点击注册按钮时,地址字段详细信息没有保存在数据库中,我收到服务器错误
我试图做的是,我创建了一个名为 processPostAddress 的新函数,并在重定向到帐户页面之前从 controller/front/Authcontroller.php 页面中的 processSubmitAccount() 调用 processPostAddress。
$this->processPostAddress(); //// custom function call
Tools::redirect('index.php?controller='.(($this->authRedirection !== false) ? urlencode($this->authRedirection) : 'my-account'));
下面是我在 controller/front/Authcontroller.php 页面中创建的自定义函数
public function processPostAddress()
{
if($this->context->customer->id_customer!=''){
$address = new Address();
$address->id_customer = 40;
$address->firstname = trim(Tools::getValue('firstname'));
$address->lastname = trim(Tools::getValue('lastname'));
$address->address1 = trim(Tools::getValue('address1'));
$address->address2 = trim(Tools::getValue('address2'));
$address->postcode = trim(Tools::getValue('postcode'));
$address->city = trim(Tools::getValue('city'));
$address->country = trim(Tools::getValue('country'));
$address->state = trim(Tools::getValue('state'));
$address->phone = trim(Tools::getValue('phone'));
$address->phone_mobile = trim(Tools::getValue('phone_mobile'));
$address->add(); // This should add the address to the addresss table }
}
请帮助我或告诉我我是否做错了什么或如何做到这一点