Meganto : Get the Shipping Method Chosen by User During Checkout

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(); ).

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:

Resource: Stackoverflow

Leave a Reply

Your email address will not be published. Required fields are marked *