如何不显眼地向 Magento 结帐添加新的验证方法?
我想阻止客户在所选送货方式的送货地址中输入邮政信箱(在本例中尤其是 UPS)。我可以重写 js/prototype/validation.js 来插入新的验证模式,但我不想分叉这样的密钥文件。
在客户通过 Javascript 选择送货方式后,是否有一种机制可以不引人注目地验证客户的送货地址,而无需覆盖核心文件?
我看到 validation.js
内部使用了 Validation.add
,因此是否可以在核心文件之外添加新的验证方法?
我想要应用的正则表达式是:
\b([P|p](OST|ost)?\.?\s?[O|o|0](ffice|FFICE)?\.?\s)?([B|b][O|o|0][X|x])\s(\d+)
如果无法在 JS 中优雅地执行验证,我会对 controller_action_predispatch_onepage_saveShippingMethod
上的观察者感兴趣,它检查数据并执行 Ajax 重定向回发货如有必要,填写地址表格。
I want to prevent customers entering PO Boxes into the shipping address for selected Shipping Methods (UPS specifically in this case). I could override js/prototype/validation.js
to insert a new validation pattern, but I don't want to fork such a key file.
Is there a mechanism to unobtrusively validate the customer's shipping address AFTER they select a shipping method via Javascript without overriding core files?
I see that Validation.add
is used inside the validation.js
, so it may be possible to add a new validation method outside of the core file?
The regex that I want to apply is:
\b([P|p](OST|ost)?\.?\s?[O|o|0](ffice|FFICE)?\.?\s)?([B|b][O|o|0][X|x])\s(\d+)
If the validation cannot be performed elegantly in the JS, I would be interested in an Observer on the controller_action_predispatch_onepage_saveShippingMethod
that inspects the data and performs an Ajax redirect back to the shipping address form if necessary.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用的库是真正简单的字段验证,该页面确实解释了如何扩展它。我想你会需要这样的东西:
The library used is Really Easy Field Validation and that page does explain how to extend it. I guess you will need something like this:
作为一个简短的研究,而不调试结账
As a brief look into it without debugging the checkout