Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Coding Problem please help!


twigster

Recommended Posts

Hi All

 

I am trying to put some logic into my php code that checks against an order total. The piece of code below is taken from the invoice.php and is used to display the subtotal, postage and total cost fields.

 

<?php

for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {

echo ' <tr>' . "n" .

' <td align="right" class="smallText">' . $order->totals[$i]['title'] . '</td>' . "n" .

' <td align="right" class="smallText">' . $order->totals[$i]['text'] . '</td>' . "n" .

' </tr>' . "n";

}

?>

 

I have tried to get the integer value of the field by coding this but it doesn't return a value.

 

$order->totals[$i]['value']

 

does anyone know how I can get hold of the integer value for the subtotal?

 

I know there are java functions available to strip string lengths down and pass them to integer values but am unable to find an equivelent in PHP. :'(

 

Many Thanks

Mike

Link to comment
Share on other sites

you have to retrieve the value from the dbase. Open your catalog\admin\includes\classes\order.php locate this code

 

$totals_query = tep_db_query("select title, text from "

 

change it to this

$totals_query = tep_db_query("select title, text, value from "

 

further down pass it to the totals array

		$this->totals[] = array('title' => $totals['title'],
							'value' => $totals['value'],
							'text' => $totals['text']);

Link to comment
Share on other sites

Hi All

 

I am trying to put some logic into my php code that checks against an order total. The piece of code below is taken from the invoice.php and is used to display the subtotal, postage and total cost fields.

 

<?php

for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {

echo ' <tr>' . "n" .

' <td align="right" class="smallText">' . $order->totals[$i]['title'] . '</td>' . "n" .

' <td align="right" class="smallText">' . $order->totals[$i]['text'] . '</td>' . "n" .

' </tr>' . "n";

}

?>

I have tried to get the integer value of the field by coding this but it doesn't return a value.

 

$order->totals[$i]['value']

 

does anyone know how I can get hold of the integer value for the subtotal?

 

I know there are java functions available to strip string lengths down and pass them to integer values but am unable to find an equivelent in PHP. :'(

 

Many Thanks

Mike

 

From what I can tell, there is no $order->totals[$i]['value'] so of course it would not return anything.

 

Here is the code from admin/includes/classses/order.php where the $order->totals array is defined:

	$this->totals[] = array('title' => $totals['title'],
						   'text' => $totals['text']);

 

The values of the subtotal, shipping, tax and total are all in 'text' => $totals['text'] at the point in the code. By then it has already been formatted. If you want the value of any one of those fields at that point, you could do a bit of logic, searching for the string "Sub-Total" in 'title' => $totals['title'] and if true, then storing the value of 'title' => $totals['text'] in a variable and then processing that to strip out the currency character and convert to an integer.

 

But that value has to exist BEFORE it gets formatted and that seems like a simpler way to deal with it, providing you can find it of course.

 

Hmm... each order has three rows in the orders_total table. The subtotal is stored as a float in the orders_total table value field where the title field has a value of "Sub-Total".

 

I'm sure some others here will be able to tell us a simpler way to get to this value, but the only ideas I have at the moment are either testing the 'title' => $totals['title'] as I mentioned above or adding another query to pull the value out of the database directly.

 

That would be pretty simple:

 

add this to invoice.php

 

  $subtotal_query = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$oID . "' and  title = 'Sub-Total:'");
 $sub_total = tep_db_fetch_array($subtotal_query);

 

Then your subtotal will be stored in $subtotal_total['value'] as a float.

 

Do you really need an integer? or did you really just need the value as a number?

Link to comment
Share on other sites

you have to retrieve the value from the dbase. Open your catalog\admin\includes\classes\order.php locate this code

 

$totals_query = tep_db_query("select title, text from "

 

change it to this

$totals_query = tep_db_query("select title, text, value from "

 

further down pass it to the totals array

		$this->totals[] = array('title' => $totals['title'],
							'value' => $totals['value'],
							'text' => $totals['text']);

Then he'll get the value for all three rows in order_totals for each order (subtotal, shipping and total) and no way to differentiate which is which. Won't he?

 

He only wants the subtotal. Unless I'm misinterpreting his question.

Link to comment
Share on other sites

Then he'll get the value for all three rows in order_totals for each order (subtotal, shipping and total) and no way to differentiate which is which. Won't he?

 

He only wants the subtotal. Unless I'm misinterpreting his question.

No because you can also fetch the class colum (the same way as I posted). That is the correct way of determining the orders totals type.

 

This:

then processing that to strip out the currency character and convert to an integer.

of your method I will avoid because there is no need to put code stripping the currency characters from left/right of the value. Over-complicated.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...