Implementations of hook_shipping_method() return an associative array used throughout uc_quote and uc_shipping. The 'quote' subarray defines, among other things, a callback function used to acquire shipping quotes. Likewise, the 'ship' subarray defines a callback used for shipping. Currently, these 'callback' functions must reside in the same .module file as the hook. The attached patch allows both the 'quote' and 'ship' subarrays to specify an optional 'file' key specifying the name of a file containing the callback function. The location of the callback function defaults to its current location in the .module file.

The reason this is important is that, for example, the 'ship' functionality is only used by the admin. But if all the 'ship' functions are located in the .module file they are parsed and loaded into memory every time a shipping quote is loaded, even though they are not needed and will not be used. For example, about 500 lines out of the 1300 lines in the uc_ups.module are devoted towards 'ship' functionality and are needlessly parsed and loaded into memory every time a UPS shipping quote is performed. The situation is similar with the FedEx module.

This becomes even more important if this hook is extended in the future to include tracking functionality (via a 'track' key), or other functionality, since there will be even more special-purpose bundled with the module.

CommentFileSizeAuthor
uc_quote.module.patch653 bytestr
uc_shipping.admin_.inc_.patch556 bytestr

Comments

tr’s picture

I consider this patch as essential for my uc_fedex module, for the reasons stated above. There's no need to load the huge number of lines of code that implement ship functionality when just getting quotes at checkout time. Please review and commit.

tr’s picture

Assigned: Unassigned » tr
Island Usurper’s picture

Status: Needs review » Fixed

Yeah, this is something I've wanted to get to for a while. Not only 'track', but I also expect a 'void' key to become standard in the method array. Next, we should get uc_ups and uc_usps to take advantage of this.

Committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

joshuautley’s picture

Fatal error: Call to undefined function _uc_fedex_services() in /home/obcentrc/public_html/sites/all/modules/uc_fedex/uc_fedex.ship.inc on line 596