This is the blog for getting Idea regarding PHP, Magento, jQuery and JavaScript for Customization.

Thursday 3 January 2013

Magento : Remove Shipping Method form Checkout

Hi,

  If in any case need to remove the Shipping Method from the site, then Now easily remove that by macking change in  following steps,

  For Remove Shipping Methods you need to change its function 

  This code is working for me in 1.7.0.2 but you can try this for older version also

A)  Open Mage/checkout/controllers/Onepagecontroller.php

     In this File Go to on  "function saveBillingAction() "

    Check this line in this function and change

     From

       elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1) {
                    $result['goto_section'] = 'shipping_method';
                    $result['update_section'] = array(
                        'name' => 'shipping-method',
                        'html' => $this->_getShippingMethodsHtml()
                    );

     To

       elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1) {
                    $result['goto_section'] = 'payment';
                    $result['update_section'] = array(
                        'name' => 'payment-method',
                        'html' => $this->_getPaymentMethodsHtml()
                    );

 B)  Now, In Onepagecontroller.php

   Go to on this function  "public function saveShippingAction()"

  change this function

  From

   public function saveShippingAction()
    {
        if ($this->_expireAjax()) {
            return;
        }
        if ($this->getRequest()->isPost()) {
            $data = $this->getRequest()->getPost('shipping', array());
            $customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
            $result = $this->getOnepage()->saveShipping($data, $customerAddressId);

            if (!isset($result['error'])) {
                $result['goto_section'] = 'shipping_method';
                $result['update_section'] = array(
                    'name' => 'shipping-method',
                    'html' => $this->_getShippingMethodsHtml()
                );
            }
            $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
        }
    }      


To

public function saveShippingAction()
    {
        if ($this->_expireAjax()) {
            return;
        }
        if ($this->getRequest()->isPost()) {
            $data = $this->getRequest()->getPost('shipping', array());
            $customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
            $result = $this->getOnepage()->saveShipping($data, $customerAddressId);

            if (!isset($result['error'])) {
                $result['goto_section'] = 'payment';
                $result['update_section'] = array(
                    'name' => 'payment-method',
                    'html' => $this->_getPaymentMethodsHtml()
                );
            }
            $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
        }
    }


C) After that Open Code/core/mage/sales/model/service/Quote.php

  Find this function " protected function _validate() "

  Here comment below code

  if ($addressValidation !== true) {
                Mage::throwException(
                    Mage::helper('sales')->__('Please check shipping address information. %s', implode(' ', $addressValidation))
                );
            }
            $method= $address->getShippingMethod();
            $rate  = $address->getShippingRateByCode($method);
            if (!$this->getQuote()->isVirtual() && (!$method || !$rate)) {
                Mage::throwException(Mage::helper('sales')->__('Please specify a shipping method.'));
            }

D) Open file code/core/mage/checkout/block/onepage/shipping/Method.php

   This is hide the Shipping Method tab from the Onepage checkout during Place the order

   Find below function

    public function isShow()
    {
        return !$this->getQuote()->isVirtual();
    }

   Change it with

    public function isShow()
    {
                return false;
    }


   Now, Finally you can check that your Shipping Method will remove from your site.

  Enjoy ::





,

4 comments:

  1. But After that when i press continue. it's didnt go ahead.. please help me

    ReplyDelete
  2. Thanks Admin,
    It's working fine...thanks dude....cheers :)

    ReplyDelete
  3. Hi Rajeshwari,

    After making the changes Are you clear all the Cache and Index Management also.

    ReplyDelete