1

I'm writing a custom .phtml file for a CMS page, in which a list of products is shown with the price of the item, including GST (10%). I've got the items and the prices being output to a table, yet I can't get the tax-inclusive price.

I've read all over the internet that there's two main ways to get tax-inclusive prices:

Mage::helper('core')->currency($product->getFinalPrice())

Mage::helper('tax')->getPrice($product, $product->getFinalPrice(), 2)

Yet trying both of these, all I can get is the ex-GST amount. Tax is set up, and shows on catalog pages, yet no matter what I do I can't get it to show on a CMS page. The code below is what I have on my page, and you can see I've been trying all sorts of combinations with getPrice, getFinalPrice, etc, but it just won't print anything except the exclusive price. Any suggestions would be great.

function construct($catID) {
 /* load product collection */
    $categoryId = Mage::getModel('catalog/category')->load($catID);
    $products = Mage::getModel('catalog/product')->getCollection();
    $products->addCategoryFilter($categoryId)->addAttributeToSelect(array('sku','name','price'))->load();
    ?>
    <div class="productTable" id="<?php echo $categoryId->getName(); ?>">
      <?php echo "<h3>".$categoryId->getName()."</h3>"; ?>
      <table class="table table-bordered table-condensed">
        <tr>
          <th>Product Name</th>
          <th>Price</th>
        </tr>
        <?php
        foreach ($products as $product) {
          $name = $product->getName();
          $sku = $product->getSku();
          $price = Mage::helper('core')->currency($product->getFinalPrice());
          ?>
          <tr>
            <td><?php echo $name; ?></td>
            <td>
              <?php echo Mage::helper('core')->currency($product->getFinalPrice()); ?>
              <?php echo Mage::helper('tax')->getPrice($product, $product->getFinalPrice(), 4);?>
              <?php echo Mage::helper('tax')->getPrice($product, $product->getFinalPrice(), true);?>
              <?php echo Mage::helper('tax')->getPrice($product, $product->getFinalPrice(), false);?>
              <?php echo Mage::helper('tax')->getPrice($product, $product->getFinalPrice());?>
              <?php echo $product->getFinalPrice();?>

            </td>
          </tr>

          <?php
        }
        echo "</table></div>";
      } /* end construct */

  $cpuID = 22;
  $memoryID = 23;
  $gpuID = 27;
  $caseID = 19;

  construct($cpuID);
  construct($memoryID);
  construct($gpuID);
  construct($caseID);


  ?>

1 Answer 1

2

I believe the issue here is that there is no sales quote address available. In order to calculate sales tax (including GST) you need a shipping address available. (It can also be set to billing regions - see System > Configuration > Tax).

Debug:

First, try starting a cart (Sales Quote) and proceeding to checkout (Onepage) and move through past the shipping method selection. In the review screen, if configured properly, it should display tax totals.

After this, refresh your script and getFinalPrice should display the correct price.

What's happening?

The lack of a shipping address means no tax rates are being calculated when you call your standalone script. That means each customer would have to either give you their eventual shipping destination upon arrival at your site (yeah, right) or proceed beyond the shipment method selection in checkout -> at that point in the conversion funnel they've probably already made the decision to purchase, right?

So, to circumvent this restriction, consider using a plugin that will default quote values to a preselected shipping address within the locale that you're trying to display tax-inclusive rates for.

One such extension used to exist on Magento Connect but has since been de-listed. I have preserved it on Github:

https://github.com/philwinkle/Mage_Autoquote

3
  • Thanks so much for the answer - but how does the Catalog get prices including tax without a shipping address?
    – Ben Harris
    Commented Jul 12, 2013 at 4:25
  • Registered customer only feature I believe? I don't think it works the way you're envisioning it. A shipping destination is required for tax calculations.
    – philwinkle
    Commented Jul 12, 2013 at 4:50
  • Our website shows GST included into all prices when you go to it - exclusive prices in the backend, but the frontend gets marked up 10% automatically, regardless of if a user is logged in or not.
    – Ben Harris
    Commented Jul 12, 2013 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.