title: How to auto fill shipping method Magento for onepagechekout
body: <p>I want to auto fill the shipping method automatically and not show it on the onepage checkout. I was able to hide the shipping method on my Onepagechekout by changing this on <strong>app/code/local/Mage/Checkout/controllers/OnepageController.php</strong>:</p>
  
  <pre><code>/**
   * save checkout billing address
   */
  public function saveBillingAction()
  {
      if ($this-&gt;_expireAjax()) {
          return;
      }
      if ($this-&gt;getRequest()-&gt;isPost()) {
  //            $postData = $this-&gt;getRequest()-&gt;getPost('billing', array());
  //            $data = $this-&gt;_filterPostData($postData);
          $data = $this-&gt;getRequest()-&gt;getPost('billing', array());
          $customerAddressId = $this-&gt;getRequest()-&gt;getPost('billing_address_id', false);
  
          if (isset($data['email'])) {
              $data['email'] = trim($data['email']);
          }
          $result = $this-&gt;getOnepage()-&gt;saveBilling($data, $customerAddressId);
  
          if (!isset($result['error'])) {
              /* check quote for virtual */
              if ($this-&gt;getOnepage()-&gt;getQuote()-&gt;isVirtual()) 
              {
                  $result['goto_section'] = 'payment';
                  $result['update_section'] = array(
                      'name' =&gt; 'payment-method',
                      'html' =&gt; $this-&gt;_getPaymentMethodsHtml()
                  );
              } elseif (isset($data['use_for_shipping']) &amp;&amp; $data['use_for_shipping'] == 1) 
                {
                  $result['goto_section'] = 'payment';
                  $result['update_section'] = array(
                      'name' =&gt; 'payment-method',
                      'html' =&gt; $this-&gt;_getPaymentMethodsHtml()
                  );
  
                  $result['allow_sections'] = array('shipping');
                  $result['duplicateBillingInfo'] = 'true';
              } else {
                  $result['goto_section'] = 'shipping';
              }
          }
          $this-&gt;saveShippingMethodAction();
          $this-&gt;getResponse()-&gt;setBody(Mage::helper('core')-&gt;jsonEncode($result));
      }
  }
  </code></pre>
  
  <p>As you can see I changed the link where I redirect the next step after billing action to the payment step. </p>
  
  <p>In order to auto-save a shipping method, I added </p>
  
  <pre><code>$this-&gt;saveShippingMethodAction();
  </code></pre>
  
  <p>at the end of the function, and this method looks like here:</p>
  
  <pre><code>    public function saveShippingMethodAction()
  {
      $this-&gt;_expireAjax();
      if ($this-&gt;getRequest()-&gt;isPost()) {
          /* $this-&gt;savePaymentAction(); */
          $data = $this-&gt;getRequest()-&gt;getPost('shipping_method', 'flatrate_flatrate');
          $result = $this-&gt;getOnepage()-&gt;saveShippingMethod($data);
             $this-&gt;getResponse()-&gt;setBody(Zend_Json::encode($result));
      }
  
  }
  </code></pre>
  
  <p>So what I did is try to include automatically <strong>flatrate_flatrate</strong> method as the default one. </p>
  
  <p>But when I try to finish a sale, it says I didn't specify a shipping method. Any idea on why it doesn't work?</p>