Cart Shipping Methods – How to Select Default Shipping Method

cartonepage-checkoutshippingshipping-methods

I have various shipping methods configured and would like to select a default one based on country of the visitor or something.

For example if the user is from Spain (Or spanish Locale) then default shipping is … and if from another country then International shipping.

Can anybody help me out here? I don't have a clue where to start.

Also I want it to be applied by default, because we have an PayPal express checkout and if I click on it without entering the cart and selecting the Shipping method from the Estimate section, the shipping cost's are not applied when Paying by PayPal… This is a problem..

Thanks,

Best Answer

You need to create your custom shipping method.

To do so, create a custom class extended from Mage_Shipping_Model_Carrier_Abstract, and start writing your business logic code inside overloaded collectRates method.

class Arturas_CountryBasedShipping_Model_Shipping_Carrier_ShippingMethod extends Mage_Shipping_Model_Carrier_Abstract {

    protected $_code = 'countrybasedshipping';

    public function collectRates(Mage_Shipping_Model_Rate_Request $request) {
        // skip if not enabled
        if( !Mage::getStoreConfig( 'carriers/' . $this->_code . '/active' ) ) {
            return false;
        }

        // Fetching a country based price
        $cb_price = $this->getCountryShippingPrice( $request->getDestCountryId() );

        $result   = Mage::getModel('shipping/rate_result');
        $method   = Mage::getModel('shipping/rate_result_method');

        $method->setCarrier($this->_code);
        $method->setMethod($this->_code);
        $method->setMethodTitle('Contry Based Shipping');
        $method->setCost($cb_price);
        $method->setPrice($cb_price);

        $result->append($method);

        return $result;
    }
}

You also may want to read this article.

Related Topic