title: getRate() and Magento tax percentage
body: <p>I'm trying to get the tax rate (percentage, not currency) for a given postcode so I can display it in a third-party quote PDF printout (no relation to the "quote" Magento uses as the shopping cart pre-checkout).  While I'm still relatively new to Magento it appears that getRateRequest() and getRate() are the two main functions which get the tax rate based on all the variables (product tax class, customer tax class, etc.).</p>
  
  <p>Since this is for a third-party extension and all our products are taxable I figured I would just use getRate() with the correct Varien Object input and it would return the tax rate.  After a week of trial and error I can't figure out why I'm always getting a rate of zero.  I've confirmed I'm calling the getRate() function and that it's not returning zero from the first if() statement checking for Country and Customer/Product class ID.  In addition I've confirmed all the variables are being passed on and accessible in the getRate() function itself.</p>
  
  <p>I've created an object with the below input (based on the output of getRateRequest()) that I call with getRate() and am hoping someone can shed light on what is wrong with my data input or why the getRate() function is always returning a result of zero.  (I'm actually setting with $variables below, they are just defined earlier up and one of my test case values are below)</p>
  
  <pre><code>    // UPDATED CODE (variable values come from 3rd party quote extension)
  
      $country = 'US';  // use short country code
      $region = '12';   // must be numeric!
      $postcode = '95050';
      // our quote extension stores the customer id ('2') which we use to get the tax class
      $customer = Mage::getModel('customer/customer')-&gt;load( '2' );
      $custTax = $customer-&gt;getTaxClassId();
  
      $TaxRequest  = new Varien_Object();
      $TaxRequest-&gt;setCountryId( $country );
      $TaxRequest-&gt;setRegionId( $region );
      $TaxRequest-&gt;setPostcode( $postcode );
      $TaxRequest-&gt;setStore( Mage::app()-&gt;getStore() );
      $TaxRequest-&gt;setCustomerClassId( $custTax );
      $TaxRequest-&gt;setProductClassId(2);  // 2=taxable id (all our products are taxable)
  
      $taxCalculationModel = Mage::getSingleton('tax/calculation');
      $rate = $taxCalculationModel-&gt;getRate($TaxRequest);
  </code></pre>
  
  <p>My backup plan is to just do a direct SQL lookup formula although that will probably get a bit messy.  Since our web development team didn't exactly follow good coding standards an eventual site re-write is in my future anyway once the initial launch fixes are in (all 4 pages of them).</p>
  
  <p>Thanks for any help and taking the time to read this.</p>
  
  <p>EDIT - Stack Overflow is awesome :)</p>