Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Rounding TOTAL


teebor

Recommended Posts

Hi! I need help for rounding Total price.

If sum is 100,20 I need it rounded 100.

If sum is 100,60 I need it rounded 100,5.

etc.

We have only 0,50 coins in SK.

I need changes in this php:

 

<?php

/*

$Id: ot_round.php,v 1.7 2003/02/13 00:12:04 hpdl Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

class ot_round {

var $title, $output;

 

function ot_round() {

$this->code = 'ot_round';

$this->title = MODULE_ORDER_TOTAL_ROUND_TITLE;

$this->description = MODULE_ORDER_TOTAL_ROUND_DESCRIPTION;

$this->enabled = ((MODULE_ORDER_TOTAL_ROUND_STATUS == 'true') ? true : false);

$this->sort_order = MODULE_ORDER_TOTAL_ROUND_SORT_ORDER;

 

$this->output = array();

}

 

function process() {

global $order, $currencies;

 

$temp = 1-($order->info['total']-floor($order->info['total']));

if ($temp == 1) $temp = 0;

 

$this->output[] = array('title' => $this->title . ':',

'text' => $currencies->format($temp, true, $order->info['currency'], $order->info['currency_value']),

'value' => $temp);

 

$order->info['total'] += $temp;

}

 

function check() {

if (!isset($this->_check)) {

$check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_ORDER_TOTAL_ROUND_STATUS'");

$this->_check = tep_db_num_rows($check_query);

}

 

return $this->_check;

}

 

function keys() {

return array('MODULE_ORDER_TOTAL_ROUND_STATUS', 'MODULE_ORDER_TOTAL_ROUND_SORT_ORDER');

}

 

function install() {

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Display Total', 'MODULE_ORDER_TOTAL_ROUND_STATUS', 'true', 'Do you want to display the total order value?', '6', '1','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_ORDER_TOTAL_ROUND_SORT_ORDER', '4', 'Sort order of display.', '6', '2', now())");

}

 

function remove() {

tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");

}

}

?>

 

Many thanks

Teebor

Link to comment
Share on other sites

you might be able to use the contribution called Charity Round up which is just a code to round the final price up to the nearest dollar.. you can strip that code down and change it around a little to get the desired value.

A great place for newbies to start

Road Map to oscommerce File Structure

DO NOT PM ME FOR HELP. My time is valuable, unless i ask you to PM me, please dont. You will get better help if you post publicly. I am not as good at this as you think anyways!

 

HOWEVER, you can visit my blog (go to my profile to see it) and post a question there, i will find time to get back and answer you

 

Proud Memeber of the CODE BREAKERS CLUB!!

Link to comment
Share on other sites

Hi! I need help for rounding Total price.

If sum is 100,20 I need it rounded 100.

If sum is 100,60 I need it rounded 100,5.

etc.

We have only 0,50 coins in SK.

I need changes in this php:

 

 

here's a function you can use to round up or down to the nearest 1/2:

function sk_round($value)
{
 $nWhole = (int) $value;
 $nDec = $value - $nWhole;

 $nDec *= 2;
 $nDec = round($nDec);
 $nDec /= 2;

 return ($nWhole + $nDec);
}

 

if you can use that in your code, you're welcome to it.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...