Prestashop - 如果选择了特定国家/地区,则替换邮政编码中的某些字符

发布于 2025-01-10 23:03:02 字数 1691 浏览 3 评论 0原文

我需要在结账时更改邮政编码(该模块是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 get:
enter image description here

What i should get:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文