如何获取用户在结账时选择的送货方式?
我想获取用户在结账时选择的运输方式的名称。有谁知道如何检索该信息?
这将在一定程度上得到它,但它会被缓存:
Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingDescription();
当我进行一步结帐时,我返回到运输选项卡并更改运输,它仍然保留旧的运输方法。我需要弄清楚如何获得当前的。
I want to get the name of the shipping method the user has chosen during checkout. Does anyone know how to retrieve that info?
This will get it to some extent but it is cached:
Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingDescription();
When I am on the onestep checkout and I go back to the shipping tab and change the shipping, it is still holding the old shipping method. I need to figure out how to get the current one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
前言
由 Magento app/code/core/Mage/Checkout/Block/Onepage/Shipping/Method/Available.php 和其他内容构建:
app/design/frontend/base/default/template/ checkout/onepage/shipping_method/available.phtml 使用此代码来确定选择哪种送货方式:
app/code/core/Mage/Checkout/Block/Onepage/Shipping/Method/Available.php strong> 将该代码扩展为:
让我们研究一下并更深入地扩展它:
父块扩展方法 getQuote():
更深入:
合并所有代码给我们这个:
这给你 运输方式代码。有了这个,你就可以按照你的意愿操纵它。此数据存储在数据库中,因此当您更改运输方式时,代码也会更改。
越来越深!
如果您曾经创建过自己的送货方式,您就会知道它有一个名为collectRates()的方法。
它填充一组 shipping/rate_result_method 模型,将其存储在 shipping/rate_result 模型的实例中并返回它(您可以使用 Mage 获取每个模型的实例) ::getModel(<我命名的模型>); )。
但是,请注意:一个实例可以包含多个 rate_result_method 实例,而所有这些实例的运输方式代码都是相同的!
因此,为了获取描述,您需要获取 rate_result_method 实例之一并检索其 methodTitle 或 rierTitle。
经过一番小研究后,我找到了如何检索所有这些费率:
这将为您提供所选运输方式的所有费率的集合。您可以使用 getItems() 对其进行操作并获取哈希值。或者您可以使用 getFirstItem() 并将其用作模板。
不管怎样,我们假设您已经检索了该集合中的某些项目并将其存储在 $rate 变量中:
就是这样,伙计们!
我真的很抱歉我糟糕的英语和我奇怪的思维方式。希望这会对您或其他人有所帮助。谢谢!
Foreword
Constructed from Magento app/code/core/Mage/Checkout/Block/Onepage/Shipping/Method/Available.php and others:
app/design/frontend/base/default/template/checkout/onepage/shipping_method/available.phtml uses this code to determine which shipping method was selected:
app/code/core/Mage/Checkout/Block/Onepage/Shipping/Method/Available.php expands that code to this:
Let's research a bit and expand it even deeper:
Parent block expands method getQuote():
And deeper:
Merging all that code gives us this:
That gives you the shipping method code. Giving that, you could manipulate it just as you wish. This data is stored within the database, so when you change shipping method, the code changes too.
Getting deeper and deeper!
If you've ever created your own shipping method, you'd know, that it has the method called collectRates().
It fills a set of shipping/rate_result_method models, stores it within the instance of shipping/rate_result model and returns it (you can get each model' instance using Mage::getModel(<model i've named>); ).
Yet, note: one could contain multiple rate_result_method instances, while the shipping method code is the same for all those instances!
Thus, in order to get the description, you need to get one of the rate_result_method instances and retrieve its methodTitle or carrierTitle.
After a small researching i've found how to retrieve all these rates:
This will provide you with a collection of all rates for the selected shipping method. You can operate it with getItems() and get a hash. Or you could use getFirstItem() and use it as the template.
Anyway, let's assume u've retrieved some item of that collection and stored it within the $rate variable:
That's all, folks!
I am really sorry for my poor English and for my strange mind flow. Hope this will help you or someone else. Thanks!
以防万一您仍然需要它。您可以从 order by 获取运输方式:
当然,您如何获取 $order 取决于上下文。
您还可以通过以下方式获取描述:
Just in case you need it still. You can get shipping method from order by:
Of course how you get your $order depends on context.
Also you can get description by:
如果您希望能够访问此信息,则需要在结帐控制器中添加额外的步骤来保存报价。
我添加了一些 '$quote->save();'然而,我不能明确地说哪个条目是修复该问题的条目。我在 Magento 论坛上也找不到该链接,但是,我希望我已经让您对正在发生的事情有了一个良好的开端。
In your checkout controller you need to add extra steps to save your quote if you want this information to be accessible to you.
I added a few '$quote->save();' entries to get this to work, however, I cannot definitively say which entry is the one that did the fix. I also cannot find the link on Magento forums, however, I hope I have given you a head start on what is going on.
您可以重写
Mage_Checkout_OnepageController
中的saveShippingMethodAction()
函数,或对其进行扩展,然后通过插入以下内容将该方法保存到注册表中:并在需要时调用它:
Mage::registry('blahShippingMethod');
当您不再需要它时,不要忘记取消设置它,因为如果您尝试在以下情况重置,您将遇到错误它已经被设置了。
You could override the
saveShippingMethodAction()
function in theMage_Checkout_OnepageController
, or extend upon it, and save the method into the registry by inserting:and call upon it as you need it:
Mage::registry('blahShippingMethod');
Don't forget to unset it when you no longer need it as you will run into an error if you try to reset when it's already been set.