The other day I installed my Coupon Discount module on a site and all went smoothly. As I offer Tech Support on the module, the shop owner contacted me a few days later to ask if it was possible that my installation of Coupons has caused his “free shipping” to stop working.
I was sure it had not, as my coupon module doesn’t touch any shipping modules, so couldn’t see how, but I made some investigations anyway. It turns out that the shop owner was using some system of “hard coding” free shipping if the total weight of the order was zero…which is an OK way to do things if it is done right.
In this case, what was happening was something like (in the checkout_shipping page);
IF the total weight of the order is ZERO, then;
DON’T show any shipping modules
DO show the words “you’ve qualified for free shipping”
The problem here is that the system is expecting the buyer to actually select a shipping method – but as the modules were not showing, it was impossible to select anything, hence the checkout_payment page was redirecting back to checkout_shipping. What the shop owner had neglected to do was instantiate a “free” shipping method (to go along with the words “free shipping”).
So, I emailed back to let the shop owner know the problem. My advice was to scrap all teh nonsense code that he already was using for “free” shipping, and do something different…
Ideas, ideas
My first idea was to amend each shipping method to add in a “zero price” for “zero weight” – which would have worked great – but would have given the buyer the opportunity to select 1 of a number of shipping methods (all zero priced). That would have looked unprofessional.
My next idea was to amend the shipping order_total module to give free shipping if the weight is zero. At present this order_total module works only on “price”, but it should be easy to add in an extra weight system to it…
Step 1: to amend the order_total module to add in an extra box to allow weight based instantiation. Easy enough, turn off the module, find the following functions (keys, install, remove) at the bottom of the file, and replace with the following;
[php]function keys() {
return array(‘MODULE_ORDER_TOTAL_SHIPPING_STATUS’, ‘MODULE_ORDER_TOTAL_SHIPPING_SORT_ORDER’, ‘MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING’, ‘MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER’, ‘MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_WEIGHT_UNDER’, ‘MODULE_ORDER_TOTAL_SHIPPING_DESTINATION’);
}
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 Shipping’, ‘MODULE_ORDER_TOTAL_SHIPPING_STATUS’, ‘true’, ‘Do you want to display the order shipping cost?’, ‘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_TOTAL_SHIPPING_SORT_ORDER’, ‘2’, ‘Sort order of display.’, ‘6’, ‘2’, now())”);
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 (‘Allow Free Shipping’, ‘MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING’, ‘true’, ‘Do you want to allow free shipping?’, ‘6’, ‘3’, ‘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, use_function, date_added) values (‘Free Shipping For Orders Over’, ‘MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER’, ’50’, ‘Provide free shipping for orders over the set amount.’, ‘6’, ‘4’, ‘currencies->format’, now())”);
tep_db_query(“insert into ” . TABLE_CONFIGURATION . ” (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, date_added) values (‘Free Shipping For Weight Under’, ‘MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_WEIGHT_UNDER’, ‘0’, ‘Provide free shipping for orders of this weight and below.’, ‘6’, ‘4’, ”, now())”);
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 (‘Provide Free Shipping For Orders Made’, ‘MODULE_ORDER_TOTAL_SHIPPING_DESTINATION’, ‘both’, ‘Provide free shipping for orders sent to the set destination.’, ‘6’, ‘5’, ‘tep_cfg_select_option(array(\’national\’, \’international\’, \’both\’), ‘, now())”);
}
function remove() {
tep_db_query(“delete from ” . TABLE_CONFIGURATION . ” where configuration_key in (‘” . implode(“‘, ‘”, $this->keys()) . “‘)”);
}[/php]
Step 2: I opened up checkout_shipping.php and changed this:
[php]if ( ($pass == true) && ($order->info[‘total’] >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) ) {[/php]
To this:
[php]if (($pass == true)&&($order->info[‘total’] >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER)||($cart->show_weight() <= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_WEIGHT_UNDER)) {[/php] And that was about it, as far as I recall. If you try it, and it does not work, let me know so that I can go back through my code to see if I had to make any extra changes...