VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: Genius WebDesign on October 29, 2014, 21:31:23 PM

Title: Trying to locate JS that updates cart module prices
Post by: Genius WebDesign on October 29, 2014, 21:31:23 PM
Hi,

My client has a shop that is primarily for business customers, so he wants to show all prices "without tax", also in the cart module.
Out of the box there are no option to set the the cart module to show prices without tax, so I guess I need to locate the JS responsible for updating the cart prices.

Can anyone tell me which JS file I need to look into for this?
Title: Re: Trying to locate JS that updates cart module prices
Post by: AH on October 29, 2014, 22:58:59 PM
I am using VM2.9 - but this should be VERY similar for 2.6 versions as well

You can show prices without tax

But you have to do a template override to: \modules\mod_virtuemart_cart\tmpl\default.php

<div class="subtotal_with_tax" style="float: right;"><?php echo $product['subtotal_with_tax'] ?></div>
becomes
<div class="subtotal_with_tax" style="float: right;"><?php echo $product['subtotal'] ?></div>


This leaves you with the issue that there is no Cart total variable that excludes tax for the minicart

In components/com_virtuemart/helpers/cart.php

function prepareAjaxData

$data->billTotal = $currencyDisplay->priceDisplay( $this->cartPrices['billTotal'] );
        //Quorvia Provide ex-tax prices to minicart
        $data->billTotal_tax_amount = $currencyDisplay->priceDisplay( $this->cartPrices['taxAmount'] );
        $data->billTotal_net = $currencyDisplay->priceDisplay( $this->cartPrices['priceWithoutTax'] );
        $data->billTotal_discounted_net = $currencyDisplay->priceDisplay( $this->cartPrices['discountedPriceWithoutTax'] );
        //end

You can then change the \modules\mod_virtuemart_cart\tmpl\default.php
<?php echo $data->billTotal; ?>

To
<?php echo $data->billTotal_net; ?>

Hope this puts you on the right track

NOTE

The components/com_virtuemart/helpers/cart.php

Will get overwritten every time you upgrade VM

Title: Re: Trying to locate JS that updates cart module prices
Post by: Genius WebDesign on November 03, 2014, 01:28:19 AM
Thanks for the reply.

I dug a little deeper into the module PHP file and found out that the mini cart prices are generated from a plugin:
/plugins/system/vm2_cart/vm2_cart.php

In someone out there needs this in the future, here are the modifications I made in order to change the default prices to "Without Tax"

Locate this code:
$data->products[$i]['prices'] = $currency->priceDisplay( $this->_cart->pricesUnformatted[$priceKey]['salesPrice']);

And change it to:
if ($this->_cart->pricesUnformatted[$priceKey]['subtotal_tax_amount'] > 0) {
$data->products[$i]['prices'] = $currency->priceDisplay( $this->_cart->pricesUnformatted[$priceKey]['salesPrice'] - ($this->_cart->pricesUnformatted[$priceKey]['subtotal_tax_amount'] / $product->quantity)  );
      } else {
      $data->products[$i]['prices'] = $currency->priceDisplay( $this->_cart->pricesUnformatted[$priceKey]['salesPrice']);
      }


And locate this code:
$data->billTotal = $currency->priceDisplay( $this->_cart->pricesUnformatted['billTotal'] );

And change it to:
if($this->_cart->pricesUnformatted['billTaxAmount'] > 0) {
$data->billTotal = $currency->priceDisplay( $this->_cart->pricesUnformatted['billTotal'] - $this->_cart->pricesUnformatted['billTaxAmount'] );
} else {
$data->billTotal = $currency->priceDisplay( $this->_cart->pricesUnformatted['billTotal'] );
}



Title: Re: Trying to locate JS that updates cart module prices
Post by: GJC Web Design on November 03, 2014, 08:47:17 AM
Please note: there is no such plugin in a standard VM install - this plugin your talking about comes from some 3rd party extension (probably a OPC) or the template your using
Title: Re: Trying to locate JS that updates cart module prices
Post by: AH on November 03, 2014, 09:00:47 AM
as GJC said - my changes were for the core VM module

vm2_cart.php is a third party module