Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2005
    Location
    Cumbria, UK
    Posts
    10,269
    Plugin Contributions
    3

    Default Enable / Disable shipping module by DAY and TIME

    I know this may not be easy, but we want certain shipping options to be sensitive (enabled / disabled) depending on the DAY and TIME a visitor accesses the site.

    For example, we want to allow Royal Mail Priority Mail as a postal option, but only if the DAY is SUNDAY 01H00 thru to THURSDAY 13H00 (British Standard Time).

    If a visitor goes through checkout, then PRIORITY POSTAL OPTION would only be visible/selectable to them, IF the time (and day) is later than 1am Sunday, and earlier than 3pm Thursday.

    Outside of these days/times, the module is disabled.

    As this shipping option is only available to UK-address deliveries, we would base the programming on our server time, which is BST. This shipping option is already disabled using standard limitation features in ZC for non-UK shipping addresses.

    Any ideas?

    ------------------------------------------------------
    20 years a Zencart User

  2. #2
    Join Date
    Dec 2009
    Location
    Amersfoort, The Netherlands
    Posts
    2,845
    Plugin Contributions
    25

    Default Re: Enable / Disable shipping module by DAY and TIME

    the first thing that came to my mind was to maybe us a cron job to execute a script, and enable/disable the module directly in the database

  3. #3
    Join Date
    Jul 2012
    Posts
    16,817
    Plugin Contributions
    17

    Default Re: Enable / Disable shipping module by DAY and TIME

    In each shipping module there is generally a statment towards the beginning of execution that identifies if the module is enabled or disabled. It is in that area that enablement and disablement would be determined by use of PHP date and time functions.

    I don't have ready access to the module's code to provide specific guidance, but in my opinion it isn't a significant task to accomplish. The thing of concern is more likely an issue of program/customer flow if the final button press occurs just after the cutoff time and how that affects the shopping experience. Ie. If all seems well and good for the purchase, they perhaps navigate around a little then go to complete the purchase just after cutoff where the selected option is no longer available, will the purchase go through with/without shipping?

    Ps. Perhaps post the "upper" portion of the shipping code and can offer specific guidance?
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  4. #4
    Join Date
    Jun 2005
    Location
    Cumbria, UK
    Posts
    10,269
    Plugin Contributions
    3

    Default Re: Enable / Disable shipping module by DAY and TIME

    Quote Originally Posted by mc12345678 View Post
    In each shipping module there is generally a statment towards the beginning of execution that identifies if the module is enabled or disabled. It is in that area that enablement and disablement would be determined by use of PHP date and time functions.

    I don't have ready access to the module's code to provide specific guidance, but in my opinion it isn't a significant task to accomplish. The thing of concern is more likely an issue of program/customer flow if the final button press occurs just after the cutoff time and how that affects the shopping experience. Ie. If all seems well and good for the purchase, they perhaps navigate around a little then go to complete the purchase just after cutoff where the selected option is no longer available, will the purchase go through with/without shipping?

    Ps. Perhaps post the "upper" portion of the shipping code and can offer specific guidance?
    Thanks for the reply - and the various cautions.

    To keep it relatively simple, and not specify a time of day (in addition to the day concerned), the following configuration is acceptable - being the day of the week only:

    MODULE ACTIVE: Monday, Tuesday, Wednesday, Thursday.
    MODULE INACTIVE: Friday, Saturday, Sunday

    The module is out of "Big Royal Mail". The relevant code seems to be:

    PHP 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->enabled = @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_STATUS') == 'True' true false;

          
    // 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 != -&& $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 != -&& $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

        
    }
    20 years a Zencart User

  5. #5
    Join Date
    Jun 2005
    Location
    Cumbria, UK
    Posts
    10,269
    Plugin Contributions
    3

    Default Re: Enable / Disable shipping module by DAY and TIME

    Quote Originally Posted by Design75 View Post
    the first thing that came to my mind was to maybe us a cron job to execute a script, and enable/disable the module directly in the database
    Yes... this was my plan-B, but thanks for the suggestion.
    20 years a Zencart User

  6. #6
    Join Date
    Dec 2009
    Location
    Amersfoort, The Netherlands
    Posts
    2,845
    Plugin Contributions
    25

    Default Re: Enable / Disable shipping module by DAY and TIME

    Yes, I also like MC 's plan more.

  7. #7
    Join Date
    Jul 2012
    Posts
    16,817
    Plugin Contributions
    17

    Default Re: Enable / Disable shipping module by DAY and TIME

    So looks like the code initially determines if the module is active or inactive based on the admin setting (Which in this case will be date related), then if other criteria are "met" the module is deactivated, such as too large of a weight, etc... See below with the colored text based on the criteria provided for day of week. Including time would be possible as well.. There still is the "issue" of how it is desired to handle say someone initiating the purchase at 2359 on Thursday night, but not getting to the final purchase until 0000+ the next day. If it is considered acceptable to have the purchase started but not completed until after that midnight cutoff, then a $_SESSION[] variable could be used as a standin that would expire with logout/timeout...



    Quote Originally Posted by schoolboy View Post
    Thanks for the reply - and the various cautions.

    To keep it relatively simple, and not specify a time of day (in addition to the day concerned), the following configuration is acceptable - being the day of the week only:

    MODULE ACTIVE: Monday, Tuesday, Wednesday, Thursday.
    MODULE INACTIVE: Friday, Saturday, Sunday

    The module is out of "Big Royal Mail". The relevant code seems to be:

    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, $dayofweek ;
    
    
    // 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 = ($this->dayofweek >= 1 && $this->dayofweek <= 4) ? true : false; //mc12345678 15-06-30 following code is commented out to support date specific activation: @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_STATUS') == 'True' ? true : false;
    
          // 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
    
        }
    Last edited by mc12345678; 30 Jun 2015 at 10:04 PM. Reason: Converted PHP tags to CODE tags to make edit clearer
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  8. #8
    Join Date
    Jul 2012
    Posts
    16,817
    Plugin Contributions
    17

    Default Re: Enable / Disable shipping module by DAY and TIME

    Quote Originally Posted by schoolboy View Post
    Thanks for the reply - and the various cautions.

    To keep it relatively simple, and not specify a time of day (in addition to the day concerned), the following configuration is acceptable - being the day of the week only:

    MODULE ACTIVE: Monday, Tuesday, Wednesday, Thursday.
    MODULE INACTIVE: Friday, Saturday, Sunday

    The module is out of "Big Royal Mail". The relevant code seems to be:
    Quote Originally Posted by mc12345678 View Post
    So looks like the code initially determines if the module is active or inactive based on the admin setting (Which in this case will be date related), then if other criteria are "met" the module is deactivated, such as too large of a weight, etc... See below with the colored text based on the criteria provided for day of week. Including time would be possible as well.. There still is the "issue" of how it is desired to handle say someone initiating the purchase at 2359 on Thursday night, but not getting to the final purchase until 0000+ the next day. If it is considered acceptable to have the purchase started but not completed until after that midnight cutoff, then a $_SESSION[] variable could be used as a standin that would expire with logout/timeout...
    Would like to take my nickel back a little... Basically the previous code enabled the module regardless of the setting in the admin panel, which is less than ideal... Below is a more correct version. Sorry about that.
    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 = (($this->dayofweek >= 1 && $this->dayofweek <= 4) && @constant('MODULE_SHIPPING_'.(strtoupper($this->code)).'_STATUS') == 'True') ? true : false; //mc12345678 15-06-30 evaluates true for customers if within the day of the week desired and activated in admin, 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
    
        }
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  9. #9
    Join Date
    Jul 2012
    Posts
    16,817
    Plugin Contributions
    17

    Default Re: Enable / Disable shipping module by DAY and TIME

    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
    
        }
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  10. #10
    Join Date
    Jun 2005
    Location
    Cumbria, UK
    Posts
    10,269
    Plugin Contributions
    3

    Default Re: Enable / Disable shipping module by DAY and TIME

    Quote Originally Posted by mc12345678 View Post
    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
    
        }
    Thanks a ton for the help... You're like I used to be on this forum (before age and health issues slowed me down) - not letting go of a challenge!

    I appreciate the help MC...
    20 years a Zencart User

 

 

Similar Threads

  1. Enable / Disable shipping module on checkout
    By probtc in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 2
    Last Post: 4 Mar 2013, 12:12 PM
  2. Shipping problems - UPS only giving Next Day and 2nd day?
    By ijarofjami in forum Built-in Shipping and Payment Modules
    Replies: 3
    Last Post: 3 Oct 2009, 04:13 AM
  3. One Flat Rate Shipping Table w/ 2nd Day Air and Next Day Air Options
    By Computra in forum Built-in Shipping and Payment Modules
    Replies: 11
    Last Post: 13 Feb 2009, 08:16 PM
  4. enable/disable shipping methods on products
    By tombo9876 in forum Built-in Shipping and Payment Modules
    Replies: 0
    Last Post: 18 Aug 2008, 08:59 PM
  5. how do I enable/disable a payment module based on order total?
    By amy351111 in forum Built-in Shipping and Payment Modules
    Replies: 0
    Last Post: 23 Jul 2008, 10:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg