Show Shipping Method elsewhere on invoice.php

By | March 17, 2009

In the standard osCommerce invoice page, the shipping method and cost is shown in the order_totals, as below;

You can see that this order used “Flat Rate (Best Way)”…

On the official osCommerce forum, Tony asked;

I wish to add the shipping/postal method selected during checkout as part of the delivery label. Does anybody know the code to do this?

I am using integrated label paper (the paper with a sticker attached which I peel off with the delivery address) and have got everything else I want to display on the label (OID, Shipping Address, Return Address).

My answer was;

Stored in order_totals table of database, so easiest way would be to create a function that gets the value of text based on order_id and ot_shipping. Sounds complicated but should be straightforward once you dig in.

The asked found a solution, but it’s a horrible way;

[php]for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) { if ($order->totals[$i][‘code’] == ‘ot_shipping’) {
$myshipping = $order->totals[$i][‘title’];
}
}
echo $myshipping;[/php]

Which is iterating through all the order_totals in order to match “ot_shipping” and then display it. OK, so, it works fine and is not causing much overhead. But so ugly!

Here’s a piece of code I just cooked up which gets the shipping method;

Step 1. Add this to /admin/includes/functions/general.php

[php]function clubosc_get_shipping_method($oID) {
$shipping_query = tep_db_query(“select title from ” . TABLE_ORDERS_TOTAL . ” where class=’ot_shipping’ AND orders_id = ‘” . (int)$oID . “‘”);
$shipping_value = tep_db_fetch_array($shipping_query);
return substr($shipping_value[‘title’], 0, -1);
}[/php]

Step 2. Add this whereever you want in admin/invoice.php

[php][/php]

For this blog post, let’s add it near the “Payment Method” line of text, so do this:

[php]

info[‘payment_method’]; ?>

[/php]

Step 3. Add this to admin/includes/languages/english/invoice.php

[php]define(‘ENTRY_SHIPPING_METHOD’, ‘Shipping Method:’);[/php]

Save all files and upload. This are of your invoice should now look like this:

Easy as 123. Or is it?

Deconstructing the code

[php]function clubosc_get_shipping_method($oID)[/php]
Simply a name, and a variable to pass through.

[php] $shipping_query = tep_db_query(“select title from ” . TABLE_ORDERS_TOTAL . ” where class=’ot_shipping’ AND orders_id = ‘” . (int)$oID . “‘”);
$shipping_value = tep_db_fetch_array($shipping_query); [/php]

Grabbing the correct data from the database. In this case scanning the orders_total table for the text column that has column values of the “order_id” and where the class text is “ot_shipping”.

[php] return substr($shipping_value[‘title’], 0, -1);[/php]

Showing the data on the page, without the ending “:” – this is necessary as the actual textual methos of shipping is “Flat Rate (Best Way):” – obviously we don’t want to show the end colon!

Yes, it is as easy as 123!

Leave a Reply

Your email address will not be published.