2

I have only one shipping method - Table rate on which I calculate two different aspects.

  1. for over $200 - shipping price will be $0.00 that is free.
  2. below $200 is $9.50.

Now I get these calculation processed only after I trigger estimate shipping form or co-shipping form. Is that possible to load the shipping fee automatically once the page loads? and show up the result on cart total box.

1

I just send the co-shipping-method-form details via ajax submission on page load. this helped me to calculate the shipping Fee automatically without the estimate shipping and update total things. code what I used to trigger the form is below hope this will help someone.. also if this method is not good to use please guide me on this.

<script type="text/javascript">
        (function($){
            $(document).ready(function() {

                var currentRequest = null;
                var url = "<?php echo $this->getUrl('checkout/cart/estimateUpdatePost') ?>"; // co-shipping-method-form action url.
                var data = $("#co-shipping-method-form");
                $("#process").show(); // shows loading

                currentRequest =$.ajax({
                  type: "POST",
                  data: data.serialize(),
                  dataType: "html",
                  url: url,
                  beforeSend : function(){           
                        if(currentRequest != null){
                            currentRequest.abort();
                        }
                   },
                  success: function(response){ 
                      //console.log(response);
                      // find element with class name .cart-totals
                      var result = $('.cart-totals', response)

                      //console.log(result);
                      // replace with original
                      $(".cart-totals-wrapper").html(result); 

                      $("#process").hide("slow"); // hide loading
                   },
                  });    
                return false;    
            });
        })(jQuery);
    </script>
0

Inorder to add shipping charge automatically to cart page, use the magento extension https://www.magentocommerce.com/magento-connect/auto-shipping-pro.html . Its really awesome and works like a charm. [enter link description here][1]

0

The shipping totals in the cart are shown as soon as the quote has a shipping address with country and a shipping method has been selected, because the calculation is based on the country and there might be different methods available.

You need to add a dummy address with the default country and automatically select the first available shipping address when on the cart page.

We have an open source extension on GitHub for this: https://github.com/integer-net/AutoShipping

It also solves quite some special cases, like shipping rates that depend on the items in the cart, free shipping rules etc. - too much to fit into this answer.

0

For that you have to work with observer and used checkout_cart_save_after event and paste this below code in the observer file that you created:

private $_shippingCode = 'flatrate_flatrate';
private $_country = 'GB';

public function addShipping($params = null) {
    if (Mage::registry('checkout_addShipping')) {
        Mage::unregister('checkout_addShipping');
        return;
    }

    Mage::register('checkout_addShipping',true);

    $cart = Mage::getSingleton('checkout/cart');
    //zend_debug::dump($cart->getData());exit;
    $quote = $cart->getQuote();

    if ($quote->getCouponCode() != '') {
        $c = Mage::getResourceModel('salesrule/rule_collection');
        $c->getSelect()->where("code=?", $quote->getCouponCode());
        foreach ($c->getItems() as $item) { $coupon = $item; }

        if ($coupon->getSimpleFreeShipping() > 0) {
            $quote->getShippingAddress()->setShippingMethod($this->_shippingCode)->save();
            return true;
        }
    }

    try {

        //$method = $quote->getShippingAddress()->getShippingMethod();

        //if ($method) return; // don't overwrite what's already there if we have one set already

        if ($quote->getShippingAddress()->getCountryId() == '') {
            $quote->getShippingAddress()->setCountryId($this->_country);
        }

        $quote->getShippingAddress()->setCollectShippingRates(true);
        $quote->getShippingAddress()->collectShippingRates();

        $rates = $quote->getShippingAddress()->getAllShippingRates();
        $allowed_rates = array();
        foreach ($rates as $rate) {
            array_push($allowed_rates,$rate->getCode());
        }

        if (!in_array($this->_shippingCode,$allowed_rates) && count($allowed_rates) > 0) {
            $shippingCode = $allowed_rates[0];
        }

        //zend_debug::dump(Mage::getSingleton('checkout/session')->getQuote()->getGrandTotal());exit;
        //if(Mage::helper('checkout')->getQuote()->getData('subtotal')<=49){
            $totals = Mage::getSingleton('checkout/cart')->getQuote()->getTotals();
            $finaltotal = $totals["subtotal"]->getValue();

         // zend_debug::dump($sample);exit;
            //zend_debug::dump($finaltotal);exit;
            if($finaltotal<=49){
        if (!empty($shippingCode)) {
            $address = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress();
            if ($address->getCountryId() == '') $address->setCountryId($this->_country);
            if ($address->getCity() == '') $address->setCity('');
            if ($address->getPostcode() == '') $address->setPostcode('');
            if ($address->getRegionId() == '') $address->setRegionId('');
            if ($address->getRegion() == '') $address->setRegion('');
            $address->setShippingMethod($this->_shippingCode)->setCollectShippingRates(true);
            Mage::getSingleton('checkout/session')->getQuote()->save();
        } else {
            $address = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress();
            if ($address->getCountryId() == '') $address->setCountryId($this->_country);
            if ($address->getCity() == '') $address->setCity('');
            if ($address->getPostcode() == '') $address->setPostcode('');
            if ($address->getRegionId() == '') $address->setRegionId('');
            if ($address->getRegion() == '') $address->setRegion('');
            $address->setShippingMethod($this->_shippingCode)->setCollectShippingRates(true);
            Mage::getSingleton('checkout/session')->getQuote()->save();
        }
    }
        else{

                if (!empty($shippingCode)) {
            $address = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress();
            if ($address->getCountryId() == '') $address->setCountryId($this->_country);
            if ($address->getCity() == '') $address->setCity('');
            if ($address->getPostcode() == '') $address->setPostcode('');
            if ($address->getRegionId() == '') $address->setRegionId('');
            if ($address->getRegion() == '') $address->setRegion('');
            $address->setShippingMethod('freeshipping_freeshipping')->setCollectShippingRates(true);
            Mage::getSingleton('checkout/session')->getQuote()->save();
        } else {
            $address = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress();
            if ($address->getCountryId() == '') $address->setCountryId($this->_country);
            if ($address->getCity() == '') $address->setCity('');
            if ($address->getPostcode() == '') $address->setPostcode('');
            if ($address->getRegionId() == '') $address->setRegionId('');
            if ($address->getRegion() == '') $address->setRegion('');
            $address->setShippingMethod('freeshipping_freeshipping')->setCollectShippingRates(true);
            Mage::getSingleton('checkout/session')->getQuote()->save();
        }
        }

        Mage::getSingleton('checkout/session')->resetCheckout();

    }
    catch (Mage_Core_Exception $e) {
        Mage::getSingleton('checkout/session')->addError($e->getMessage());
    }
    catch (Exception $e) {
        Mage::getSingleton('checkout/session')->addException($e, Mage::helper('checkout')->__('Load customer quote error'));
    }


}

It worked for me when checkout cart subtotal is less than 49.

If so it displays free shipping otherwise displays flat rate charge.

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.