Announcement

Collapse
No announcement yet.

Date Code and Calculation

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    From the page BASK > Basket Contents tab make sure you add the customfield that contains the ship date.

    Then:

    Code:
     <mvt:do file="g.module_library_utilities" name="g.has_sorted_ship_date" value="QuickSortArray ( l.settings:basket:groups, 'ship_date', 1 )" />  
    As Bruce alluded to earlier, the content in the ship_date customfield cannot be formatted otherwise you will get unexpected results. You would need it to be an integer for best results. For example, alphabetically, April comes before January. And mathematically 12-1-18 = -7 and 12/1/18 = 216.21.
    http://www.alphabetsigns.com/

    Comment


      #17
      If date, I'd stick with Unix Time base, then convert at display time.
      Bruce Golub
      Phosphor Media - "Your Success is our Business"

      Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
      phosphormedia.com

      Comment


        #18
        Originally posted by alphabet View Post
        From the page BASK > Basket Contents tab make sure you add the customfield that contains the ship date.

        Then:

        Code:
        <mvt:do file="g.module_library_utilities" name="g.has_sorted_ship_date" value="QuickSortArray ( l.settings:basket:groups, 'ship_date', 1 )" /> 
        As Bruce alluded to earlier, the content in the ship_date customfield cannot be formatted otherwise you will get unexpected results. You would need it to be an integer for best results. For example, alphabetically, April comes before January. And mathematically 12-1-18 = -7 and 12/1/18 = 216.21.
        This is what I am working with. your variable has_sorted_ship_date is that something I change? I feel I need to start from scratch on this one.


        So I have added, inside the foreach loop, the following:
        Code:
        <mvt:item name="customfields" param="Read_Product_Code( l.settings:group:code, 'leadtime', l.settings:leadtime )" />
        the leadtime variable or custom field is just a number so it should work well.

        Next do I add your string before the loop?
        Marshall
        http://www.hmcdisplay.com
        http://www.churchonwheels.com

        Comment


          #19
          OK I had it working. However, now the QuickSortArray will not sort if the first item has a NULL variable or is 0, if the first item in the array has a number then it works fine.

          Any idea why that happens?

          Is there another function like QuickSortArray?

          Thanks.
          Marshall
          http://www.hmcdisplay.com
          http://www.churchonwheels.com

          Comment


            #20
            Can you post your code so we can see if we can help.
            http://www.alphabetsigns.com/

            Comment


              #21
              I added a custom field to products :leadtime this is an integer.

              Next I have a Calc Script that shows a date in english of when a product will ship. This is based on todays date plus the leadtime plus 1-2 for a weekend.

              Code:
              <mvt:comment>
                  Create Estimated Date for Basket. 
              </mvt:comment>
              <mvt:item name="customfields" param="Read_Product_Code(l.settings:group:code, 'leadtime' ,  l.settings:leadtime)" />
              <mvt:if expr="ISNULL l.settings:leadtime">
                      <mvt:assign name="l.settings:leadtime" value="1" />
              </mvt:if>
              <mvt:if expr="l.settings:leadtime GT '1'">
                  <mvt:comment>
                      Create array of days and months for text output of dates.
                  </mvt:comment>
                  <mvt:assign name="l.months"  value="miva_array_deserialize( 'January,February,March,April,May,June,July,August,September,October,November,December' )" />
                  <mvt:assign name="l.daysoftheweek" value="miva_array_deserialize( 'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday' )" />
                  <mvt:comment>
                      Calculate todays Date.
                  </mvt:comment>
                  <mvt:assign name="l.today_date" value="mktime_t( s.tm_year, s.tm_mon, s.tm_mday, 0, 0, 0, g.Merchant_Local_Timezone )" />
                  <mvt:assign name="l.today_dow" value="l.daysoftheweek[ time_t_dayofweek( l.today_date, g.Merchant_Local_Timezone )]" />
                  <mvt:assign name="l.today_month" value="l.months[ time_t_month( l.today_date, g.Merchant_Local_Timezone ) ]" />
                  <mvt:assign name="l.today_day" value="time_t_dayofmonth( l.today_date, g.Merchant_Local_Timezone )" />
                  <mvt:assign name="g.today_date" value="l.today_dow $ ',  '  $ l.today_month $ ' ' $ l.today_day " />
                  <mvt:comment>
                      Create estimated ship date.
                  </mvt:comment>
                  <mvt:assign name="l.shipdate" value="mktime_t( s.tm_year, s.tm_mon, s.tm_mday, 0, 0, 0, g.Merchant_Local_Timezone ) + ( 60 * 60 * 24 * l.settings:leadtime + 0.5)" />
                  <mvt:assign name="l.ship_dow" value="l.daysoftheweek[ time_t_dayofweek( l.shipdate, g.Merchant_Local_Timezone )]" />
                      <mvt:if expr="l.ship_dow EQ 'Saturday'">
                          <mvt:assign name="l.shipdate" value="mktime_t( s.tm_year, s.tm_mon, s.tm_mday, 0, 0, 0, g.Merchant_Local_Timezone ) + ( 60 * 60 * 24 * (l.settings:leadtime + 2.5))" />
                          <mvt:assign name="l.ship_dow" value="l.daysoftheweek[ time_t_dayofweek( l.shipdate, g.Merchant_Local_Timezone )]" />
                          <mvt:assign name="l.month" value="l.months[ time_t_month( l.shipdate, g.Merchant_Local_Timezone ) ]" />
                          <mvt:assign name="l.day" value="time_t_dayofmonth( l.shipdate, g.Merchant_Local_Timezone )" />
                          <mvt:assign name="g.ships_on_date_text" value="l.ship_dow $ ',  '  $ l.month $ ' ' $ l.day " />
                          <p><i>*Estimated Ship Date <b>&mvt:global:ships_on_date_text;</b>.</i></p>
                      <mvt:else>
                          <mvt:if expr="l.ship_dow EQ 'Sunday'">
                          <mvt:assign name="l.shipdate" value="mktime_t( s.tm_year, s.tm_mon, s.tm_mday, 0, 0, 0, g.Merchant_Local_Timezone ) + ( 60 * 60 * 24 * (l.settings:leadtime + 1.5))" />
                          <mvt:assign name="l.ship_dow" value="l.daysoftheweek[ time_t_dayofweek( l.shipdate, g.Merchant_Local_Timezone )]" />
                          <mvt:assign name="l.month" value="l.months[ time_t_month( l.shipdate, g.Merchant_Local_Timezone ) ]" />
                          <mvt:assign name="l.day" value="time_t_dayofmonth( l.shipdate, g.Merchant_Local_Timezone )" />
                          <mvt:assign name="g.ships_on_date_text" value="l.ship_dow $ ',  '  $ l.month $ ' ' $ l.day " />
                          <p><i>*Estimated Ship Date <b>&mvt:global:ships_on_date_text;</b>.</i></p>
                      <mvt:else>
                  <mvt:assign name="l.month" value="l.months[ time_t_month( l.shipdate, g.Merchant_Local_Timezone ) ]" />
                  <mvt:assign name="l.day" value="time_t_dayofmonth( l.shipdate, g.Merchant_Local_Timezone )" />
                  <mvt:assign name="g.ships_on_date_text" value="l.ship_dow $ ',  '  $ l.month $ ' ' $ l.day " />
                  <p><i>*Estimated Ship Date <b>&mvt:global:ships_on_date_text;</b>.</i></p>
                      </mvt:if>
                  <mvt:assign name="g.shipdate" value="l.shipdate" />
              </mvt:if>
              </mvt:if>
              Next on the Basket view I Call this in with a ready theme link:

              Code:
              <mvt:item name="readytheme" param="contentsection( 'lt-est-date' )" />
              Next above the foreach loop in the basket I have this sort line

              Code:
              <mvt:do file="g.module_library_utilities" name="g.has_sorted_lead_time" value="QuickSortArray(l.settings:basket:groups,':leadtime', 1)" />
              The Main script there is just to output text, I do not use that for the sorting. I use the number value for sorting. However, that is not working.

              Marshall
              http://www.hmcdisplay.com
              http://www.churchonwheels.com

              Comment


                #22
                Here is a photo of an item in the basket with the above codes. This is just to add the text below the product name.
                Marshall
                http://www.hmcdisplay.com
                http://www.churchonwheels.com

                Comment


                  #23
                  I will note that the QuickSort Array works if I change the token from :leadtime to :subtotal - it sorts the prices fine. So, I feel I am missing one thing to force this to see the leadtime correctly. The lead time is in the foreach via the date calc. But does it need to be somewhere else?
                  Marshall
                  http://www.hmcdisplay.com
                  http://www.churchonwheels.com

                  Comment


                    #24
                    I'm not sure why your code is not working. It may have to do with where your readytheme and quicksort is placed.

                    I noticed that if your leadtime was null you set its value to 1, then tested if the value was greater than 1. So use GE instead of GT.

                    Using the Unix timestamp simplifies calculations and formatting, especially when sorting arrays.

                    It looks like you can calculate each item's ship date and add its epoch to a fullfillment array inside of the basket:groups array.

                    Then outside of the basket:groups array you can sort for the basket's longest leadtime and print the date.

                    Code:
                    <mvt:foreach iterator="group" array="basket:groups">
                    
                        <mvt:comment>Begin Ship Date Calculation</mvt:comment>
                        <mvt:item name="customfields" param="Read_Product_Code(l.settings:group:code, 'leadtime' ,  l.settings:leadtime)" />
                        <mvt:if expr="ISNULL l.settings:leadtime">
                                <mvt:assign name="l.settings:leadtime" value="1" />
                        </mvt:if>
                        <mvt:if expr="l.settings:leadtime GE '1'">
                    
                            <mvt:assign name="g.ship_epoch" value="s.dyn_time_t" />
                            <mvt:assign name="g.ship_epoch" value="g.ship_epoch + (l.settings:leadtime * 86400)" />
                            <mvt:assign name="g.time_zone" value="'local'" />
                    
                            <mvt:comment>Weekend orders are pushed to Monday</mvt:comment>
                            <mvt:if expr="time_t_dayofweek( g.ship_epoch, g.time_zone ) EQ '7'" >
                                <mvt:assign name="g.ship_epoch" value="g.ship_epoch + (2*86400)" />
                            <mvt:elseif expr="time_t_dayofweek( g.ship_epoch, g.time_zone ) EQ '1'">
                                <mvt:assign name="g.ship_epoch" value="g.ship_epoch + 86400" />
                            </mvt:if>
                    
                           <mvt:comment>Item ship epoch added to order fullfilment array</mvt:comment>
                            <mvt:assign name="l.gts_index" value="miva_array_insert( l.settings:fullfillment, g.ship_epoch, -1 )" />
                    
                            <mvt:assign name="g.ship_month" value="padl(time_t_month( g.ship_epoch, g.time_zone ), 2, '0')" />
                            <mvt:assign name="g.ship_date" value="padl(time_t_dayofmonth( g.ship_epoch, g.time_zone ), 2, '0')" />
                            <mvt:assign name="g.ship_year" value="time_t_year( g.ship_epoch, g.time_zone )" />
                            This item ships: &mvt:global:ship_month;-&mvt:global:ship_date;-&mvt:global:ship_year;<br>
                    
                        </mvt:if>
                    
                    </mvt:foreach>
                    <mvt:comment>Sort and pop basket leadtime</mvt:comment>
                    <mvt:do file="g.module_library_utilities" name="l.null" value="QuickSortArray( l.settings:fullfillment, '',-1)" />
                    <mvt:assign name="g.basket_ship_epoch" value="miva_array_shift( l.settings:fullfillment )" />
                    
                    <mvt:comment>Format basket leadtime</mvt:comment>
                    <mvt:assign name="g.basket_ship_month" value="padl(time_t_month( g.basket_ship_epoch, g.time_zone ), 2, '0')" />
                    <mvt:assign name="g.basket_ship_date" value="padl(time_t_dayofmonth( g.basket_ship_epoch, g.time_zone ), 2, '0')" />
                    <mvt:assign name="g.basket_ship_year" value="time_t_year( g.basket_ship_epoch, g.time_zone )" />
                    This basket ships by: &mvt:global:basket_ship_month;-&mvt:global:basket_ship_date;-&mvt:global:basket_ship_year;<br>
                    I haven't tested this script but I've done something similar in the past. Hope this helps.

                    http://www.alphabetsigns.com/

                    Comment


                      #25
                      So I added ISNULL yesterday because I was thinking that a zero value was effecting the sorting. I do not want a ship date on items unless we mark them with a leadtime. I also use this same script on product pages, order details, etc. I am good with how the calculation works. Just trying to find out why the sort is not seeing the one variable on each item within the array.

                      Marshall
                      http://www.hmcdisplay.com
                      http://www.churchonwheels.com

                      Comment


                        #26
                        The variables can change state depending on where you place an item.

                        Are you calling in the readytheme lt-est-date within the basket:groups loop? Otherwise, l.settings:group:code may not refer to the basket index you want.

                        If you call the lt-est-date before the basket:groups array it will use the last item in the basket array to call the customfields function. But I am not sure if that is what you want because the last item may not have the longest lead time.

                        Is the customfield leadtime available? BASK > Basket Contents > Customfields > Select > leadtime

                        Then you can use the Quicksort by basket:group:leadtime.
                        Last edited by alphabet; 02-12-19, 09:46 AM. Reason: typos
                        http://www.alphabetsigns.com/

                        Comment


                          #27
                          I have the lt-est-date in the foreach loop: Basket:groups. Yes.

                          I also have custom fields enabled in the page items.

                          I also have the leadtime in the select side under the contents section.


                          I have tested changing the sort and all variables work but this one. I can sort via Name, price, quantity, etc. however when I sort by :leadtime it gets all wonky... so there is definitely something not being assigned at the product/group level in the array.

                          I put a $mvt:leadtime; under the product name and that shows on the page as each item has that variable and they are all correctly assigned.
                          Marshall
                          http://www.hmcdisplay.com
                          http://www.churchonwheels.com

                          Comment


                            #28
                            What do you mean by wonky?

                            It should take the leadtimes of all basket items and sort and return true if the sort function worked. g.has_sorted_lead_time should be 1.
                            http://www.alphabetsigns.com/

                            Comment


                              #29
                              wonky just a more random order. Actually it moves the first item to the end and all others stay the same.

                              I ran an output for the g.has_sorted_leadtime in my foot and no results show for that.
                              Marshall
                              http://www.hmcdisplay.com
                              http://www.churchonwheels.com

                              Comment


                                #30

                                Depending on how you pull in the custom field it will be in a different array:
                                Code:
                                  <mvt:do file="g.module_library_utilities" name="g.has_basket_sorted_lead_time" value="QuickSortArray(l.settings:basket:groups:customfield_values:customfields:leadtime,'', 1)" />
                                Code:
                                  <mvt:do file="g.module_library_utilities" name="g.has_read_item_sorted_lead_time" value="QuickSortArray(l.settings:customfields:leadtime,'', 1)" />
                                Try one of those.
                                http://www.alphabetsigns.com/

                                Comment

                                Working...
                                X