Announcement

Collapse
No announcement yet.

Estimated Delivery Date for Google Reviews

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

    Estimated Delivery Date for Google Reviews

    The Google Reviews survey opt-in module requires an estimated delivery day YYYY-MM-DD as part of the javascript snippet that is placed on the INVC screen. The store owner would like the estimate to be 7 days from the order date. My feeble attempt at reusing some mvt:assign code failed miserably.

    Code:
    <mvt:assign name="l.settings:order:est_arrival_ts" value="l.settings:order:orderdate + (60 * 60 * 24 * 7)" />
    <mvt:assign name="l.settings:order:est_arrival_year" value="time_t_year( l.settings:order:est_shipped_ts ,g.Merchant_Local_Timezone)" />
    <mvt:assign name="l.settings:order:est_arrival_month" value="padl(time_t_month( l.settings:order:est_shipped_ts ,g.Merchant_Local_Timezone), 2, 0)" />
    <mvt:assign name="l.settings:order:est_arrival_day" value="padl(time_t_dayofmonth( l.settings:order:est_shipped_ts ,g.Merchant_Local_Timezone), 2, 0)" />
    
    
    "estimated_delivery_date": "&mvt:order:est_shipped_year;-&mvt:order:est_shipped_month;-&mvt:order:est_shipped_day;",
    The only thing that displays are the dashes

    Code:
    "estimated_delivery_date": "--",
    What am I doing wrong?

    Leslie Kirk
    Miva Certified Developer
    Miva Merchant Specialist since 1997
    Previously of Webs Your Way
    (aka Leslie Nord leslienord)

    Email me: [email protected]
    www.lesliekirk.com

    Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

    #2
    Leslie,

    It looks as though you're calling using different variables to create data and display.
    Code:
         <!--Set a time stamp for test -->
    <mvt:assign name="l.settings:order:orderdate" value="1516375646" />
    
         <!-- assign est_arrival_ts as date + 7 days-->
    <mvt:assign name="l.settings:order:est_arrival_ts" value="l.settings:order:orderdate + (60 * 60 * 24 * 7)" />
    
         <!-- calculate the arrival year, month, day using est_arrival_date, here you were calculating based on original order date--> 
    <mvt:assign name="l.settings:order:est_arrival_year" value="time_t_year( l.settings:order:est_arrival_ts ,g.Merchant_Local_Timezone)" />
    <mvt:assign name="l.settings:order:est_arrival_month" value="padl(time_t_month( l.settings:order:est_arrival_ts ,g.Merchant_Local_Timezone), 2, 0)" />
    <mvt:assign name="l.settings:order:est_arrival_day" value="padl(time_t_dayofmonth( l.settings:order:est_arrival_ts ,g.Merchant_Local_Timezone), 2, 0)" />
    
         <!-- print new data, using new variables -->
    "estimated_delivery_date": "&mvt:order:est_arrival_year;-&mvt:order:est_arrival_month;-&mvt:order:est_arrival_day;",
    The result I get with this sample data is
    "estimated_delivery_date": "2018-01-26",

    Keeping in mind, this calculation does not take non-business days into account.

    Comment


      #3
      Thanks - ignorant question. Did you use a "fixed" date for your test? If so, do I exclude it from the code I use? Or do I use &mvt:order:orderdate;
      Leslie Kirk
      Miva Certified Developer
      Miva Merchant Specialist since 1997
      Previously of Webs Your Way
      (aka Leslie Nord leslienord)

      Email me: [email protected]
      www.lesliekirk.com

      Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

      Comment


        #4
        I did use a static date for the example, just exclude the first mvt:assign from your INVC page. "l.settings:order:orderdate" will be naturally defined on page for each order.

        Code:
         
         <mvt:assign name="l.settings:order:est_arrival_ts" value="l.settings:order:orderdate + (60 * 60 * 24 * 7)" /> <mvt:assign name="l.settings:order:est_arrival_year" value="time_t_year( l.settings:order:est_arrival_ts ,g.Merchant_Local_Timezone)" /> <mvt:assign name="l.settings:order:est_arrival_month" value="padl(time_t_month( l.settings:order:est_arrival_ts ,g.Merchant_Local_Timezone), 2, 0)" /> <mvt:assign name="l.settings:order:est_arrival_day" value="padl(time_t_dayofmonth( l.settings:order:est_arrival_ts ,g.Merchant_Local_Timezone), 2, 0)" /> "estimated_delivery_date": "&mvt:order:est_arrival_year;-&mvt:order:est_arrival_month;-&mvt:order:est_arrival_day;",

        Comment


          #5
          You can combine the date formatting into a single mvt:assign as well, this makes for more difficult to read, but more compact code.

          Code:
          <mvt:assign name="l.settings:order:est_arrival_ts" value="l.settings:order:orderdate + (60 * 60 * 24 * 7)" />
          <mvt:assign name="l.settings:order:formatted_arrival_date" value="time_t_year( l.settings:order:est_arrival_ts ,g.Merchant_Local_Timezone) $ '-' $ padl(time_t_month( l.settings:order:est_arrival_ts ,g.Merchant_Local_Timezone), 2, 0) $ '-' $ padl(time_t_dayofmonth( l.settings:order:est_arrival_ts ,g.Merchant_Local_Timezone), 2, 0)" />
          "estimated_delivery_date": "&mvt:order:formatted_arrival_date;",

          Comment


            #6
            LOL, I was trying to figure out what I did wrong in my code. Now I see it. I had the "print" variables wrong.

            Mine:

            Code:
             "estimated_delivery_date": "&mvt:order:est_shipped_year;-&mvt:order:est_shipped_month;-&mvt:order:est_shipped_day;",
            Yours
            Code:
             <!-- print new data, using new variables -->
            
            "estimated_delivery_date": "&mvt:order:est_arrival_year;-&mvt:order:est_arrival_month;-&mvt:order:est_arrival_day;",

            I missed that est_shipped
            Leslie Kirk
            Miva Certified Developer
            Miva Merchant Specialist since 1997
            Previously of Webs Your Way
            (aka Leslie Nord leslienord)

            Email me: [email protected]
            www.lesliekirk.com

            Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

            Comment


              #7
              Something must be getting in the way of this firing correctly - the estimated_delivery_date is still just the 2 dashes, no dates.
              Leslie Kirk
              Miva Certified Developer
              Miva Merchant Specialist since 1997
              Previously of Webs Your Way
              (aka Leslie Nord leslienord)

              Email me: [email protected]
              www.lesliekirk.com

              Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

              Comment


                #8
                Have you tried printing each variable as it is created for debugging purposes? I have noticed I occasionally have to manually assign the time zone in order for the date functions to work.

                Comment


                  #9
                  Originally posted by kocourek View Post
                  Have you tried printing each variable as it is created for debugging purposes? I have noticed I occasionally have to manually assign the time zone in order for the date functions to work.
                  Question - since using the INVC can be a pain to test on, is there another screen that could be used? What about the Merchant email? It can manually be resent.
                  Leslie Kirk
                  Miva Certified Developer
                  Miva Merchant Specialist since 1997
                  Previously of Webs Your Way
                  (aka Leslie Nord leslienord)

                  Email me: [email protected]
                  www.lesliekirk.com

                  Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

                  Comment


                    #10
                    You can test it on any page, you would just need to manually assign a value to l.settings:order:orderdate as in my original chunk of code

                    Comment


                      #11
                      So it works on my testing page, now to figure out why it's not working on the INVC page.
                      Leslie Kirk
                      Miva Certified Developer
                      Miva Merchant Specialist since 1997
                      Previously of Webs Your Way
                      (aka Leslie Nord leslienord)

                      Email me: [email protected]
                      www.lesliekirk.com

                      Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

                      Comment


                        #12
                        So I'm using the View Variable on Live Page to try and see what's going on with this code I'm using

                        Code:
                        <!-- Start of Google Reviews -->
                        <script src="https://apis.google.com/js/platform.js?onload=renderOptIn" async defer></script>
                        
                        <script>
                          window.renderOptIn = function() {
                            window.gapi.load('surveyoptin', function() {
                              window.gapi.surveyoptin.render(
                                {
                                  // REQUIRED FIELDS
                                  "merchant_id": XXX,
                                  "order_id": "&mvt:order:id;",
                                  "email": "&mvt:order:bill_email;",
                                  "delivery_country": "US",
                        // DATE
                        <!--Set a time stamp for test -->
                        <mvt:assign name="l.settings:order:orderdate" value="1516375646" />
                        <!-- assign est_arrival_ts as date + 7 days-->
                        <mvt:assign name="l.settings:order:est_arrival_ts" value="l.settings:order:orderdate + (60 * 60 * 24 * 7)" />
                        
                        <!-- calculate the arrival year, month, day using est_arrival_date, here you were calculating based on original order date--> 
                        <mvt:assign name="l.settings:order:est_arrival_year" value="time_t_year( l.settings:order:est_arrival_ts ,g.Merchant_Local_Timezone)" />
                        <mvt:assign name="l.settings:order:est_arrival_month" value="padl(time_t_month( l.settings:order:est_arrival_ts ,g.Merchant_Local_Timezone), 2, 0)" />
                        <mvt:assign name="l.settings:order:est_arrival_day" value="padl(time_t_dayofmonth( l.settings:order:est_arrival_ts ,g.Merchant_Local_Timezone), 2, 0)" />
                        // PRINT DATE
                             <!-- print new data, using new variables -->
                        "estimated_delivery_date": "&mvt:order:est_arrival_year;-&mvt:order:est_arrival_month;-&mvt:order:est_arrival_day;",
                        
                                  // OPTIONAL FIELDS
                        
                                  "products": [
                                  <mvt:foreach iterator="item" array="order:items">
                                  {"gtin":"&mvte:item:code;"},
                                      </mvt:foreach> ]
                                });
                            });
                          }
                        </script>
                        <!-- End of Google Reviews -->
                        When I view the source I'm not seeing the two additional comments // DATE and // PRINT DATE


                        Code:
                        window.renderOptIn = function() {
                        window.gapi.load('surveyoptin', function() {
                        window.gapi.surveyoptin.render(
                        {
                        // REQUIRED FIELDS
                        "merchant_id": XXX,
                        "order_id": "258010",
                        "email": "[email protected]",
                        "delivery_country": "US",
                        "estimated_delivery_date": "--",
                        // OPTIONAL FIELDS
                        "products": [
                        {"gtin":"NAENUG"},
                        {"gtin":"CATCAO"},
                        ]
                        });
                        });
                        }
                        Those comments appear as expected on the test page. So what is preventing this from working on this store's INVC page?
                        Leslie Kirk
                        Miva Certified Developer
                        Miva Merchant Specialist since 1997
                        Previously of Webs Your Way
                        (aka Leslie Nord leslienord)

                        Email me: [email protected]
                        www.lesliekirk.com

                        Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

                        Comment


                          #13
                          If this is actual code,

                          <script src="https://apis.google.com/js/platform.js?onload=renderOptIn" async defer></script>

                          Should be after the script values code generation.





                          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


                            #14
                            Originally posted by Bruce - PhosphorMedia View Post
                            If this is actual code,

                            <script src="https://apis.google.com/js/platform.js?onload=renderOptIn" async defer></script>

                            Should be after the script values code generation.




                            That makes a lot of sense. I just placed per Google's instructions.
                            Leslie Kirk
                            Miva Certified Developer
                            Miva Merchant Specialist since 1997
                            Previously of Webs Your Way
                            (aka Leslie Nord leslienord)

                            Email me: [email protected]
                            www.lesliekirk.com

                            Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

                            Comment


                              #15
                              Oh, and yea...if you need to test things against the various Order arrays, the easiest way is to use a Template Email as those are the same arrays used on the INVC screen and can just be rerun from an order in the Admin.
                              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

                              Working...
                              X