Prestashop - 如果选择了特定国家/地区,则替换邮政编码中的某些字符
我需要在结账时更改邮政编码(该模块是Onepagecheckout)。
目标是在 wp_address 中存储的数据之前根据地址所在国家/地区执行邮政编码的 str_replace()。例如,如果国家/地区是葡萄牙,则邮政编码格式为 NNNN-NNN。我必须将“-”替换为“”。
我找到了将地址存储在数据库中的钩子,并且编辑工作很好。但有一个新问题:通常,当我选择国家/地区时,模块会自动向我显示一些运送的可能性,但现在我编辑邮政编码的国家/地区不会发生这种情况。
提供存储地址的钩子是 Hook::exec('actionSubmitCustomerAddressForm', array('address' => &$address)); ,在文件 onepagecheckoutps.php 中
肯定有与表 ww_ps_country 中的 zip_code_format 不兼容,在某些时候,他将 zip_code_format (NNNN-NN) 与邮政编码(即 NNNNNN)。
但我不知道为什么我可以解决这个问题。这是我的代码 onepagecheckoutps.php =>; validateFieldsAddress()
...
if (!Validate::isDate($address->date_add)) {
$address->date_add = date('Y-m-d H:i:s');
}
if (!Validate::isDate($address->date_upd)) {
$address->date_upd = $address->date_add;
}
switch ($address->id_country) {
case 15 :
$address->postcode = str_replace("-","",$address->postcode);
case 13:
$address->postcode = substr($address->postcode,0,4);
case 125:
$address->postcode = substr($address->postcode,3);
case 12:
$address->postcode = substr($address->postcode,2);
}
Hook::exec('actionSubmitCustomerAddressForm', array('address' => &$address));
}
我应该得到什么:
I need to change the postal code at the moment of the check out (the module is Onepagecheckout).
The target is to do a str_replace() of postal cose according to country of the address, before the data stored in wp_address. For exemple, if the country is Portugal, the zip code format is NNNN-NNN. I have to replace the "-" with "".
I found the hook that store the address in the DB, and the edit work nice. But there is a new problem: normally, when i select the conuntry, automatically the module show me some possibility of shipping and now that's not happen with the country where i edit the zip code.
The hook that provide store the address is Hook::exec('actionSubmitCustomerAddressForm', array('address' => &$address));, in the file onepagecheckoutps.php
For sure, there is a incompatibility with the zip_code_format in the table ww_ps_country, at some point he compare the zip_code_format (NNNN-NN) with the zip code (that will be NNNNNN).
But i don't know why i can fix this. Here my code in onepagecheckoutps.php => validateFieldsAddress()
...
if (!Validate::isDate($address->date_add)) {
$address->date_add = date('Y-m-d H:i:s');
}
if (!Validate::isDate($address->date_upd)) {
$address->date_upd = $address->date_add;
}
switch ($address->id_country) {
case 15 :
$address->postcode = str_replace("-","",$address->postcode);
case 13:
$address->postcode = substr($address->postcode,0,4);
case 125:
$address->postcode = substr($address->postcode,3);
case 12:
$address->postcode = substr($address->postcode,2);
}
Hook::exec('actionSubmitCustomerAddressForm', array('address' => &$address));
}
What i should get:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论