問題描述
我正在事件 checkout_controller_onepage_save_shipping_method 期間驗證運輸報價,如果驗證失敗,我想將用戶發送回運輸方式選擇,但我還想顯示一條消息,說明失敗的原因.Magento 有內置的方法嗎?
I am verifying shipping quotes during the event checkout_controller_onepage_save_shipping_method and if the verification fails i want to send the user back to shipping method selection but I would also like to display a message saying why it failed. Does Magento have a way of doing this built in?
我已經在驗證數據,只是缺少重定向到運輸方式和顯示消息的方式.
I am already verifying the data I just lack the redirect to shipping methods and way to display a message.
推薦答案
Alan Storm 的回答一如既往地內容豐富且具有啟發性.但是在這種情況下,單頁結帳主要是 AJAX,它會忽略會話錯誤消息,直到離開結帳頁面才能看到它.
Alan Storm's answer is, as ever, informative and enlightening. But in this situation the onepage checkout is mostly AJAX which ignores the session error message, you won't see it until leaving the checkout page.
在 saveShippingMethodAction
中有如下一行:
$result = $this->getOnepage()->saveShippingMethod($data);
...然后 $result 是 JSON 編碼的.如果您覆蓋 Mage_Checkout_Model_Type_Onepage::saveShippingMethod
以執行檢查,然后控制返回的內容,您可以插入一條錯誤消息,該消息將返回到瀏覽器并在彈出窗口中顯示給用戶.
...and then $result is JSON encoded. If you override Mage_Checkout_Model_Type_Onepage::saveShippingMethod
to perform your check then control what is returned you can insert an error message that will be returned to the browser and shown to the user in a popup.
您的覆蓋可能如下所示:
Your override might look something like this:
public function saveShippingMethod($shippingMethod)
{
if ($this->doesntApplyHere()) {
return array('error' => -1, 'message' => $this->_helper->__('Explain the problem here.'));
}
return parent::saveShippingMethod($shippingMethod);
}
這篇關于停止從 Magento 中的事件觀察者結賬的正確方法是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!