Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Creating an extra Order_Total Field


Portman

Recommended Posts

Can anyone explain to me where the final total for an order is created and uploaded onto the database? 

I understand it is stored in the orders_total table  but I cannot work out where the fields for this table are populated....

basically I want  to add a couple of extra records to order_total per order, but cannot workout where to do it. 

Thanks for any help.

Link to comment
Share on other sites

I have a wholesale site with different groups with different prices for different regions/currencies at the end of transaction the idea is to convert the total into AUD before being charged ... so i need the already existing order total plus an extra 'converted order total' which will be passed on to the payment modules instead of the standard order total - it will also help me have more accurate reporting of sales  - I was also thinking I may need a currency/group row as well (though this may be redundant) just so i can separate purchase by group in the back of house. 

Link to comment
Share on other sites

I have created something on the order conformation page - under the order total that gives the converted total which I could then pass to the payment module, but I also want to save the total onto the database.

Link to comment
Share on other sites

Like @burt said, you want to create an order total module. But bear in mind that you may need to do additional payment module integration to get the correct total passed in. 

Contributions: Better Together and Quantity Discounts for osCommerce 2.3.x and Phoenix. See my profile for more details.

Link to comment
Share on other sites

You do not need an order total module.  You simply need to force the checkout to AUD.

So, make a header_tag or hook for checkout_shipping (or any other page prior to where the buyer goes off to pay) that;

  1. checks if the selected currency is AUD and if it is not AUD
  2. reload the page with AUD selected and put out a messageStack message to let the buyer know that you only accept AUD for payment.

That is simplest.  Playing with order_totals is far from simple.

Link to comment
Share on other sites

  • 3 weeks later...

thanks for the reply @burt I see what you are saying but I don't think that option will work given how my store is structured... Can I ask for you to humor me a little bit more as I try to sort this out? 

I have created another order total module which I have ALMOST got working...

my Converted  order total module looks like this ....

<?php
/*
  $Id$

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

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

  class ot_conv_total {
    var $title, $output;

    function __construct() {
      $this->code = 'ot_conv_total';
      $this->title = MODULE_ORDER_CONV_TOTAL_TOTAL_TITLE;
      $this->description = MODULE_ORDER_CONV_TOTAL_TOTAL_DESCRIPTION;
      
      if ( defined('MODULE_ORDER_CONV_TOTAL_TOTAL_STATUS') ) {
        $this->enabled = ((MODULE_ORDER_CONV_TOTAL_TOTAL_STATUS == 'true') ? true : false);
        $this->sort_order = MODULE_ORDER_CONV_TOTAL_TOTAL_SORT_ORDER;
      }

      $this->output = array();
    }

    function process() {
      global $order, $currencies;

      $this->output[] = array('title' => $this->title . ':',
                              'text' => '<strong>' . DEFAULT_CURRENCY . number_format($order->info['conv_total'], 2) . '</strong>',
                              'value' => $order->info['conv_total']);
    }

    function check() {
      if (!isset($this->_check)) {
        $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_ORDER_CONV_TOTAL_TOTAL_STATUS'");
        $this->_check = tep_db_num_rows($check_query);
      }

      return $this->_check;
    }

    function keys() {
      return array('MODULE_ORDER_CONV_TOTAL_TOTAL_STATUS', 'MODULE_ORDER_CONV_TOTAL_TOTAL_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_CONV_TOTAL_TOTAL_STATUS', 'true', 'Do you want to display the converted 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_CONV_TOTAL_TOTAL_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()) . "')");
    }
  }
?>

at this stage I have an if statement that runs at the bottom of includes/classes/order.php that looks like this ...

      if (DISPLAY_PRICE_WITH_TAX == 'true') {
        $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'];
      } else {
        $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost'];
      }
// This section added by peter - creating converted to AUD price 	  
	  $group_currency = constant('MODULE_STORE_WHOLESALE_OPT_PRICE_' . $wholesale_group . '_' . strtoupper($language));
	  
	  if ($group_currency != DEFAULT_CURRENCY) {
			
		    $value_query = tep_db_query("select value from " . TABLE_CURRENCIES . " where code = '" . $group_currency .  "'");	
			$ex_value = tep_db_fetch_array($value_query);
			$this->info['ex_rate'] =  $ex_value['value'];
			$this->info['conv_total'] = ($this->info['total'] * $ex_value['value']);
		} else {
			$this->info['ex_rate'] = 1;
			$this->info['conv_total'] = $this->info['total'];
		}

the first if/else statement is original code... my if/else statement is trying to piggyback off that to put a value into $conv_total - which works except when you are dealing with taxes where it seems to not include tax on shipping...

this is what it looks like on order confirmation...

Sub-Total: $120.00
Flat Rate (): $2.00
GST: $12.20
Total: $134.20
Converted Total: AUD134.00

I am confused as to why this is happening .... this section in order.php seems to be the only place that the $total variable is applied and the else part of my statement just says $conv_total = $total so why is there a disparity in the prices...

also, so that I am not messing with the original code - is there some way that I can put my If/else statement into my ot_conv_total module? IE, How do I call the $total value to do the manipulation.

Note: I am not sure if I am going to use ex_rate in a similar module or not 

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...