Announcement

Collapse
No announcement yet.

Helping Reading Custom Field

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

    Helping Reading Custom Field

    I was playing around with something that seems straight forward this morning but I'm obviously missing something. I just added a couple custom product fields so that I can click a checkbox in admin to tag products with some text on the PROD page. I added the variables to the PROD page.

    Code:
    <mvt:item name="customfields" param="Read_Product_Code(l.settings:product:code, 'prod-tag-so', g.prod-tag-so)" />
    <mvt:item name="customfields" param="Read_Product_Code(l.settings:product:code, 'prod-tag-cm', g.prod-tag-cm)" />
    
          <mvt:if expr="g.prod-tag-so EQ 'yes'">
          <div class="product-tag pt-medgray">
          Special Order
          </div>
          </mvt:if>
    
          <mvt:if expr="g.prod-tag-cm EQ 'yes'">
          <div class="product-tag pt-darkgray">
          Custom Made
          </div>
          </mvt:if>
    
    <!-- burt test //-->
    If the checkbox is checked, I want to show the div with text. Nada. Gone in circles a few times looking at similar code in the templates but can't sort it out.

    Any help appreciated.

    #2
    Okay well eventually hit on it via trial and error.

    Code:
          <mvt:if expr="NOT ISNULL g.prod-tag-cm">

    Comment


      #3
      Actually I do need help. This is all trial and error I'm afraid but with the code in red the code in green is correctly added to the PROD page BUT

      1- I don't understand why the code in red is required!? The conditional in the green blocks NOT ISNULL should be true or 'not null' if the field is checked shouldn't they? The conditional in red is apparently false because no text shows in those red condition blocks UNLESS I set them to 'no'. Very confusing
      2-The code in green, as written below shows up on every page using the PROD template - regardless of the checkboxes being checked on the product level. I thought the code in blue was reading the custom field value for that specific product, assigning it to a global value but.... an issue of scope? Do I need to use local variables instead?

      I'd appreciate any help anyone can offer. It's fun to do this stuff but the brain, while creative is not so good at the programming stuff.


      Code:
      <mvt:item name="customfields" param="Read_Product_Code(l.settings:product:code, 'prod-tag-so', g.prod-tag-so)" />
      <mvt:item name="customfields" param="Read_Product_Code(l.settings:product:code, 'prod-tag-cm', g.prod-tag-cm)" />
      
      
            <mvt:if expr="g.prod-tag-so EQ 'yes'">
      
            </mvt:if>
      
            <mvt:if expr="g.prod-tag-cm EQ 'yes'">
      
            </mvt:if>
      
      
            <mvt:if expr="g.prod-tag-so EQ 'yes'">
            <div class="product-tag pt-medgray">
            Special Order
            </div>
            </mvt:if>
      
            <mvt:if expr="NOT ISNULL g.prod-tag-cm">
            <div class="product-tag pt-darkgray">
            <a href="#" data-title="These items are customized for your order and may not be returned.">Custom Made</a>
            </div>
            </mvt:if>
      
      <!-- burt test //-->

      Comment


        #4
        Your issue is the dashes in your names. When miva is evaluating:

        <mvt:if expr="g.prod-tag-so EQ 'yes'">

        It is seeing g.prod <subtract> g.tag <subtract> g.so EQ yes

        As a good rule of thumb, avoid using dashes in variable names especially if you are going to need to evaluate the variable in a conditional statement. Try changing the dashes to underscores and it should work.

        While somewhat hidden, there is a reference to that issue at the bottom of this page: http://docs.miva.com/template-langua...-documentation

        Brennan Heyde
        VP Product
        Miva, Inc.
        [email protected]
        https://www.miva.com

        Comment


          #5
          Ahhh! Thank you! That did it.
          Last edited by habreu; 02-17-17, 10:22 AM.

          Comment


            #6
            Well in case it is useful for anyone else here is the final code. I used it on the PROD and CTGY pages (only on CTGY I swapped the data-title tag for title because the tooltip it was acting weird).

            Here's the CSS...

            Code:
            /* product tag styles */
            .product-tag {
                    display:inline;
                color: #fff;
                border-radius: 3px;
                    padding: 3px;
                font-weight: normal;
                font-size: 10px;
                font-family: "arial narrow";
                margin:2px;
            }
            
            .product-tag a[data-title]:hover:after {
              content: attr(data-title);
              padding: 4px 4px;
              color: #333;
              position: absolute;
              left: 0;
              top: 100%;
              white-space: wrap;
              max-width: 180px;
              z-index: 50px;
              border: 2px solid #333;
              -moz-border-radius: 3px;
              -webkit-border-radius: 3px;
              border-radius: 3px;
              -webkit-box-shadow: 2px 2px 6px 0px rgba(0,0,0,0.2);
              -moz-box-shadow: 2px 2px 6px 0px rgba(0,0,0,0.2);
              box-shadow: 2px 2px 6px 0px rgba(0,0,0,0.2);
              background-color: #ffffe5;
              font-size: 12px;
            }
            
            .product-tag a{
            color: #fff;
            }
            
            .pt-medgray {
            background: #A6A6A6;    
            border: 1px solid #6E6E6E;
            }
            .pt-darkgray {
            background: #6E6E6E;
            border: 1px solid #525252;    
            }
            
            .pt-midnight {
            background: #525252;    
            border: 1px solid #000;
            }

            Here's the code...

            Code:
            <mvt:item name="customfields" param="Read_Product_Code(l.settings:product:code, 'prod_tag_so', g.prod_tag_so)" />
            <mvt:item name="customfields" param="Read_Product_Code(l.settings:product:code, 'prod_tag_cm', g.prod_tag_cm)" />
            
            
                  <mvt:if expr="g.prod_tag_so EQ 'yes'">
                  <div class="product-tag pt-medgray">
                   <a href="#" title="These items may not be stocked or require us to place a special order potentially increasing delivery time. If you need them for a time sensitive project please call for additional information.">Special Order</a>
                  </div>
                  </mvt:if>
            
                  <mvt:if expr="NOT ISNULL g.prod_tag_cm">
                  <div class="product-tag pt-darkgray">
                  <a href="#" title="These items are customized for your order and may not be returned.">Custom Made</a>
                  </div>
                  </mvt:if>
            Here's the result on our site.

            Comment

            Working...
            X