iamjonesy
iamjonesy

Reputation: 25122

Magento: Show both incl AND excl. VAT prices for single product

I have created a custom Yes/No attribute for products that will determine whether or not to show the products price including and excluding VAT or just including (my default). This is possible with Magento but not for specific products. I've had to hack around the price.phtml file to get both prices to show by changing:

<?php if ($_taxHelper->displayBothPrices()): ?>

To:

<?php if ($_taxHelper->displayBothPrices() || $_product->getData('show_both_prices')): ?>

This will now show the price formatted to the show both format. i.e

Excl. Tax: £856.80

Incl. Tax: £856.80

However, you can see the price calculation is not actually done as the including VAT price is shown for both.

I have tracked this down to a piece of code in the tax helper (app/code/Mage/Tax/Helper/Data.php)

if ($percent != 0) {
    $price = $this->getCalculator()->round($price); // price = 714
    // price changes from the excl VAT to including VAT on line below.
    $price = $this->_calculatePrice($price, $percent, true); // now 856.8
}

This is the function that seems to be changing the price. Tried passing in FALSE instead of true but it seems to then get treated as a special price product somehow :S

protected function _calculatePrice($price, $percent, $type)
{
    if ($type) {
        return $price * (1+($percent/100));
    } else {
        return $price/(1+$percent/100);
    }
}

I need to somehow mimic how the "show both prices" code works, so far anything I have tried hasn't worked. Any help most appreciated!

Upvotes: 0

Views: 8306

Answers (1)

Theodores
Theodores

Reputation: 1209

I would avoid getting too far into the price code rendering block as it is complicated to work out what is going on there.

You can set the frontend to show prices - both - with system->config->tax->price display settings.

Now you can see if your prices are coming through correctly. If not then check your Tax/VAT setup and rates.

With that resolved you can look into trying a different approach to selectively show/hiding the inc/ex options. This can be done in CSS if you selectively add a class to the category listing and product pages. In list/view pages put something like this where the li tag class is:

if($_item->getWhatever()==1) echo 'whatever'

Then in the css:

.whatever .price-excluding-tax {display:none;}

with this class depending on your attribute. Sure you are only hiding the ex-VAT prices, however I doubt anyone will care to notice.

Upvotes: 4

Related Questions