1

I have several shipping methods. And each method has own rates. But I cannot get it while the user enters his address.

I would like to get all active shipping methods and their rates. After user selected shipping methods he should select payment method (depends on shipping method) and fill his address fields (fields also depends on shipping method).

To get all shipping methods is simply enough:

$methods = Mage::getSingleton('shipping/config')->getActiveCarriers();

But to get its rates without address - a little bit complex.

Any ideas on how to solve it?

Perhaps someone could recommend some modules.

2

I don't know any module, however you could find a way to include or reorder the checkout process as explained below. It could help you to develop a solution.

I wanted one day add a step in the middle of the checkout process. At the moment, there is no official way to do it, I mean you don't have any events which allows to change the behavior.

The solution I found consist to modify the class Mage_Checkout_Block_Onepage_Abstract. Attention, it's not a classic model, it's an abstract, you can't overwrite it by using the tag <rewrite> in config.xml file.

So, you have to copy the file app/code/core/Mage/Checkout/Block/Onepage/Abstract.php to app/code/local/Mage/Checkout/Block/Onepage/Abstract.php, edit the file by adding (if you use Magento 1.5) or editing (if you use Magento >= 1.6), the method _getStepCodes as showned below. In this case, you can change the order of the steps, add your own or remove steps. Take care of the consequences of such changes.

abstract class Mage_Checkout_Block_Onepage_Abstract extends Mage_Core_Block_Template {
...
/**
 * Get checkout steps codes
 * diglin - method took from Magento 1.6 but add a dispatch and $transport to allow to hook the code
 * 
 * @return array
 */
protected function _getStepCodes()
{
    $data = new Varien_Object();
    $data->setStepCodes(array('login', 'billing', 'shipping', 'shipping_method', 'payment', 'review'));

    Mage::dispatchEvent('checkout_onepage_stepcodes', array('transport' => $data));

    return $data->getStepCodes();
}
}

EDIT

The code I provide here was a code proposed to Magento core team to allow customized steps, that's one of the reason why the Mage namespace and the Abstract are used.

The block checkout/onepage class is also rewritten:

class Mage_Checkout_Block_Onepage extends Mage_Checkout_Block_Onepage_Abstract
{

/**
 * Get 'one step checkout' step data
 *
 * @return array
 */
public function getSteps()
{
    $steps = array();
    $stepCodes = $this->_getStepCodes();

    if ($this->isCustomerLoggedIn()) {
        $stepCodes = array_diff($stepCodes, array('login'));
    }

    foreach ($stepCodes as $step) {
        $steps[$step] = $this->getCheckout()->getStepData($step);
    }

    return $steps;
}

public function getActiveStep()
{
    // diglin - add the $stepCodes to provide custom step
    $stepCodes = $this->_getStepCodes();
    return $this->isCustomerLoggedIn() ? $stepCodes[1] : $stepCodes[0]; //custom / billing Step or Login Step 
}
  • Instead of monkey patching the abstract class I'd prefer rewriting the "checkout/onepage" class (which extends the abstract one) and overriding the getSteps() method. – Alessandro Ronchi Jan 30 '13 at 11:31
  • @SylvainRayé ...and shipping_method doesn't work then, because it hasn't customer address yet. Just it's a problem I described above-) – Anthony Jan 30 '13 at 11:36
  • @AlessandroRonchi I agree, this is what I did first but I got problems with something else, I don't remember what. There is a reason behind why I did so otherwise I would do as you explained. In fact, I see that my code is not complete I have also rewritten the 'checkout/onepage' class as you suggested. I update the answer. – Sylvain Rayé Jan 30 '13 at 14:54
  • @Anthony the idea here is to insert a step where you wish. It doesn't resolve your problem completely, I agree. But how a carrier can calculate how much does it costs if he doesn't know where to send it? if you wish to do so, you need a minimum of information, in any case you will have to provide your own step with your own logic, purpose of my answer. – Sylvain Rayé Jan 30 '13 at 15:07
1

In Magento shipping rates are stored against the quote_address object. So unless you implement your own mechanism or stub the address then you will struggle. Possible to do but a fair bit of work.

0

Along with the GeoIP idea you could use this extension from @Tim:

https://github.com/openstream/geoip

Making use of his code you could modify the Lazzymonk's Auto Quote to apply a default shipping method based on this locale. Note: I have had much success with this module from 1.1 through 1.11 EE, not sure about the reviews here.

http://www.magentocommerce.com/magento-connect/lazzymonks-auto-apply-default-shipping-for-1-1.html

Another alternative

Rather than beginning checkout, possibly you could have a zipcode entry field in the totals section of the shopping cart that they could fill in, which would expand and reveal shipping methods of their choosing.

Just because I'm curious - what is the impetus here? Are you trying to lower abandonment or increase conversion?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.