Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Too many decimal places on Admin side


jhande

Recommended Posts

This may seem silly but it's been driving me crazy.

 

On the admin side with some contributions it shows 4 decimal places instead of the 2 as set in Currencies.

 

I have this - $12.5000 instead of $12.50.

 

How can I drop those extra 2 zero's?

 

The code in the files looks normal:

$products_query_raw = "p.products_price, ...

- or -

$product_query = tep_db_query("p.products_price, ...

- and -

<?php echo ($products['products_price']); ?>

 

Could it have anything to do with using just p.products_price and not including pd.products_price in the query?

 

:huh:

- :: Jim :: -

- My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -

Link to comment
Share on other sites

Ok, before I make a big mess of things...

 

I just changed some database settings:

Table = tax_rates, Field = tax_rate - Length/Values to 7,2

Table = currencies, Field = Value - Type to Decimal, Length/Values to 13,2

 

I am still getting four decimal places.

 

I Googled for an answer and found this:

 

"Looks as if you are outputting the raw price from your database instead of a parsed price through the currency class. Look in the relevant module displayed on your homepage, and where the price display is called, ensure it matches the following structure:

$currencies->display_price($data_array['products_price'], tep_get_tax_rate($data_array['products_tax_class_id']))

Replacing data_array with the array name holding all the database information in the particular module."

 

 

Don't know if or how that might solve my problem. Here is the code from a complicated file:

NOTE: I don't need/charge tax so I'd like to dump that code if it's unnecessary.

require(DIR_WS_CLASSES . 'currencies.php');
 $currencies = new currencies();

/* Skipping some irrelevant code */

}

 if(isset($HTTP_GET_VARS['cPath']) && $HTTP_GET_VARS['cPath'] != 0){
  $current_category_id = $HTTP_GET_VARS['cPath'];
  $product_query = tep_db_query("select pd.products_name, p.products_id, p.products_price, p.products_quantity, p.products_model, p.products_weight, p.products_status, p.products_tax_class_id, tr.tax_rate from " . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id inner join " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c on p.products_id = p2c.products_id left join " . TABLE_TAX_RATES . " tr on p.products_tax_class_id = tr.tax_class_id where pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = " . (int)$HTTP_GET_VARS['cPath'] . $search_qry . $stock_qry . " order by p.products_model ");
 } else {
  $product_query = tep_db_query("select pd.products_name, p.products_id, p.products_price, p.products_quantity, p.products_model, p.products_weight, p.products_status, p.products_tax_class_id, tr.tax_rate from " . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id left join " . TABLE_TAX_RATES . " tr on p.products_tax_class_id = tr.tax_class_id where  pd.language_id = '" . (int)$languages_id . "'" . $search_qry . $stock_qry . " order by p.products_model ");
$current_category_id = '';
 }

/* Skipping some irrelevant code */

<script language="javascript"><!--</P> <P>function doRound(x, places) {
 return Math.round(x * Math.pow(10, places)) / Math.pow(10, places);
}</P> <P>function updateGross(taxRate, product_id) {
//  var taxRate = getTaxRate();
 var grossValue = document.getElementById('price_' + product_id).value;
 if (taxRate > 0) {
grossValue = grossValue * ((taxRate / 100) + 1);
 }
document.getElementById('price_gross_' + product_id).value = doRound(grossValue, 4);
//  document.forms["new_product"].products_price_gross.value = doRound(grossValue, 4);
}</P> <P>function updateNet(taxRate, product_id) {
//  var taxRate = getTaxRate();
 var netValue = document.getElementById('price_gross_' + product_id).value;
 if (taxRate > 0) {
netValue = netValue / ((taxRate / 100) + 1);
 }
document.getElementById('price_' + product_id).value = doRound(netValue, 4);
//  document.forms["new_product"].products_price_gross.value = doRound(grossValue, 4);
}
//--></script>

/* Skipping some irrelevant code */

<td  valign="top" class="dataTableContent"><input type="text" name="price[]" id="price_<?php echo $product['products_id'];?>" value="<?php echo $product['products_price'];?>" size="6" onKeyUp="updateGross(<?php echo ((tep_not_null($product['tax_rate'])) ? $product['tax_rate'] : 0)?>, <?php echo $product['products_id'];?>)"></td>

 

Here is the code from a simple file:

<?php
 if ($HTTP_GET_VARS['page'] > 1) $rows = $HTTP_GET_VARS['page'] * 20 - 20;
 $products_query_raw = "select p.products_id, pd.products_name, p.products_quantity, p.products_price, p.products_model, l.name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_LANGUAGES . " l where p.products_id = pd.products_id and p.products_id = pd.products_id and l.languages_id = pd.language_id order by p.products_model ASC";</P> <P>  $products_query = tep_db_query($products_query_raw);
 while ($products = tep_db_fetch_array($products_query)) {
$rows++;</P> <P>	if (strlen($rows) < 2) {
  $rows = '0' . $rows;
}
?>

/* Skipping some irrelevant code */

<tr class="tableRow">
			<td width="90" class="dataTableContent"><?php echo $products['products_model']; ?></td>
			<td width="*" class="dataTableContent"><?php echo $products['products_name']; ?></td>
			<td width="30" align="center" class="dataTableContent"><?php echo $products['products_quantity']; ?></td>
			<td width="60" align="right" class="dataTableContent"><?php echo $products['products_price']; ?></td>
		  </tr>

 

I would truely appreciate any help, thoughts or ideas especially with the simple file.

 

:huh:

- :: Jim :: -

- My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -

Link to comment
Share on other sites

Off the top, I'd say replacing this code:

 

<?php echo $products['products_price']; ?>

With

<?php echo $currencies->display_price($products['products_price'], tep_get_tax_rate($products['products_tax_class_id'])); ?>

In the simple file will work for you.

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

Thanks Jim!

 

Somethings not quite right...

 

Received this error when the page loads:

 

Fatal error: Call to a member function display_price() on a non-object in /home3/handesho/public_html/catalog/admin/stats_products.php on line 66

Line 66: <td width="60" align="right" class="dataTableContent"><?php echo $currencies->display_price($products['products_price'], tep_get_tax_rate($products['products_tax_class_id'])); ?></td>

 

:(

- :: Jim :: -

- My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -

Link to comment
Share on other sites

At the top of /catalog/admin/stats_products.php just AFTER this line:

 

  require('includes/application_top.php');

ADD these lines if they aren't there:

 

  require(DIR_WS_CLASSES . 'currencies.php');
 $currencies = new currencies();

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

I tried playing with the complicated file and changed this code:

 

<td  valign="top" class="dataTableContent"><input type="text" name="price[]" id="price_<?php echo $product['products_id'];?>" value="<?php echo $product['products_price'];?>" size="6" onKeyUp="updateGross(<?php echo ((tep_not_null($product['tax_rate'])) ? $product['tax_rate'] : 0)?>, <?php echo $product['products_id'];?>)"></td>

To this:

<td  valign="top" class="dataTableContent"><input type="text" name="price[]" id="price_<?php echo $product['products_id'];?>" value="<?php echo $currencies->display_price($products['products_price'], tep_get_tax_rate($products['products_tax_class_id'])); ?>" size="6" onKeyUp="updateGross(<?php echo ((tep_not_null($product['tax_rate'])) ? $product['tax_rate'] : 0)?>, <?php echo $product['products_id'];?>)"></td>

And I tried this:

<td  valign="top" class="dataTableContent"><input type="text" name="price[]" id="price" value="<?php echo $currencies->display_price($products['products_price'], tep_get_tax_rate($products['products_tax_class_id'])); ?>" size="6"></td>

Both dropped the 2 extra decimal places, BUT changed all the prices to $0.00.

- :: Jim :: -

- My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -

Link to comment
Share on other sites

Maybe this:

 

<td  valign="top" class="dataTableContent"><input type="text" name="price[]" id="price_<?php echo $product['products_id'];?>" value="<?php echo $currencies->display_price($products['products_price'], 1.0); ?>" size="6" onKeyUp="updateGross(<?php echo ((tep_not_null($product['tax_rate'])) ? $product['tax_rate'] : 0)?>, <?php echo $product['products_id'];?>)"></td>

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

Maybe this:

 

<td  valign="top" class="dataTableContent"><input type="text" name="price[]" id="price_<?php echo $product['products_id'];?>" value="<?php echo $currencies->display_price($products['products_price'], 1.0); ?>" size="6" onKeyUp="updateGross(<?php echo ((tep_not_null($product['tax_rate'])) ? $product['tax_rate'] : 0)?>, <?php echo $product['products_id'];?>)"></td>

 

Two decimal places, but all prices zero again = $0.00

- :: Jim :: -

- My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -

Link to comment
Share on other sites

A couple of things to try:

 

<td  valign="top" class="dataTableContent"><input type="text" name="price[]" id="price_<?php echo $product['products_id'];?>" value="<?php echo $currencies->display_price($products['products_price'], 100.0); ?>" size="6" onKeyUp="updateGross(<?php echo ((tep_not_null($product['tax_rate'])) ? $product['tax_rate'] : 0)?>, <?php echo $product['products_id'];?>)"></td>

(I screwed up the tax value :blush: )

 

<td  valign="top" class="dataTableContent"><input type="text" name="price[]" id="price_<?php echo $product['products_id'];?>" value="<?php echo number_format($products['products_price'], 2, '.', ''); ?>" size="6" onKeyUp="updateGross(<?php echo ((tep_not_null($product['tax_rate'])) ? $product['tax_rate'] : 0)?>, <?php echo $product['products_id'];?>)"></td>

(A totally different appraoch altogether ;) )

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

Same for both = $0.00

 

Can there be something wrong with some of the other code on the page?

- :: Jim :: -

- My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -

Link to comment
Share on other sites

The second method I posted uses PHP routines only.

 

If the output was zero so was the input.

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

The second method I posted uses PHP routines only.

 

If the output was zero so was the input.

 

Please forgive my ignorance Jim, but that just confussed the heck out of me. :blush:

 

I know the prices are in the database.

 

With using the below code, I get the result in the top picture.

<td  valign="top" class="dataTableContent"><input type="text" name="price[]" id="price_<?php echo $product['products_id'];?>" value="<?php echo $product['products_price'];?>" size="6" onKeyUp="updateGross(<?php echo ((tep_not_null($product['tax_rate'])) ? $product['tax_rate'] : 0)?>, <?php echo $product['products_id'];?>)"></td>

decimal1as9.gif

 

But once I change to your second method of code (below), I get the results in the picture below.

<td  valign="top" class="dataTableContent"><input type="text" name="price[]" id="price_<?php echo $product['products_id'];?>" value="<?php echo number_format($products['products_price'], 2, '.', ''); ?>" size="6" onKeyUp="updateGross(<?php echo ((tep_not_null($product['tax_rate'])) ? $product['tax_rate'] : 0)?>, <?php echo $product['products_id'];?>)"></td>

decimal2wo8.gif

 

Can you explain what you mean by the input being zero?

- :: Jim :: -

- My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -

Link to comment
Share on other sites

<td  valign="top" class="dataTableContent"><input type="text" name="price[]" id="price_<?php echo $product['products_id'];?>" value="<?php echo $currencies->display_price($product['products_price'], 100.0); ?>" size="6" onKeyUp="updateGross(<?php echo ((tep_not_null($product['tax_rate'])) ? $product['tax_rate'] : 0)?>, <?php echo $product['products_id'];?>)"></td>

 

<td  valign="top" class="dataTableContent"><input type="text" name="price[]" id="price_<?php echo $product['products_id'];?>" value="<?php echo number_format($product['products_price'], 2, '.', ''); ?>" size="6" onKeyUp="updateGross(<?php echo ((tep_not_null($product['tax_rate'])) ? $product['tax_rate'] : 0)?>, <?php echo $product['products_id'];?>)"></td>

Try one of those.

 

It will help when I get the variable name right.

:blush:

 

I was using $products['products_price'] when it should have been $product['products_price'].

 

$products['products_price'] didn't exist so PHP created it and gave it a value of ZERO and printed it.

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

I think we've fallen victim to the GIGO (garbage in garbage out) Syndrome.

 

The code in your "simple" file uses the array $products

 

The code in your "more complicated" file uses the array $product (no s at the end).

:lol:

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

<td  valign="top" class="dataTableContent"><input type="text" name="price[]" id="price_<?php echo $product['products_id'];?>" value="<?php echo $currencies->display_price($product['products_price'], 100.0); ?>" size="6" onKeyUp="updateGross(<?php echo ((tep_not_null($product['tax_rate'])) ? $product['tax_rate'] : 0)?>, <?php echo $product['products_id'];?>)"></td>

 

Fantastic! That worked :)

 

You are a Saint Jim, thank you so much for all the help. ;)

 

I can't believe all the time it was a nasty little s causing the problem.

 

Oh my GOD!!!

 

I just deleted a few of those nasty little s's in another section of code I've been messing with for two weeks and now that works too.

 

Thank you for the early Christmas gift! :D

 

One more addition to the file and I'll be all set.

 

Thank you, Thank you, Thank you!!!

- :: Jim :: -

- My Toolbox ~ Adobe Web Bundle, XAMPP & WinMerge | Install ~ osC v2.3.3.4 -

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...