Page 1 of 1

[solved] Orders, custom shipping and UDT

Posted: Sat Aug 22, 2009 3:21 pm
by psy
I've created a custom shipping module for the products, orders, cart, payment combo and it's all working well until I try to call it from a UDT. The UDT is needed as my customer wants to know the shipping cost before the payment gateway, ie on the confirm order screen.

In the Confirm Order template:

Code: Select all

{view_shipping_total billing_info=$order.billing items=$order.shipping.0.items shipping_dest=$order.shipping}

<p>Shipping total: ${$shipping_cost|number_format:2}</p>
The UDT is:

Code: Select all

global $gCms;
$smarty = &$gCms->GetSmarty();

$order = &$gCms->modules['Orders']['object'];
$shipping_cost = 0;

$items = $params['items'];
$shipping_dest = $params['shipping_dest'];
$billing_info = $params['billing_info'];

$shipping_cost = $order->GetShippingForBasket($billing_info,$shipping_dest,$items);

$smarty->assign('shipping_cost', $shipping_cost);

I know that the freight module is calculating the correct amount as when I add print_r to the Orders module...

Code: Select all


function GetShippingForBasket($billing_info,$shipping_dest,$items)
{
 // code .....

// test to see if amount is correct
print_r($shipping_cost);
exit;
//comment out above to return result to UDT/Invoice
return $shipping_cost;

}
...it spits out the correct amount on the screen. No matter what I've tried however, the UDT always returns 0.

When I complete the order and the calculation is applied to the invoice via the normal Orders/Payment/Shipping/Invoice process, the correct amount displays.

It was working in a previous version but it required a small hack to the Orders module. On Calguy's advice, I now use the GetShippingForBasket method.  The UDT has not worked since making these changes.

The thing that has me confounded is that the methods are working - it's just not returning the result to the UDT. Why????

Would really appreciate advice on where I'm going wrong with this.

thx
psy


Cms Version: 1.6.3

Installed Modules:

CMSMailer: 1.73.14
FileManager: 1.0
MenuManager: 1.6.1
ModuleManager: 1.3.1
News: 2.10.2
nuSOAP: 1.0.1
Printing: 1.0.1
Search: 1.6.1
ThemeManager: 1.1.1
TinyMCE: 2.5.1
CGExtensions: 1.16.2
FormBuilder: 0.5.5
FrontEndUsers: 1.6.9
CGSimpleSmarty: 1.4.3
Products: 2.4
JQueryTools: 1.0.3
SelfRegistration: 1.2.2
CGUserDirectory: 1.0
Orders: 1.4
FRTaxes: 1.0.1
Cart: 1.4.2
CGPaymentGatewayBase: 1.0
AustraliaPost: 1.0.1
PaypalGateway: 2.0
Uploads: 1.6
CustomContent: 1.5.2

Config Information:

php_memory_limit:
process_whole_template: true
max_upload_size: 2000000
default_upload_permission: 664
assume_mod_rewrite: false
page_extension:
internal_pretty_urls: false
use_hierarchy: false

Php Information:

phpversion: 5.2.9-2
md5_function: On (True)
gd_version: 2
tempnam_function: On (True)
magic_quotes_runtime: Off (False)
memory_limit: 128M
max_execution_time: 30
safe_mode: Off (False)
session_save_path: c:/wamp/tmp (0777)

Server Information:

Server Api: apache2handler
Server Db Type: MySQL (mysql)
Server Db Version: 5.1.33

Re: Orders, shipping and UDT

Posted: Sun Aug 23, 2009 2:12 am
by psy
To remove one variable from the equation, I swapped the custom shipping module to calguy's DestinationShipping module.

The result was the same, ie GetShippingForBasket works perfectly in the normal order/confirm/invoice process but when used with a UDT, the shipping cost value returned is zero.

Again, when called from the UDT, and

Code: Select all

print_r($shipping_cost);exit;
inserted in the orders code just prior to

Code: Select all

return $shipping_cost;
the correct value displays on the screen.

Any ideas why the method does not return the value to the UDT?

thx
psy

Re: Orders, custom shipping and UDT

Posted: Sun Aug 23, 2009 3:05 pm
by Jeff
why are you using a UDT in the first place? why don't you just put {myCustomShippingMod} right in the template instead of using a UDT for a wrapper for the API.

[solved]Re: Orders, custom shipping and UDT

Posted: Mon Aug 24, 2009 10:52 am
by psy
so simple, so elegant, so obvious!  :)
thank you, ajprog.

Even your solution was overkill. All I had to do was find the var in the confirm order template, ie $destination.shipping_cost.  It was there all the time.

Sometimes you look so hard you can't see what's staring you in the face.  LOL

psy

Re: [solved] Orders, custom shipping and UDT

Posted: Mon Sep 27, 2010 5:08 am
by wazman21
Hi psy, hate to revive an OLD topic - but I'm facing a dilemma where I need to calculate shipping costs based on location as well as other factors - ideally, a freight calculator for a particular freight company would be the best, however the solution you have looks like the most appropriate for me.  Could you shed some light on how you have done it (or even consider supplying your freight modules and some simple usage instructions)?  I am struggling to even find the AustraliaPost module which would at least provide a stopgap.