Results 1 to 10 of 544

Hybrid View

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

    Default Re: Order Delivery Date Support Thread

    Quote Originally Posted by audrey View Post
    Hi there and first off, thank you so much for this wonderful mod. It is extremely useful for logistics operations.

    One question: is there anyway I can code it such that the delivery date picker pops up only for local orders and not international orders?
    Right now, if an international customer ignores the date picker and doesn't make a selection, the customer isn't allowed to proceed to the next page.

    Any insight will be greatly appreciated!
    At minimum there are two files that would require modification, the observer class and then the checkout_shipping template file. I assume that for "sanity's" sake that if the current page were loaded with a send-to address that is international, that you would *not* want to display the delivery date field, though perhaps that would be a separate control to be addressed. The "condition" would update based on page reload/change when selecting an alternate ship-to address.

    Some things that need to be considered: Where the definition/control is to be placed to identify perhaps usage for 'national', 'international', or 'both' (shipping typically or possibly has such a control which can be adapted to this), the consideration of free shipping items (does the delivery date and/or identification of a delivery date factor into such a situation)

    The below is completely untested and written from a perspective of "seems like it would work"...

    Per the below, modify: includes/classes/observers/auto.order_delivery_date_observer.php

    Add a new function just before:
    Code:
      function update(&$callingClass, $notifier) {
    The function would be:
    Code:
      /**
      * Function to support display of the delivery date based on known internally collected order information.
      **/
      function display_delivery_date($order = NULL) {
        // if this  function is called, but there is no ORDER_DELIVERY_DATE_LOCATION  defined, then allow the delivery date to be displayed.
        if (!defined('ORDER_DELIVERY_DATE_LOCATION')) return true;
        //  If the location to be sent to is not defined, then address information  will not be available for the $order class to determine
        //  the destination, indicate to display the delivery date.
        if (!isset($_SESSION['sendto']) return true; 
    
        if (!isset($order)) {
          $order = $GLOBALS['order'];
        }
    
        if (!isset($order)) {
          // This area may need additional assignments in order to generate the appropriate information to be handled below
          //   if $order has not previously been fully populated.
          require(DIR_WS_CLASSES . 'order.php');
          $order = new order;
        }
    
        $pass = false;
    
        switch (ORDER_DELIVERY_DATE_LOCATION) {
          case 'national':
            if ($order->delivery['country_id'] == STORE_COUNTRY) {
              $pass = true;
            }
            break;
          case 'international':
            if ($order->delivery['country_id'] != STORE_COUNTRY) {
              $pass = true;
            }
            break;
          case 'both':
            $pass = true;
            break;
        }
    
        return $pass;
      }
    Modify the function updateNotifyHeaderStartCheckoutShipping as below in red:
    Code:
      // ZC155:   $zco_notifier->notify('NOTIFY_HEADER_START_CHECKOUT_SHIPPING');
      // NOTIFY_HEADER_START_CHECKOUT_SHIPPING
      function updateNotifyHeaderStartCheckoutShipping(&$callingClass, $notifier) {
        global $order_delivery_date, $messageStack;
    
          // BEGIN Order Delivery Date
        if (isset($_SESSION['order_delivery_date'])) {
          $order_delivery_date = (isset($_SESSION['order_delivery_date'])) ? $_SESSION['order_delivery_date'] : null;
        }
    
        if ( isset($_POST['action']) && ($_POST['action'] == 'process') ) {
          if (zen_not_null($_POST['order_delivery_date'])) {
            $_SESSION['order_delivery_date'] = zen_db_prepare_input($_POST['order_delivery_date']);
          } else if (defined('MIN_DISPLAY_DELIVERY_DATE') && MIN_DISPLAY_DELIVERY_DATE > 0 && $this->display_delivery_date())
          {
            $messageStack->add_session('checkout_shipping', ERROR_PLEASE_CHOOSE_DELIVERY_DATE, 'error');
            unset($_SESSION['order_delivery_date']);
            unset($order_delivery_date);
            zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
          } else {
            // If nothing was posted, and the date is not required, then
            //  be sure to clear the date from the session so that the
            //  nothing will carry forward.
            unset($_SESSION['order_delivery_date']);
          }
          $order_delivery_date = isset($_SESSION['order_delivery_date']) ? $_SESSION['order_delivery_date'] : null; // modified for strict processing mc12345678 2018-01-24
        }
      }
    Then modify the updateNotifyOrderCartFinished function as indicated below in red:
    Code:
      // ZC 1.5.5: $this->notify('NOTIFY_ORDER_CART_FINISHED');
      // This point was chosen to have just one delivery date for the entire order.
      //  To support a different delivery date by product, would want to either cycle through all of the product in this
      //    function or use the notifier 'NOTIFY_ORDER_CART_ADD_PRODUCT_LIST' to work with each product as it comes along.
      function updateNotifyOrderCartFinished(&$callingClass, $notifier) {
        global $display_delivery_date;
    
        $callingClass->info['order_delivery_date'] = (isset($_SESSION['order_delivery_date'])) ? $_SESSION['order_delivery_date'] : null;
    
        // set the global variable to display the delivery date (or not) based on the destination of the delivery.
        $display_delivery_date = $this->display_delivery_date($callingClass);
      }

    Then in the template files:
    includes/templates/YOUR_TEMPLATE/templates/tpl_checkout_shipping_default.php
    and/or
    includes/templates/YOUR_TEMPLATE_RESPONSIVE/templates/tpl_checkout_shipping_default.php

    Find:
    Code:
    <!-- Bof Order Delivery Date -->
    <fieldset class="shipping" id="order_delivery_date">
    <legend><?php echo sprintf(TABLE_HEADING_DELIVERY_DATE, (defined('MIN_DISPLAY_DELIVERY_DATE') && MIN_DISPLAY_DELIVERY_DATE > 0) ? TABLE_HEADING_DELIVERY_DATE_IS_REQUIRED : TABLE_HEADING_DELIVERY_DATE_IS_OPTIONAL); ?></legend>
    
    <label for="order_delivery_date">Date:</label>
    <input id="date" name="order_delivery_date" type="text" value="<?php echo $order_delivery_date; ?>">
    </fieldset>
    <!-- Eof Order Delivery Date -->
    And change per the below:
    Code:
    <!-- Bof Order Delivery Date -->
    <?php if (isset($display_delivery_date) ? $display_delivery_date : true) { ?>
    <fieldset class="shipping" id="order_delivery_date">
    <legend><?php echo sprintf(TABLE_HEADING_DELIVERY_DATE,  (defined('MIN_DISPLAY_DELIVERY_DATE') &&  MIN_DISPLAY_DELIVERY_DATE > 0) ?  TABLE_HEADING_DELIVERY_DATE_IS_REQUIRED :  TABLE_HEADING_DELIVERY_DATE_IS_OPTIONAL); ?></legend>
    
    <label for="order_delivery_date">Date:</label>
    <input id="date" name="order_delivery_date" type="text" value="<?php echo $order_delivery_date; ?>">
    </fieldset>
    <?php } ?>
    <!-- Eof Order Delivery Date -->
    Then, lastly, to define ORDER_DELIVERY_DATE_LOCATION to be one of the three values of: 'national', 'international', or 'both'.
    Ideally/ultimately this may be in an admin setting; however, let's put it in a file for the moment.

    add a new file: includes/extra_datafiles/order_delivery_date_location.php

    that contains:
    Code:
    <?php
    /**
     * This file contains the definition for when to display the order delivery date field based on the shipping destination.
     **/
    define('ORDER_DELIVERY_DATE_LOCATION', 'both'); // values are 'national', 'international', or 'both'
    If the above changes are entered in that sequence (and potentially tested at each "chunk" of addition), then operation should not be disturbed along the way.

    Again, this has not been tested and was presented as a thought of what may be necessary...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  2. #2
    Join Date
    Dec 2008
    Posts
    15
    Plugin Contributions
    0

    xhtml problem Re: Order Delivery Date Support Thread

    Thank you for replying!

    I tried the code but failed at the first chunk at: function update(&$callingClass, $notifier) {
    Immediately after, the my index page showed up blank.

    I wonder if I am doing something wrong? Pardon me, I'm not only at an intermediate level. Appreciate any thoughts.

    This is how it looks like after I added in the code before the above line.

    Code:
        // Need a test for presence of field/plugin? Prefer something already in memory rather than asking the DB.
        $order = $db->Execute("SELECT order_delivery_date 
                               from " . TABLE_ORDERS . "
                               where orders_id = " . (int)$order_id);
    
        $callingClass->info = array_merge($callingClass->info, array('order_delivery_date' => $order->fields['order_delivery_date']));
      }
    
      /**
      * Function to support display of the delivery date based on known internally collected order information.
      **/
      function display_delivery_date($order = NULL) {
        // if this  function is called, but there is no ORDER_DELIVERY_DATE_LOCATION  defined, then allow the delivery date to be displayed.
        if (!defined('ORDER_DELIVERY_DATE_LOCATION')) return true;
        //  If the location to be sent to is not defined, then address information  will not be available for the $order class to determine
        //  the destination, indicate to display the delivery date.
        if (!isset($_SESSION['sendto']) return true; 
    
        if (!isset($order)) {
          $order = $GLOBALS['order'];
        }
    
        if (!isset($order)) {
          // This area may need additional assignments in order to generate the appropriate information to be handled below
          //   if $order has not previously been fully populated.
          require(DIR_WS_CLASSES . 'order.php');
          $order = new order;
        }
    
        $pass = false;
    
        switch (ORDER_DELIVERY_DATE_LOCATION) {
          case 'national':
            if ($order->delivery['country_id'] == STORE_COUNTRY) {
              $pass = true;
            }
            break;
          case 'international':
            if ($order->delivery['country_id'] != STORE_COUNTRY) {
              $pass = true;
            }
            break;
          case 'both':
            $pass = true;
            break;
        }
    
        return $pass;
      }
    
      function update(&$callingClass, $notifier) {
    Quote Originally Posted by mc12345678 View Post
    At minimum there are two files that would require modification, the observer class and then the checkout_shipping template file. I assume that for "sanity's" sake that if the current page were loaded with a send-to address that is international, that you would *not* want to display the delivery date field, though perhaps that would be a separate control to be addressed. The "condition" would update based on page reload/change when selecting an alternate ship-to address.

    Some things that need to be considered: Where the definition/control is to be placed to identify perhaps usage for 'national', 'international', or 'both' (shipping typically or possibly has such a control which can be adapted to this), the consideration of free shipping items (does the delivery date and/or identification of a delivery date factor into such a situation)

    The below is completely untested and written from a perspective of "seems like it would work"...

    Per the below, modify: includes/classes/observers/auto.order_delivery_date_observer.php

    Add a new function just before:
    Code:
      function update(&$callingClass, $notifier) {
    The function would be:
    Code:
      /**
      * Function to support display of the delivery date based on known internally collected order information.
      **/
      function display_delivery_date($order = NULL) {
        // if this  function is called, but there is no ORDER_DELIVERY_DATE_LOCATION  defined, then allow the delivery date to be displayed.
        if (!defined('ORDER_DELIVERY_DATE_LOCATION')) return true;
        //  If the location to be sent to is not defined, then address information  will not be available for the $order class to determine
        //  the destination, indicate to display the delivery date.
        if (!isset($_SESSION['sendto']) return true; 
    
        if (!isset($order)) {
          $order = $GLOBALS['order'];
        }
    
        if (!isset($order)) {
          // This area may need additional assignments in order to generate the appropriate information to be handled below
          //   if $order has not previously been fully populated.
          require(DIR_WS_CLASSES . 'order.php');
          $order = new order;
        }
    
        $pass = false;
    
        switch (ORDER_DELIVERY_DATE_LOCATION) {
          case 'national':
            if ($order->delivery['country_id'] == STORE_COUNTRY) {
              $pass = true;
            }
            break;
          case 'international':
            if ($order->delivery['country_id'] != STORE_COUNTRY) {
              $pass = true;
            }
            break;
          case 'both':
            $pass = true;
            break;
        }
    
        return $pass;
      }
    Modify the function updateNotifyHeaderStartCheckoutShipping as below in red:
    Code:
      // ZC155:   $zco_notifier->notify('NOTIFY_HEADER_START_CHECKOUT_SHIPPING');
      // NOTIFY_HEADER_START_CHECKOUT_SHIPPING
      function updateNotifyHeaderStartCheckoutShipping(&$callingClass, $notifier) {
        global $order_delivery_date, $messageStack;
    
          // BEGIN Order Delivery Date
        if (isset($_SESSION['order_delivery_date'])) {
          $order_delivery_date = (isset($_SESSION['order_delivery_date'])) ? $_SESSION['order_delivery_date'] : null;
        }
    
        if ( isset($_POST['action']) && ($_POST['action'] == 'process') ) {
          if (zen_not_null($_POST['order_delivery_date'])) {
            $_SESSION['order_delivery_date'] = zen_db_prepare_input($_POST['order_delivery_date']);
          } else if (defined('MIN_DISPLAY_DELIVERY_DATE') && MIN_DISPLAY_DELIVERY_DATE > 0 && $this->display_delivery_date())
          {
            $messageStack->add_session('checkout_shipping', ERROR_PLEASE_CHOOSE_DELIVERY_DATE, 'error');
            unset($_SESSION['order_delivery_date']);
            unset($order_delivery_date);
            zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
          } else {
            // If nothing was posted, and the date is not required, then
            //  be sure to clear the date from the session so that the
            //  nothing will carry forward.
            unset($_SESSION['order_delivery_date']);
          }
          $order_delivery_date = isset($_SESSION['order_delivery_date']) ? $_SESSION['order_delivery_date'] : null; // modified for strict processing mc12345678 2018-01-24
        }
      }
    Then modify the updateNotifyOrderCartFinished function as indicated below in red:
    Code:
      // ZC 1.5.5: $this->notify('NOTIFY_ORDER_CART_FINISHED');
      // This point was chosen to have just one delivery date for the entire order.
      //  To support a different delivery date by product, would want to either cycle through all of the product in this
      //    function or use the notifier 'NOTIFY_ORDER_CART_ADD_PRODUCT_LIST' to work with each product as it comes along.
      function updateNotifyOrderCartFinished(&$callingClass, $notifier) {
        global $display_delivery_date;
    
        $callingClass->info['order_delivery_date'] = (isset($_SESSION['order_delivery_date'])) ? $_SESSION['order_delivery_date'] : null;
    
        // set the global variable to display the delivery date (or not) based on the destination of the delivery.
        $display_delivery_date = $this->display_delivery_date($callingClass);
      }

    Then in the template files:
    includes/templates/YOUR_TEMPLATE/templates/tpl_checkout_shipping_default.php
    and/or
    includes/templates/YOUR_TEMPLATE_RESPONSIVE/templates/tpl_checkout_shipping_default.php

    Find:
    Code:
    <!-- Bof Order Delivery Date -->
    <fieldset class="shipping" id="order_delivery_date">
    <legend><?php echo sprintf(TABLE_HEADING_DELIVERY_DATE, (defined('MIN_DISPLAY_DELIVERY_DATE') && MIN_DISPLAY_DELIVERY_DATE > 0) ? TABLE_HEADING_DELIVERY_DATE_IS_REQUIRED : TABLE_HEADING_DELIVERY_DATE_IS_OPTIONAL); ?></legend>
    
    <label for="order_delivery_date">Date:</label>
    <input id="date" name="order_delivery_date" type="text" value="<?php echo $order_delivery_date; ?>">
    </fieldset>
    <!-- Eof Order Delivery Date -->
    And change per the below:
    Code:
    <!-- Bof Order Delivery Date -->
    <?php if (isset($display_delivery_date) ? $display_delivery_date : true) { ?>
    <fieldset class="shipping" id="order_delivery_date">
    <legend><?php echo sprintf(TABLE_HEADING_DELIVERY_DATE,  (defined('MIN_DISPLAY_DELIVERY_DATE') &&  MIN_DISPLAY_DELIVERY_DATE > 0) ?  TABLE_HEADING_DELIVERY_DATE_IS_REQUIRED :  TABLE_HEADING_DELIVERY_DATE_IS_OPTIONAL); ?></legend>
    
    <label for="order_delivery_date">Date:</label>
    <input id="date" name="order_delivery_date" type="text" value="<?php echo $order_delivery_date; ?>">
    </fieldset>
    <?php } ?>
    <!-- Eof Order Delivery Date -->
    Then, lastly, to define ORDER_DELIVERY_DATE_LOCATION to be one of the three values of: 'national', 'international', or 'both'.
    Ideally/ultimately this may be in an admin setting; however, let's put it in a file for the moment.

    add a new file: includes/extra_datafiles/order_delivery_date_location.php

    that contains:
    Code:
    <?php
    /**
     * This file contains the definition for when to display the order delivery date field based on the shipping destination.
     **/
    define('ORDER_DELIVERY_DATE_LOCATION', 'both'); // values are 'national', 'international', or 'both'
    If the above changes are entered in that sequence (and potentially tested at each "chunk" of addition), then operation should not be disturbed along the way.

    Again, this has not been tested and was presented as a thought of what may be necessary...

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

    Default Re: Order Delivery Date Support Thread

    Looking at it again, in first "chunk"
    this:
    Code:
        if (!isset($_SESSION['sendto']) return true;
    is missing a closing paranthesis:
    Code:
        if (!isset($_SESSION['sendto'])) return true;
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  4. #4
    Join Date
    Dec 2008
    Posts
    15
    Plugin Contributions
    0

    Default Re: Order Delivery Date Support Thread

    Thanks again! I added the parenthesis and tested the site at every "chunk" edit. The site is working with no issues now. However, the delivery date picker is still showing up even though I've selected an overseas address.

    Is there some part of the code for the observer file that I'm not editing right? So far I've just cut and pasted wholesale.

    Quote Originally Posted by mc12345678 View Post
    Looking at it again, in first "chunk"
    this:
    Code:
        if (!isset($_SESSION['sendto']) return true;
    is missing a closing paranthesis:
    Code:
        if (!isset($_SESSION['sendto'])) return true;

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

    Default Re: Order Delivery Date Support Thread

    Audrey,

    Okay, had a chance to look this over and try to use it. As said it was untested. There were parts that worked, and parts that did not... For example, if the location were set to national and an international address were chosen, then the customer would not be able to check out and would be stuck in a loop. That has been corrected in the following commit that incorporates this entire concept.

    Note, it defaults to accept the date from both national and international, then if one of those is chosen, the date box is defaulted to display always. To change either/both of these settings such that the date box only displays for orders that really need them, modify the settings in the includes/extra_datafiles/order_delivery_date_location.php file.

    https://github.com/mc12345678/order-.../tree/locality

    The specific commit where the changes are shown is: https://github.com/mc12345678/order-...35349c8124621b
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  6. #6
    Join Date
    Dec 2008
    Posts
    15
    Plugin Contributions
    0

    Default Re: Order Delivery Date Support Thread

    Ok, I think that flew right over my head. But thank you MC12345678 for taking the time to walk me through this. I'll try my best to follow. Really appreciate your time!

  7. #7
    Join Date
    Dec 2008
    Posts
    15
    Plugin Contributions
    0

    Default Re: Order Delivery Date Support Thread

    Ok wow, I can't believe how easy your instructions were. I followed it to a T and the mod is working beautifully now. Thank you so much :)

    For those looking to have the Delivery Date Picker show up only for local orders and not international orders, and if you have been following the thread, all I had to do was:

    (1) edit the file -----> includes/extra_datafiles/order_delivery_date_location.php
    with this define set to "national" instead of "both". like this:

    Code:
    <?php
    /**
     * This file contains the definition for when to display the order delivery date field based on the shipping destination.
     **/
    define('ORDER_DELIVERY_DATE_LOCATION', 'national'); // values are 'national', 'international', or 'both'
    (2) THEN, make the changes to the file -----> includes/classes/observers/auto.order_delivery_date_observer.php
    with the new edits in this link ------> https://github.com/mc12345678/order-...35349c8124621b

    Psyched that this worked out. Thank you again MC12345678!
    Last edited by audrey; 29 Jan 2018 at 05:18 PM.

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

    Default Re: Order Delivery Date Support Thread

    Glad that worked out for you. It was an interesting issue to try to address, required some reworking of the code to be able to detect the delivery address.

    Note: a separate setting to consider and to achieve the goal of item 1 above (or to always display the field) is that within the same file there is an additional define that should be considered. As provided it defaults to false, but if set to true then it would always display the field:
    Code:
    define('ORDER_DELIVERY_DATE_DISPLAY_ALWAYS', 'false');
    Now though I just realized an additional "arrangement" of options. The text indicating that the delivery date for a national delivery is required but is optional for an international delivery. The code (checkout process) already operates in this manner, but the displayed text does not.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 

Similar Threads

  1. order delivery date addon - date not showing in checkout
    By jagall in forum Addon Shipping Modules
    Replies: 4
    Last Post: 19 Oct 2017, 09:09 PM
  2. JK Order Exporter - Support Thread
    By eVelt in forum All Other Contributions/Addons
    Replies: 4
    Last Post: 26 Sep 2015, 07:06 AM
  3. v151 Order Delivery date on Product Info Page
    By nicksab in forum General Questions
    Replies: 0
    Last Post: 30 Dec 2013, 03:23 AM
  4. Support Thread for JS Date Picker for options
    By eVelt in forum All Other Contributions/Addons
    Replies: 17
    Last Post: 5 Dec 2013, 05:44 AM
  5. Order Delivery Date Mod
    By fagriffin in forum Addon Shipping Modules
    Replies: 1
    Last Post: 11 Oct 2008, 04:50 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