1

I am looking for a solution to modify Magento 1.9.3 in order to calculate the shipping cost according to City when checkout. Could anyone give me some pointers?

  • Which shipping method used ? – Suresh Chikani Nov 10 '16 at 17:58
  • It depends on shipping method you use – Gopal Patel Nov 10 '16 at 18:00
  • are you using onepage checkout ? – Ahsan Horani Nov 11 '16 at 6:13
1

UPS and FedEx shipping methods both calculate the cost of the shipping based on the zip code.

If you are using flat rate or matrix shipping, you would need to calculate this yourself.

0

You can use event/observers approach for this.

  1. Create a hook on the event sales_quote_address_collect_totals_after e.g.

    <events>
        <sales_quote_address_collect_totals_after>
            <observers>
                <meteorify_observerexample_model_observer>
                    <type>singleton</type>
                    <class>Meteorify_Observerexample_Model_Observer</class>
                    <method>setShippingCost</method>
                </meteorify_observerexample_model_observer>
            </observers>
        </sales_quote_address_collect_totals_after>
    </events>
    
  2. Below function is the example to set shipping price based on any logic you apply, write this function in your observer model class:

    public function setShippingCost($observer)
    {
        $events = $observer->getEvent();
        $address = $events->getQuoteAddress();
    
        if ($address->getAddressType() == 'shipping') {
            //Here you can get all shipping information on checkout 
            $shippingInfo = $events->getQuoteAddress()->getData();
            $price = 0;
    
            $address->setShippingAmount($price);
            $address->setBaseShippingAmount($price);
            $address->save();
            // Find if our shipping has been included.
            $rates = $address->collectShippingRates()
                ->getGroupedAllShippingRates();
    
            foreach ($rates as $carrier) {
                foreach ($carrier as $rate) {
                    $rate->setPrice($price);
                    $rate->save();
                    // print_r($rate->getPrice());
    
                }
            }
    
            $address->setCollectShippingRates(true);
        }
    }
    
0

You can use default shipping method "Table Rate" for this.

In this shipping method you can import CSV file for that zip codes. and set your rates and shipping label there.

OR

You can use web shop matrix shipping method for this. Both are same in functionality of working.

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.