3

選択した配送方法(この場合は特にUPS)の配送先住所に私書箱を入力しないようにします。オーバーライドjs/prototype/validation.jsして新しい検証パターンを挿入することはできますが、そのようなキーファイルをフォークしたくありません。

コアファイルを上書きせずに、Javascriptを介して配送方法を選択した後、顧客の配送先住所を目立たないように検証するメカニズムはありますか?

Validation.add内で使用されているのでvalidation.js、コアファイルの外に新しい検証メソッドを追加できる可能性がありますか?

適用したい正規表現は

\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リダイレクトを実行するオブザーバーに関心があります。

4

2 に答える 2

7

使用されるライブラリはReallyEasyField Validationであり、そのページにはそれを拡張する方法が説明されています。私はあなたがこのようなものを必要とするだろうと思います:

Validation.add('address', 'Error message text', {
    pattern : /\b([P|p](OST|ost)?\.?\s?[O|o|0](ffice|FFICE)?\.?\s)?([B|b][O|o|0][X|x])\s(\d+)/
});
于 2011-12-06T00:59:34.703 に答える
3

チェックアウトをデバッグせずに簡単に調べてください

# Unfortunately Magento 1.3.2.3 - Find real postcode from debugging checkout
    public function saveShippingAction()

        {
            $this->_expireAjax();
            if ($this->getRequest()->isPost()) {
                $data = $this->getRequest()->getPost('shipping', array());
                $customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
                $result = $this->getOnepage()->saveShipping($data, $customerAddressId);

                $preg_search = '\b([P|p](OST|ost)?\.?\s?[O|o|0](ffice|FFICE)?\.?\s)?([B|b][O|o|0][X|x])\s(\d+)';
                $address = $this->getQuote()->getShippingAddress(); #find real postcode

                if(preg_match($preg_search, $address['postcode']){
                    $result = array(
                            'error' => 1,
                            'message' => Mage::helper('checkout')->__('Invalid PO Box postcode');
                        );
                }
                else{
                        if (!isset($result['error'])) {
                            $result['goto_section'] = 'shipping_method';
                            $result['update_section'] = array(
                                'name' => 'shipping-method',
                                'html' => $this->_getShippingMethodsHtml()
                            );
                        }
                }

                $this->getResponse()->setBody(Zend_Json::encode($result));
            }
        }
于 2011-12-06T01:36:07.183 に答える