Announcement

Collapse
No announcement yet.

Display Ship Date at Attribute Level

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

    Display Ship Date at Attribute Level

    To allow Pre-Ordering of backordered items, I have a custom field enabled to show Est Ship Date, instead of setting inventory to 0 and displaying Sold Out. Works fine except I need it to work at the attribute level for products with Inventory Variants. Since Inventory Variants are inactive products, using the Custom Field on the backend PROD page doesn't work. If I use the custom field for the main product, it displays doesn't change for Inventory Variants. So All or Nothing


    Goal Example: Display would be via the Inventory Message

    Product A (Inventory Message: In Stock)
    A-Sm - (Inventory Message: In Stock)
    A-Med - (Inventory Message: Pre-Order ships 02/10)
    A-LG - (Inventory Message: In Stock)

    The only way I can get it to work is to have individual products instead of one product with a dropdown of options. Would prefer the later.

    Have tried:
    Attribute Machine > Inventory Element > inventory-message (Long). Example Message:<span class="red>Pre-Order Est 03/10/19</span> Works but not for Inventory Variants.

    <div id="inventory-message" itemprop="availability" href="https://schema.org/InStock" >
    <mvt:if expr="NOT ISNULL l.settings:product:customfield_values:customfields :baskmessage">
    <span class="sold-out">Pre-Order</span>
    <mvt:elseif expr="l.settings:product:inv_active">&mvt:product: inv_long;</mvt:if> IS THERE CODE I SHOULD ADD HERE FOR INACTIVE?
    </div>
    <mvt:if expr="NOT ISNULL l.settings:product:customfield_values:customfields :baskmessage">
    <span class="sold-out">Ship Est: &mvt:product:customfield_values:customfields:ba skm essage;</span>
    <mvt:elseif expr="NOT ISNULL l.settings:product:customfield_values:customfields :baskmessage">


    Thanks, Diana

    Last edited by diana; 02-09-19, 01:37 PM.
    Diana Hall
    http://aGardenPlace.com

    #2
    You'll need to load the custom field data for the variants yourself. Here is an example of how to do that.

    https://docs.miva.com/code-samples/l...variant-change

    On Variant Change, you'll make a ajax call to pull the data for the variant selected then write the data you need to the page.
    Brennan Heyde
    VP Product
    Miva, Inc.
    [email protected]
    https://www.miva.com

    Comment


      #3
      Thanks Brennan, Just saw your reply so I'll give it a try.

      Regards, Diana
      Diana Hall
      http://aGardenPlace.com

      Comment


        #4
        I added the javascript to the theme.js and created the page with the code on it, but I am not sure what else needs to be done to set this up. I need to check if a variant has data in a certain custom field and run a conditional for it.
        Last edited by afiumano; 10-22-19, 07:42 AM.

        Comment


          #5
          I added the below to the jsPROD section of the theme.js file:
          Code:
          /*call products variants so can use custom fields on them*/
          MivaEvents.SubscribeToEvent('variant_changed', function (product_data) {
          
              var master_code = product_data.product_code;
              var variant_id = product_data.variant_id;
              var url = "/load-variant-data.html?product_code=" + master_code + "&variant_id=" + variant_id;
          
              $.get( url, function( data ) {
                  //Data Bindings
          
                  $("#product_code").html(data.sku);
                  $("#product_name").html(data.name);
          
              });
          
          });
          I created a page called: load-variant-data and pasted the below:

          Code:
          <mvt:if expr="NOT ISNULL g.product_code AND NOT ISNULL g.variant_id">
          <mvt:do file="g.Module_Library_DB" name="l.success" value="Product_Load_Code(g.product_code, l.product)" />
          <mvt:do file="g.Module_Library_DB" name="l.success" value="ProductList_Load_Variant(l.product:id, g.variant_id, l.productvariants)" />
          <mvt:comment>Load Variant Product To Get Description</mvt:comment>  
          <mvt:do file="g.Module_Library_DB" name="l.success" value="Product_Load_Code(l.productvariants[1]:code, l.product)" />
          <mvt:assign name="l.productvariants[1]:descrip" value="l.product:descrip" />
          <mvt:assign name="l.settings:variant" value="l.productvariants[1]" />
             {
               "sku": "&mvtj:variant:sku;",
          "code": "&mvtj:variant:code;",
          "name": "&mvtj:variant:name",
          "weight": "&mvtj:variant:weight",
          "description": "&mvtj:variant:descrip",
          
          <mvt:item name="customfields" param="Read_Product_Code(l.settings:variant:code,'')" />
          <mvt:assign name="g.custom_field_count" value="miva_array_elements( l.settings:customfields )" />
          <mvt:foreach iterator="custom_field" array="customfields">
          "&mvte:custom_field:code;": "&mvtj:custom_field:value;" <mvt:if expr="pos1 LT g.custom_field_count">,</mvt:if>
          </mvt:foreach>
          }
          </mvt:if>
          I am trying to do a conditional on the PROD page for a custom field named 'pre_book'. One inventory variant I have selected as pre_book, the other I do not.
          I have this code at the bottom of the Product Display Layout to try to display some of the variant information to test if it is working but nothing is displaying but "TEST"
          Code:
          TEST - &mvte:custom_field:pre_book;: &mvtj:custom_field:value; &mvt:custom_field:pre_book; &mvtj:custom_field:pre_book;
          <mvt:if expr="NOT ISNULL l.settings:variant:customfield_values:customfields :pre_book AND l.settings:product:customfield_values:customfields :pre_book NE 'none'">
          <mvt:item name="customfields" param="Read_Product_Code(l.settings:variant:code, 'pre_book', g.pre_book)" />
          Pre-Book
          </mvt:if>
          &mvt:variant_option:opt_code;
          Last edited by afiumano; 10-22-19, 07:41 AM.

          Comment


            #6
            I was able to get this to work using the load variant on variant change file referenced above. But now I need the custom field of the variant to display in the basket (and throughout checkout) with the rest of the product attribute info. In checking the tokenlist it is apparent that the value of the custom field is not already available on the basket page since the custom field is ONLY tied to the variant and not the master product. The js seems to only work on the PROD page.

            How can the custom field value of a variant also be used on the checkout pages?
            Last edited by afiumano; 01-13-20, 08:21 AM.

            Comment


              #7
              Just wondering if this is possible and how to go about implementing the ability to show a custom field value of a variant, not master product in the checkout pages?

              Comment


                #8
                The code that is working for showing the variant custom field does not work for the BASK page. Any way to display the variant custom field on the BASK page (as well as subsequent pages throughout checkout)?

                Comment

                Working...
                X