Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

how to add style to cents currencies


xnewbi3x

Recommended Posts

Posted

Hi, does anyone know how to add a style class to the cents.

ex: $100.00 make the cents size smaller, underline the zeros, and align upper...?? thanks a lot...

Posted

Very nice idea.

 

Probably it needs some time consuming coding.

 

If I get it done sometimes soon I will post it here.

 

 

Nacer.

Posted
Hi, does anyone know how to add a style class to the cents.

ex: $100.00 make the cents size smaller, underline the zeros, and align upper...?? thanks a lot...

 

ok have a look at this test i did, seems to do what you want, set something like this up as an include function and feed the prices into it to return proper style styled price where needed.

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<style type="text/css">
<!--
.dollar {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
.cent {
font-size: 10px;
text-decoration: underline;
vertical-align: top;
}
-->
</style>
</head>
<body>
<?php

$price = "$100.00";
echo "Start : ". $price. "<br>";   
list($dollar, $cent) = split('\.', $price);
echo "Finish : <span class=\"dollar\">".$dollar.".</span><span class=\"cent\">".$cent."</span>";

?> 

</body>
</html>

Posted

Hi, sorry im new to php, where exactly and how do i add to the currencie so when i display on product listing or new products, or products new.php that show this style? where the cents smaller and upper

Posted

i think oscommere setup where the decimal split at, .00

so i don't know how to add your style to the currencie where it place the decimal at.

 

can you please give me a specific file to modify and which code to insert?

a sample would be much appreciated.!!!

Posted

ok add this to your stylesheet.css at the bottom:

/* price styling */
.cent {
font-size: 8px;
text-decoration: underline;
vertical-align: top;
}

that will handle the style of the cents

 

in your includes/classes/currencies.php

 

around line 34 after this function:

 

// class constructor

function currencies() {

$this->currencies = array();

$currencies_query = tep_db_query("select code, title, symbol_left, symbol_right, decimal_point, thousands_point, decimal_places, value from " . TABLE_CURRENCIES);

while ($currencies = tep_db_fetch_array($currencies_query)) {

$this->currencies[$currencies['code']] = array('title' => $currencies['title'],

'symbol_left' => $currencies['symbol_left'],

'symbol_right' => $currencies['symbol_right'],

'decimal_point' => $currencies['decimal_point'],

'thousands_point' => $currencies['thousands_point'],

'decimal_places' => $currencies['decimal_places'],

'value' => $currencies['value']);

}

}

 

add this:

//convert price style function
function style_price($price,$decimal) {
list($dollar, $cent) = split('\\'.$decimal, $price);

return $dollar.$decimal."<span class=\"cent\">".$cent."</span>";
}

 

add this line to the format function :

 

$format_string = $this->style_price($format_string,$this->currencies[$currency_type]['decimal_point']);

 

directly above this line:

 

return $format_string;

 

so your currencies file should now look like:

<?php
/*
 $Id: currencies.php,v 1.16 2003/06/05 23:16:46 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

////
// Class to handle currencies
// TABLES: currencies
 class currencies {
var $currencies;

// class constructor
function currencies() {
  $this->currencies = array();
  $currencies_query = tep_db_query("select code, title, symbol_left, symbol_right, decimal_point, thousands_point, decimal_places, value from " . TABLE_CURRENCIES);
  while ($currencies = tep_db_fetch_array($currencies_query)) {
	$this->currencies[$currencies['code']] = array('title' => $currencies['title'],
												   'symbol_left' => $currencies['symbol_left'],
												   'symbol_right' => $currencies['symbol_right'],
												   'decimal_point' => $currencies['decimal_point'],
												   'thousands_point' => $currencies['thousands_point'],
												   'decimal_places' => $currencies['decimal_places'],
												   'value' => $currencies['value']);
  }
}

//convert price style function
function style_price($price,$decimal) {
list($dollar, $cent) = split('\\'.$decimal, $price);

return $dollar.$decimal."<span class=\"cent\">".$cent."</span>";
}


// class methods
function format($number, $calculate_currency_value = true, $currency_type = '', $currency_value = '') {
  global $currency;

  if (empty($currency_type)) $currency_type = $currency;

  if ($calculate_currency_value == true) {
	$rate = (tep_not_null($currency_value)) ? $currency_value : $this->currencies[$currency_type]['value'];
	$format_string = $this->currencies[$currency_type]['symbol_left'] . number_format(tep_round($number * $rate, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];
// if the selected currency is in the european euro-conversion and the default currency is euro,
// the currency will displayed in the national currency and euro currency
	if ( (DEFAULT_CURRENCY == 'EUR') && ($currency_type == 'DEM' || $currency_type == 'BEF' || $currency_type == 'LUF' || $currency_type == 'ESP' || $currency_type == 'FRF' || $currency_type == 'IEP' || $currency_type == 'ITL' || $currency_type == 'NLG' || $currency_type == 'ATS' || $currency_type == 'PTE' || $currency_type == 'FIM' || $currency_type == 'GRD') ) {
	  $format_string .= ' <small>[' . $this->format($number, true, 'EUR') . ']</small>';
	}
  } else {
	$format_string = $this->currencies[$currency_type]['symbol_left'] . number_format(tep_round($number, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];
  }
  $format_string = $this->style_price($format_string,$this->currencies[$currency_type]['decimal_point']);
  return $format_string;
}

function is_set($code) {
  if (isset($this->currencies[$code]) && tep_not_null($this->currencies[$code])) {
	return true;
  } else {
	return false;
  }
}

function get_value($code) {
  return $this->currencies[$code]['value'];
}

function get_decimal_places($code) {
  return $this->currencies[$code]['decimal_places'];
}

function display_price($products_price, $products_tax, $quantity = 1) {
  return $this->format(tep_add_tax($products_price, $products_tax) * $quantity);
}
 }
?>

 

That will now format prices on your site, BUT because the styles are different in the product_info.php and the new_products.php box it might not look exactly as you wish, you will have to play around with the styles to sort this out. Suggest increasing font size in info boxes so that when the price is displayed the size difference wil be spotted, also try removing the class="smallText" from line 32 of new_products.php you will need to do similar things where prices are displayed on other pages. The cent is set to 8px but ofcourse edit to suit you site.

 

You have the code now that enables this function for you, its just a matter of playing around with styles to get it looking correct, but remember for it to work the style of the price needs a font at least 2 sizes/points larger than whatever you set the cent style too, else the top alignment will not show.

 

Hope that helps you :thumbsup:

Posted

Hi Guys,

 

I like the idea of styling the cents, its great..

 

but i was wondering if you would know how to fix a problem with styling of currency.

 

http://www.voipcomponents.co.uk/product_in...products_id/165

 

I get a frustrating <span class=currency_symbol>?</span>10.00 on these pages. At first I tried to delete the code that produces this from the currencies.php file but that broke the checkout process all together.

 

I have tried adding the following to my stylesheet:

 

.currency_symbol {

font-weight: bold;

{

 

so that the stylsheet class at least exists but I get no change....

 

somebody pleeeeese help.

Posted
Hi Guys,

 

I like the idea of styling the cents, its great..

 

but i was wondering if you would know how to fix a problem with styling of currency.

 

http://www.voipcomponents.co.uk/product_in...products_id/165

 

I get a frustrating <span class=currency_symbol>?</span>10.00 on these pages. At first I tried to delete the code that produces this from the currencies.php file but that broke the checkout process all together.

 

I have tried adding the following to my stylesheet:

 

.currency_symbol {

font-weight: bold;

{

 

so that the stylsheet class at least exists but I get no change....

 

somebody pleeeeese help.

 

I take it you mean the drop down box in your attributes ?

 

post the code from your product_info page that deals with the attributes

Posted

hey gscreations, you know any contribution that randoms product every 5 second or you can set it? like the what's new box..?? but this can random?

Posted
hey gscreations, you know any contribution that randoms product every 5 second or you can set it? like the what's new box..?? but this can random?

 

eh no, you can randomise the specials box does that, but every 5 seconds ?

you would need either flash or javascript dynamicly creating an array for javascript to use, then use javascript to refresh image every 5 secs or so - that would work

 

Someone else may have done this already

Posted
Hi Graham,

 

if you go to this link the code is there:

http://www.oscommerce.com/forums/index.php?showtopic=185093

 

yes thats for currencies and displaying prices on your site, they prices all look ok to me, the problem is with your attribute dropdown box, the error will be in that code, which is why i asked to see the section of code that handles your attributes in your product_info.php page

Posted
that is super perfect and fast...

you're a genious!!!!

 

 

Code from product_info

<table cellspacing=0 cellpadding=0 width=500 align=center>
				  <tr><td height=15></td></tr>
				  <tr><td>

				  <?php
				  $products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'");
				  $products_attributes = tep_db_fetch_array($products_attributes_query);
				  if ($products_attributes['total'] > 0) {
					  ?>
				  <table border="0" cellspacing="0" cellpadding="2">
				   <tr><td class="main" colspan="2"><?php echo TEXT_PRODUCT_OPTIONS; ?></td></tr>
					   <?php
						$products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "' order by popt.products_options_name");
						while ($products_options_name = tep_db_fetch_array($products_options_name_query)) {
						$products_options_array = array();
						$products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "'");
							while ($products_options = tep_db_fetch_array($products_options_query)) {
						$products_options_array[] = array('id' => $products_options['products_options_values_id'], 'text' => $products_options['products_options_values_name']);
						if ($products_options['options_values_price'] != '0') {
						   $products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $products_options['price_prefix'] . $currencies->display_price($products_options['options_values_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .') ';
						   }
				  } 

				 if (isset($cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']])) {
				 $selected_attribute = $cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']];
				  } else {
				  $selected_attribute = false;
				  }
					  ?>

				 <tr><td class="main"><?php echo $products_options_name['products_options_name'] . ':'; ?></td></tr>
				 <tr><td class="main"><?php echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?></td></tr>
				 </table>

 

 

 

 

code from classes/currencies.php - this is where it seems to be setting the currency_symbol class

function format($number, $calculate_currency_value = true, $currency_type = '', $currency_value = '') {
  global $currency;

  if (empty($currency_type)) $currency_type = $currency;

  if ($calculate_currency_value == true) {
	$rate = (tep_not_null($currency_value)) ? $currency_value : $this->currencies[$currency_type]['value'];
	$format_string = '<span class=currency_symbol>'.$this->currencies[$currency_type]['symbol_left'] .'</span>'. number_format(tep_round($number * $rate, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . '<span class=currency_symbol>'.$this->currencies[$currency_type]['symbol_right'].'</span>';
// if the selected currency is in the european euro-conversion and the default currency is euro,
// the currency will displayed in the national currency and euro currency
	if ( (DEFAULT_CURRENCY == 'EUR') && ($currency_type == 'DEM' || $currency_type == 'BEF' || $currency_type == 'LUF' || $currency_type == 'ESP' || $currency_type == 'FRF' || $currency_type == 'IEP' || $currency_type == 'ITL' || $currency_type == 'NLG' || $currency_type == 'ATS' || $currency_type == 'PTE' || $currency_type == 'FIM' || $currency_type == 'GRD') ) {
	  $format_string .= ' <small>[' . $this->format($number, true, 'EUR') . ']</small>';
	}
  } else {
	$format_string = '<span class=currency_symbol>'.$this->currencies[$currency_type]['symbol_left'].'</span>' . number_format(tep_round($number, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . '<span class=currency_symbol>'.$this->currencies[$currency_type]['symbol_right'].'</span>';
  }

  return $format_string;
}

 

extract from stylesheet:

 .currency_symbol{
 color: #ffffff;
}

Posted
Code from product_info

<table cellspacing=0 cellpadding=0 width=500 align=center>
				  <tr><td height=15></td></tr>
				  <tr><td>

				  <?php
				  $products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'");
				  $products_attributes = tep_db_fetch_array($products_attributes_query);
				  if ($products_attributes['total'] > 0) {
					  ?>
				  <table border="0" cellspacing="0" cellpadding="2">
				   <tr><td class="main" colspan="2"><?php echo TEXT_PRODUCT_OPTIONS; ?></td></tr>
					   <?php
						$products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "' order by popt.products_options_name");
						while ($products_options_name = tep_db_fetch_array($products_options_name_query)) {
						$products_options_array = array();
						$products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "'");
							while ($products_options = tep_db_fetch_array($products_options_query)) {
						$products_options_array[] = array('id' => $products_options['products_options_values_id'], 'text' => $products_options['products_options_values_name']);
						if ($products_options['options_values_price'] != '0') {
						   $products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $products_options['price_prefix'] . $currencies->display_price($products_options['options_values_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .') ';
						   }					  } 

				 if (isset($cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']])) {
				 $selected_attribute = $cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']];
				  } else {
				  $selected_attribute = false;
				  }
					  ?>

				 <tr><td class="main"><?php echo $products_options_name['products_options_name'] . ':'; ?></td></tr>
				 <tr><td class="main"><?php echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?></td></tr>
				 </table>

code from classes/currencies.php - this is where it seems to be setting the currency_symbol class

function format($number, $calculate_currency_value = true, $currency_type = '', $currency_value = '') {
  global $currency;

  if (empty($currency_type)) $currency_type = $currency;

  if ($calculate_currency_value == true) {
	$rate = (tep_not_null($currency_value)) ? $currency_value : $this->currencies[$currency_type]['value'];
	$format_string = '<span class=currency_symbol>'.$this->currencies[$currency_type]['symbol_left'] .'</span>'. number_format(tep_round($number * $rate, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . '<span class=currency_symbol>'.$this->currencies[$currency_type]['symbol_right'].'</span>';
// if the selected currency is in the european euro-conversion and the default currency is euro,
// the currency will displayed in the national currency and euro currency
	if ( (DEFAULT_CURRENCY == 'EUR') && ($currency_type == 'DEM' || $currency_type == 'BEF' || $currency_type == 'LUF' || $currency_type == 'ESP' || $currency_type == 'FRF' || $currency_type == 'IEP' || $currency_type == 'ITL' || $currency_type == 'NLG' || $currency_type == 'ATS' || $currency_type == 'PTE' || $currency_type == 'FIM' || $currency_type == 'GRD') ) {
	  $format_string .= ' <small>[' . $this->format($number, true, 'EUR') . ']</small>';
	}
  } else {
	$format_string = '<span class=currency_symbol>'.$this->currencies[$currency_type]['symbol_left'].'</span>' . number_format(tep_round($number, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . '<span class=currency_symbol>'.$this->currencies[$currency_type]['symbol_right'].'</span>';
  }

  return $format_string;
}

 

extract from stylesheet:

 .currency_symbol{
 color: #ffffff;
}

 

ok this bit: (in currencies)

 

$format_string = '<span class=currency_symbol>'.$this->currencies[$currency_type]['symbol_left'] .'</span>'. number_format(tep_round($number * $rate, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . '<span class=currency_symbol>'.$this->currencies[$currency_type]['symbol_right'].'</span>';

// if the selected currency is in the european euro-conversion and the default currency is euro,

// the currency will displayed in the national currency and euro currency

if ( (DEFAULT_CURRENCY == 'EUR') && ($currency_type == 'DEM' || $currency_type == 'BEF' || $currency_type == 'LUF' || $currency_type == 'ESP' || $currency_type == 'FRF' || $currency_type == 'IEP' || $currency_type == 'ITL' || $currency_type == 'NLG' || $currency_type == 'ATS' || $currency_type == 'PTE' || $currency_type == 'FIM' || $currency_type == 'GRD') ) {

$format_string .= ' <small>[' . $this->format($number, true, 'EUR') . ']</small>';

}

} else {

$format_string = '<span class=currency_symbol>'.$this->currencies[$currency_type]['symbol_left'].'</span>' . number_format(tep_round($number, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . '<span class=currency_symbol>'.$this->currencies[$currency_type]['symbol_right'].'</span>';

}

 

change to:

$format_string = $this->currencies[$currency_type]['symbol_left'] . number_format(tep_round($number * $rate, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];

// if the selected currency is in the european euro-conversion and the default currency is euro,

// the currency will displayed in the national currency and euro currency

if ( (DEFAULT_CURRENCY == 'EUR') && ($currency_type == 'DEM' || $currency_type == 'BEF' || $currency_type == 'LUF' || $currency_type == 'ESP' || $currency_type == 'FRF' || $currency_type == 'IEP' || $currency_type == 'ITL' || $currency_type == 'NLG' || $currency_type == 'ATS' || $currency_type == 'PTE' || $currency_type == 'FIM' || $currency_type == 'GRD') ) {

$format_string .= ' <small>[' . $this->format($number, true, 'EUR') . ']</small>';

}

} else {

$format_string = $this->currencies[$currency_type]['symbol_left']. number_format(tep_round($number, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']).$this->currencies[$currency_type]['symbol_right'];

}

 

that will remove the formatting from all prices, which will fix the error in dropdowns

 

But it will affect the way all the prices are shown so we might have to look at that after

 

I though there might be an error with the product_info page but all looks ok there

 

you did mention you had deleted your currencies.php page but it caused error in checkout, i take it you've reinstated the code you deleted? if not do so.

 

Try that and see what happens, the box should be ok, we might have to play with other styles for the other prices

Posted

Ok I have removed the class stylesheet stuff and for some reason its not crashing the shop now.

 

hmmmm.

 

let me check all other areas and make sure all is well.

 

Thanks so much for your help

Archived

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

×
×
  • Create New...