And not sure off hand which would be "easier" to understand on the next upgrade or not, but the following would pull the new code out a little more providing a more logical presentation of what is going on, though equally functional. There are other potential variations, though I suggest keeping the day of week check within a bounds rather than simply greater than/greater than equal to a number or less than/less than equal to a number. By limiting the potential comparisons to only the values that could exist the code has less of an opportunity to have other data impress upon it. Ie., if the value were >6 and somehow a date value of A were provided, then the function would evaluate as true because A is greater than 6 (See ascii tables for one type of example.)
Alright, enough now.. :) Sorry, just expressing some other potential concepts.
Code:<?php /* GPL released as part of the big_royalmail_v2.3 package see CREDITS.txt for the contributors and support forum. */ class specialdelivery { var $code, $title, $description, $enabled, $num_zones ; // class constructor function specialdelivery() { global $order, $total_weight, $messageStack ; $this->version = '2.3.8'; $this->code = 'specialdelivery'; $this->title = ( (defined('IS_ADMIN_FLAG') && IS_ADMIN_FLAG == true) ? @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_TEXT_TITLE'). ' <b style="color:#ff4000">ver. '.$this->version.'</b>' : constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_TEXT_TITLE') ); $this->description = @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_TEXT_DESCRIPTION'); $this->sort_order = @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_SORT_ORDER'); $this->icon = (( defined('DIR_WS_ICONS') ? DIR_WS_ICONS : 'images/icons/' ) . 'shipping_sdnd.gif'); $this->tax_class = @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_TAX_CLASS'); $this->dayofweek = date('N'); //mc12345678 added to use a single day-of-week value. 1= Monday, 7 = Sunday. if desired to instead use a session situation, then in addition to this line uncomment below: // if (isset($_SESSION['big_royal_day_of_week']) && $_SESSION['big_royal_day_of_week'] != '') { // $this->dayofweek = (int)$_SESSION['big_royal_day_of_week']; // } else { // $_SESSION['big_royal_day_of_week'] = $this->dayofweek; // } $this->enabled = @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_STATUS') == 'True' ? true : false; $this->enabled = $this->enabled && (($this->dayofweek >= 1 && $this->dayofweek <= 4) ? true : false); //mc12345678 15-06-30 evaluates true for customers if activated in admin and if within the day of the week desired, otherwise false. This "setting" could also be incorporated into the module as criteria; however, would require a bit of rewriting and other logic. // CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED $this->num_zones = 1; // inspired by Jim Barrington (JollyJim) if( isset($order) && @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_HIDE_SHIPPING_ERRORS') == 'True' ){ switch(isset($order->info['subtotal'])){ case true: if( $order->info['subtotal'] < @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_MIN_ORDERVALUE')){ $this->enabled = false; return ; }else if(MODULE_SHIPPING_SPECIALDELIVERY_MAX_ORDERVALUE != -1 && $order->info['subtotal'] > @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_MAX_ORDERVALUE')){ $this->enabled = false; return ; } break; case false: if($order->info['total'] < @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_MIN_ORDERVALUE')){ $this->enabled = false; return ; }else if(MODULE_SHIPPING_SPECIALDELIVERY_MAX_ORDERVALUE != -1 && $order->info['total'] > @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_MAX_ORDERVALUE')){ $this->enabled = false; return ; } break; } // end of switch on subtotal // check that it is a valid country being shipped to. $dest_country = $order->delivery['country']['iso_code_2']; $dest_zone = 0; for ($i=1; $i<=$this->num_zones; $i++) { $countries_table = constant('MODULE_SHIPPING_SPECIALDELIVERY_ZONES_COUNTRIES_' . $i); $country_zones = preg_split("/,/", preg_replace('/\s*/','',$countries_table) ); if (in_array($dest_country, $country_zones)) { $dest_zone = $i; break; } } // ship to country is invalid for this service if ($dest_zone == 0) { $this->enabled = false; return ; }else{ $this->enabled = false; // enabled set to true if valid shipping weight found $zones_cost = constant('MODULE_SHIPPING_SPECIALDELIVERY_ZONES_COST0_' . $dest_zone) . ',' . constant('MODULE_SHIPPING_SPECIALDELIVERY_ZONES_COST1_' . $dest_zone) . ',' . constant('MODULE_SHIPPING_SPECIALDELIVERY_ZONES_COST2_' . $dest_zone) . ',' . constant('MODULE_SHIPPING_SPECIALDELIVERY_ZONES_COST3_' . $dest_zone) . ',' . constant('MODULE_SHIPPING_SPECIALDELIVERY_ZONES_COST4_' . $dest_zone); $zones_table = preg_split("/[:,]/" , preg_replace('/\s*/', '', $zones_cost) ); $size = sizeof($zones_table); for ($i=0; $i<$size; $i+=2) { if ($total_weight <= $zones_table[$i]) { $this->enabled = true; break; } } // end of looping through return ; } // end of valid country } // end of if hide invalid shipping methods is set }


Reply With Quote
