Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19
  1. #11
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    6,977
    Plugin Contributions
    63

    Default Re: Can there be more than one "Special" for a product?

    Quote Originally Posted by swguy View Post
    You're right - the admin/specials.php passes $specials_array which is a list of things to be excluded when it calls zen_draw_products_pull_down. Have you tried resetting $specials_array, i.e.

    Code:
    $specials_array = array();
    to see what happens? I think it might work.
    That could be dangerous, given the issue that I reported in the first post of this thread.
    1. The admin-side specials' processing doesn't perform any duplicate (or date-range overlap) validation on those inserted specials.
    2. If multiple "active" specials exist for a given product, the storefront handling (when displaying products in the various listings) displays multiple instances of that product.

  2. #12
    Join Date
    Jul 2012
    Posts
    11,627
    Plugin Contributions
    13

    Default Re: Can there be more than one "Special" for a product?

    I've written a function that can identify when given two dates whether they overlap (including an option to only identify the overlap if the overlap occurs in the future). Just need a "moment" to get it posted.

    Going to recommend it as an admin side function at least.

    Options would be: provide all four dates as individual items or possibly two arrays (date1 and date2) that are expected to each (when used) have a key of start and end.

    Will be able to sort out overlap if "blank" (0001-01-01) or date provided for each or any combination of those. Base testing has been satisfactory, includes a check if a start and end are provided to sort them out if "backwards".

    So, that could be a start to the next step(s) of what to do in the event of a clash during entry. Thought is that all existing active specials would be pulled and compared against the new special. I guess the special could still be added to the list in the event of a clash with notification of it being disabled, or it could be rejected with information about why. Also a similar "action/response" when attempting to activate an existing special (assuming all are listed that are possible.) biggest hurdle I see is the display/management on the price manager as it currently is a single "field" (block) and would need to be able to expand/contract including additional action buttons.

    I have pseudo code also, but would rather give the php and be done with that "function".
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...
    Upgraded to Zen Cart V1.5.3 from V1.5.1 from V1.5.0 from V1.3.9h

  3. #13
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    5,620
    Plugin Contributions
    211

    Default Re: Can there be more than one "Special" for a product?

    Quote Originally Posted by lat9 View Post
    That could be dangerous, given the issue that I reported in the first post of this thread.
    No doubt there are many ways to get in trouble tweaking the code. But you are skilled enough to take this on.
    I will await your forthcoming mod. :)
    That Software Guy, Plugin Moderator. Store: Zen Cart Modifications
    Contributions: Quantity Discounts, Better Together, SMS on Sale, Gift Wrap at Checkout, and more.

  4. #14
    Join Date
    Jul 2012
    Posts
    11,627
    Plugin Contributions
    13

    Default Re: Can there be more than one "Special" for a product?

    Quote Originally Posted by mc12345678 View Post
    I've written a function that can identify when given two dates whether they overlap (including an option to only identify the overlap if the overlap occurs in the future). Just need a "moment" to get it posted.

    Going to recommend it as an admin side function at least.

    Options would be: provide all four dates as individual items or possibly two arrays (date1 and date2) that are expected to each (when used) have a key of start and end.

    Will be able to sort out overlap if "blank" (0001-01-01) or date provided for each or any combination of those. Base testing has been satisfactory, includes a check if a start and end are provided to sort them out if "backwards".

    So, that could be a start to the next step(s) of what to do in the event of a clash during entry. Thought is that all existing active specials would be pulled and compared against the new special. I guess the special could still be added to the list in the event of a clash with notification of it being disabled, or it could be rejected with information about why. Also a similar "action/response" when attempting to activate an existing special (assuming all are listed that are possible.) biggest hurdle I see is the display/management on the price manager as it currently is a single "field" (block) and would need to be able to expand/contract including additional action buttons.

    I have pseudo code also, but would rather give the php and be done with that "function".
    BTW, plan I have is to call the function: zen_date_overlap
    With four fields, only the first two are "required" with the following parameters in this order:
    ($start1, $start2, $end1 = NULL, $end2 = NULL, $future_only = true)
    $start1 or $start2 can be an array with both keys of 'start' and 'end' assigned. If either is an array and that array is missing either key (or both) keys, then the function returns true. True is also passed when the two date ranges provided overlap, false if they don't.

    Dates compared to today if $future_only is set to true.

    An end date of today for one range compared to a start date of today for the other would provide a false response because of how specials become inactive beginning on the date that is entered as an end date.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...
    Upgraded to Zen Cart V1.5.3 from V1.5.1 from V1.5.0 from V1.3.9h

  5. #15
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    6,977
    Plugin Contributions
    63

    Default Re: Can there be more than one "Special" for a product?

    @mc12345678, I've got a couple of questions on the proposed function's definition (a great idea):

    1. Why add the complexity of allowing those inputs to be arrays?
    2. What purpose is served by the $future_only input? It seems that either the dates overlap or they don't.

    Perhaps it also makes sense to define the function as

    Code:
    boolean zen_datetime_overlap ($start1, $start2, $end1 = NULL, $end2 = NULL);
    That way, the specials processing could append its start-time to any non-NULL start-date and its ending time to any non-NULL ending-date and any other processing that uses a date (or datetime) range could also customize the time-related values.

  6. #16
    Join Date
    Jul 2012
    Posts
    11,627
    Plugin Contributions
    13

    Default Re: Can there be more than one "Special" for a product?

    Quote Originally Posted by lat9 View Post
    @mc12345678, I've got a couple of questions on the proposed function's definition (a great idea):

    1. Why add the complexity of allowing those inputs to be arrays?
    2. What purpose is served by the $future_only input? It seems that either the dates overlap or they don't.

    Perhaps it also makes sense to define the function as

    Code:
    boolean zen_datetime_overlap ($start1, $start2, $end1 = NULL, $end2 = NULL);
    That way, the specials processing could append its start-time to any non-NULL start-date and its ending time to any non-NULL ending-date and any other processing that uses a date (or datetime) range could also customize the time-related values.
    1. The first thing that had come to mind was that a database query provides an array at least in ZC 1.5.5 and up, so can "skip" a step by the query assigning the appropriate "key" to each result. Also, it seemed like someone may consider an array for data collection that needs to then be processed.
    2. Where it is possible/known how to add functionality, why not incorporate it at time of development (which in this case also means that I need to add an "option" to investigate overlap in the past)? In the base ZC usage, it doesn't matter if two specials existed in the past as overlapping, but instead that as a new special (or in other date controlled item) it will not overlap with a currently scheduled (active) or ongoing special as the automated system disables a special upon reaching the designated end date/time. If someone chooses to show all of the specials that they ran in the past or that were in the database (these two results ought to be different if there exists a special that was entered but "never" made active), then that's another matter and could be overcome by modifying the particular area(s) to then eliminate historical overlapping and prevent additional from being added in the future applicable to the past. Of course this also shows that I didn't consider the specific condition of identifying just those with overlapping date ranges in the past. So actually, by placing this logic internally, it reduces the need of more consideration of date handling outside the code. For example attempting to identify that a specific date range is within the range of a "special" that doesn't have a start nor end date isn't really done with a comparison of the known dates to a specific value, but instead having to understand how the state or condition of being "eternal" is entered. Which of course also draws back to a reason I didn't previously consider or address "historical" overlap:

    If today I enter a special that has no start date but ends tomorrow, then a week from now I enter a special that has no start date but ends at the start of the following month. Should I be prohibited from entering the second special because technically there is an overlap of start dates such that both had "always" existed/been applicable, but neither really could apply until they were entered into the database and by a strict overlap comparison, the second entry would in fact result in an overlap existing. Or the more "realistic" case of where one special was present in the database with a start and end date with both dates in the past, then a new item is added today that doesn't have a start date assigned. If those two "dates" are provided to the function, then the previously assigned range would appear as if overlapping with the newly applied/inserted range even though in reality the new item could not have been shown in the past as being applicable because it was just added... Some of that could be addressed in advance by providing "reality" dates to the function, but the concept I'm suggesting doesn't require that type of upfront preparation, but instead offers handling the evaluation based on knowing that the concern of overlap is with items to be addressed coming up.

    As to a datetime style comparison, sure can be used/considered. Would offer a wider range of capability whether for specials or any other date/time style comparison.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...
    Upgraded to Zen Cart V1.5.3 from V1.5.1 from V1.5.0 from V1.3.9h

  7. #17
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    6,977
    Plugin Contributions
    63

    Default Re: Can there be more than one "Special" for a product?

    I think I understand the $future_only flag's use now, good idea.

    Another thing to consider in the function's processing:

    $start1 or $start2 can be an array with both keys of 'start' and 'end' assigned. If either is an array and that array is missing either key (or both) keys, then the function returns true and triggers a PHP warning.

    Otherwise, some developer is going to be scratching his/her head trying to determine why the function's returning true; the function might as well "slap them upside the head".

  8. #18
    Join Date
    Jul 2012
    Posts
    11,627
    Plugin Contributions
    13

    Default Re: Can there be more than one "Special" for a product?

    So, here's the result that appears to function, could use a little verification by anyone. I have believe I have covered all potential uses of the function, future only, past only, or at all. I've included the capability of comparing with date as well as datetime because of the use of a rawdate ('0001-01-01')/rawdatetime ('0001-01-01 00:00:00') where at least in the "standard" case the date 0001-01-01 is in Y-m-d format and the time is in h:i:s (or hours:minutes:seconds).

    Code:
     /* function to evaluate two date spans and identify if they overlap or not.
     * Returns true (overlap) if:
     *  A datespan is provided as an array and that array does not have the key 'start' nor 'end' (warning log entry also made by trigger_error).
     *  When seeking overlaps in the future:
     *  -  If the date spans both never end, OR
     *  -  If one date span never ends then if the maximum of the two start dates is less than the known to be future end
     *       date where the start date for a forever in the past date range was set to the earliest of the current date or associated end date. OR
     *  -  If the end dates are specified, then if the end dates occur in the future and the maximum start date is less
     *       than the minimum end date where the start date for a forever in the past date range was set to the earliest of the current date or associated end date.
     *  When seeking overlaps in the past:
     *  -  If the date spans both never end and they both started before today, OR
     *  -  If they both started forever in the past
     *  -  If the end dates are specified, then if the start dates occur in the past and the maximum start date is less
     *       than the minimum end date.
     *  Otherwise when seeking the presence of overlap at all (and the basis for the above logic), then basically
     *    if the maximum start date (last date range) is before the earliest end date, then that indicates that the
     *    two were active at the same time.
     *
     * Returns false (no overlap) otherwise:
    ‎ *
     * Usage: zen_datetime_overlap(array('start'=>$startdate, 'end'=>$enddate), array('start'=>$startdate, 'end'=>$enddate));
     *        zen_datetime_overlap(array('start'=>$startdate, 'end'=>$enddate), array('start'=>$startdate, 'end'=>$enddate), null, null, {default:true, false, 'past'});
     *        (if dates provided where null is in line above, they will be disregarded because of the array in positions 1 and 2.)
     *        zen_datetime_overlap($startdate1, array('start'=>$startdate, 'end'=>$enddate), $enddate1, null, {default:true, false, 'past'});
     *        zen_datetime_overlap(array('start'=>$startdate, 'end'=>$enddate), $startdate2, null, $enddate2, {default:true, false, 'past'});
     *        zen_datetime_overlap($startdate1, $startdate2, $enddate1, $enddate2, {default:true, false, 'past'});
     *        Providing $future_only of true (or as default not providing anything), the dates are inspected for overlap
     *
     * $start1 array() with keys 'start' and 'end' or as a raw_datetime or raw_date, or if null then this datetime is considered as in place forever in the past.
     * $start2 array() with keys 'start' and 'end' or as a raw_datetime or raw_date, or if null then this datetime is considered as in place forever in the past.
     * $end1 raw_datetime, raw_date or effectively blank (if $start1 is array, the value here is replaced, otherwise this datetime is considered eternally effective)
     * $end2 raw_datetime, raw_date or effectively blank (if $start2 is array, the value here is replaced, otherwise this datetime is considered eternally effective)
     * $future_only boolean or string of 'past': values should be true, false, or 'past'
     * returns a boolean true/false.  In error case of array provided without proper keys true returned and warning log also generated
    */
    
    function zen_datetime_overlap($start1, $start2, $end1 = NULL, $end2 = NULL, $future_only = true)  {
      $cur_datetime = date("Y-m-d h:i:s", time());
    
      // BOF if variable is provided as an array, validate properly setup and if so, assign and replace the other applicable values.
      if (is_array($start1)) {
        if (!array_key_exists('start', $start1)‎ || !array_key_exists('end', $start1)) {
          trigger_error(__FILE__ . ':' . __LINE__ . ' missing date/time array key(s) start and/or end.', E_USER_WARNING);
          // array is not properly defined to support further operation, therefore to prevent potential downstream issues fail safe and identify that an overlap has occurred.
          return true;
        }‎ else {
          $end1 = $start1['start'];
          $start1 = $start1['end'];
        }
      }
      if (is_array($start2)) {
        if (!array_key_exists('start', $start2)‎ || !array_key_exists('end', $start2)) {
          trigger_error(__FILE__ . ':' . __LINE__ . ' missing date/time array key(s) start and/or end.', E_USER_WARNING);
          // array is not properly defined to support further operation, therefore to prevent potential downstream issues fail safe and identify that an overlap has occurred.
          return true;
        }‎ else {
          $end2 = $start2['start'];
          $start2 = $start2['end'];
        }
    ‎  }
      // EOF if variable is provided as an array, validate properly setup and if so, assign and replace the other applicable values.
    
     // BOF ensure all variables have a non-null value
      if (!isset($start1)) {
    ‎    $start1 = '0001-01-01 00:00:00';
      }
      if (!isset($start2)) {
        $start2 = '0001-01-01 00:00:00';
      }
      if (!isset($end1)) {
        $end1 = '0001-01-01 00:00:00';
      }
      if (!isset($end2)) {
        $end2 = '0001-01-01 00:00:00';
      }
      // EOF ensure all variables have a non-null value
    
      //‎ BOF check for and correct condition where known dates are provided but swapped as in start date happens after the end date.
      if ($start1 > '0001-01-01 00:00:00' && $end1 > '0001-01-01 00:00:00' && $end1 < $start1) {
        $swap = $end1;
        $end1 = $start1;
        $start1 = $swap;
      }
      if ($start2 > '0001-01-01 00:00:00' && $end2 > '0001-01-01 00:00:00' && $end2 < $start2) {
        $swap = $end2;
        $end2 = $start2;
        $start2 = $swap;
      }
      //‎ EOF check for and correct condition where known dates are provided but swapped as in start date happens after the end date.
    
      // Consider how to use forever start dates with regards to $future only....
      // Area of concern is for example a date span was entered in the past with an end date only.
      //  If later a date span is entered also with an end date only, both spans could be evaluated as overlapping
      //  in the past because they were "always" applicable.  But in regards to e-commerce, they could not be made
      //  effective until they were in the database.  ZC typically considers this ever available in the past condition
      //  for even initial entry and does not "require" that the date be entered of when it was first added and in
      //  some cases will prevent that date from being stored if it results in the event being effective in the past.
      if ($future_only === true && $start1 <= '0001-01-01 00:00:00') {
        $start1 = min($end1, $cur_datetime);
      }
      if ($future_only === true && $start2 <= '0001-01-01 00:00:00') {
        $start2 = min($end2, $cur_datetime);
      }
    
      //‎ if either date ends in the forever future, evaluate the condition.
      if ($end1 <= '0001-01-01 00:00:00' || $end2 <= '0001-01-01 00:00:00') {
        if (($future_only !== 'past' || $start1 < $cur_datetime && $start2 < $cur_datetime) && $end1 <= '0001-01-01 00:00:00' && $end2 <= '0001-01-01 00:00:00') {
          return true; // both dates extend out to the future and therefore do or will at some point overlap.
        }
    
        $end = max($end1, $end2); //one date extends out to the future, but overlap only occurs up to the point of the known date.
        if (‎$future_only === true && $end <= $cur_datetime || $future_only === 'past' && min($start1, $start2) > $cur_datetime) {
          return false;‎ //dates may overlap in the past, but because not in the present when considering future_only do not overlap.
        }
        $overlap = max($start1, $start2) < $end;‎ // if the latest starting date occurs before the earliest known date, then they overlap, if not, then they are disjointed.
      } else {
        if ($future_only === true && max($end1, $end2) <= $cur_datetime || $future_only === 'past' && min($start1, $start2) > $cur_datetime) {
          return false; // with both end dates known, and both on or before today, then when considering future overlaps only an overlap in the future does not exist.
        }‎ else {
          $overlap = max($start1, $start2) < min($end1, $end2); // if the latest starting date occurs before the earliest known date, then they overlap, if not, then they are disjointed.
        }
      }
    
      return $overlap;
    
    }
    Last edited by mc12345678; 19 Mar 2017 at 07:32 PM. Reason: Added a little more info to error_log entry to identify what keys.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...
    Upgraded to Zen Cart V1.5.3 from V1.5.1 from V1.5.0 from V1.3.9h

  9. #19
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    6,977
    Plugin Contributions
    63

    Default Re: Can there be more than one "Special" for a product?

    Thanks, mc12345678; I've got the function copied and will "play" over the next couple of days.

    Would you apply the PSR-4 styling to the function, i.e. 4-space indents and function braces on a new line?

 

 
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 9
    Last Post: 3 Feb 2015, 09:36 PM
  2. Is there an Addon for "MULTI" Group Pricing Options? (more than 2)
    By jnspire in forum All Other Contributions/Addons
    Replies: 3
    Last Post: 9 Apr 2011, 10:15 AM
  3. Adding more than one button "add to cart" on product info page....
    By Celebrimbor in forum General Questions
    Replies: 14
    Last Post: 4 Feb 2010, 05:41 PM
  4. how can i upolad more than one pics for one product?
    By blueonline in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 24 Jun 2008, 01:14 AM
  5. More than one type of "category"
    By monkeyjr47906 in forum Setting Up Categories, Products, Attributes
    Replies: 4
    Last Post: 20 Nov 2007, 11:16 AM

Bookmarks

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
Zen-Cart, Internet Selling Services, Klamath Falls, OR