News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Auto update price fields of Gross and Net on product creation page

Started by aspirinemaga, April 16, 2013, 16:01:46 PM

Previous topic - Next topic

aspirinemaga

Hi,

after unsuccessful searching of javascript/jquery function that updates automatically the prices in input fields (both for Gross and Net prices), i wrote a custom function which you should integrate into your administration template (index.php) to make it work.

It's the same functionality which were on older version of VirtueMart component (1.x)

So here you go, copy and paste it just before the end of the <body> tag in your main admin template file (index.php):


<script type="text/javascript">
jQuery(function($){

var priceBase = $('input[name="mprices[product_price][]"]', '#productPriceBody');
var priceFinal = $('input[name="mprices[salesPrice][]"]', '#productPriceBody');
var priceDiff = parseFloat(priceFinal.val()) - parseFloat(priceBase.val());
var priceTaxReal = priceDiff / priceBase.val();
var priceTax = Math.round(priceTaxReal * 100) / 100

priceBase.keyup(function(){
updateGross();
});
priceFinal.keyup(function(){
updateNet();
});

// Return PLACES digit X after the comma
function doRound(x, places) {
return Math.round(x * Math.pow(10, places)) / Math.pow(10, places);
}

function updateGross(){
var grossValue = priceBase.val();
if( grossValue != '' ){
if(priceTax > 0){
grossValue = grossValue * (priceTax + 1);
priceFinal.val(doRound(grossValue, 5));
}
}
}

function updateNet(){
var netValue = priceFinal.val();
if( netValue != '' ){
if(priceTax > 0){
netValue = netValue / (priceTax + 1);
priceBase.val(doRound(netValue, 5));
}
}
}

});
</script>