Announcement

Collapse
No announcement yet.

Help Writing Conditional

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

    Help Writing Conditional

    I am trying to setup a conditional for the OCST page that when any one of 12 products are purchased a field shows up. We are using Emporium Plus's Order Custom Fields module.

    Here is what I have and although it is working somewhat, if the last item added to the cart is NOT in the list of included products, then it will not show the field. But the field needs to show when any one of those 12 are in the basket regardless of the other items.
    Code:
    <mvt:if expr="l.settings:item:code EQ 'prod1' OR l.settings:item:code EQ 'prod2' OR l.settings:item:code EQ 'prod3' OR l.settings:item:code EQ 'prod4' OR l.settings:item:code EQ 'prod5' OR l.settings:item:code EQ 'prod6' OR l.settings:item:code EQ 'prod7' OR l.settings:item:code EQ 'prod8' OR l.settings:item:code EQ 'prod9' OR l.settings:item:code EQ 'prod10' OR l.settings:item:code EQ 'prod11' OR l.settings:item:code EQ 'prod12'"><div id="your_id"> <div class="&mvte:global:OrderCFM1_Row;">
    	<mvt:if expr="'|1|' IN g.OrderCFMErrorMessage">
    <span class="red">Error Message</span><br>
    </mvt:if>
    <label class="required">Field Prompt</label> 
    <textarea name="OrderCFM1" value="" style="height:150px;width:170px;"></textarea>
    <input type="hidden" name="OrderCFM_Count" value="1">
    </div></div>
    </mvt:if>
    I also tried the following and it had the same issue
    Code:
    <mvt:if expr="'|'$l.settings:item:code$'|' CIN '|prod1|prod2|prod3|prod4|prod5|prod6|prod7|prod8|prod9|prod10|prod11|prod12|'">

    #2
    Re: Help Writing Conditional

    The last conditional is the best (using CIN) but instead of displaying the message assign a value to a variable and test if the variable is true outside the "for each" loop. When true display the info.
    Andreas Toman
    PCINET, LLC

    Miva Merchant Design, Development, Integration & Support
    We built over 200 Miva Merchant stores!
    Miva shopping cart design & integration service and see our Portfolio!


    e-mail: [email protected]
    web: www.pcinet.com
    LinkedIn: Andreas Toman
    phone: (786) 250-2056 (Miami, FL)

    Comment


      #3
      Re: Help Writing Conditional

      I tried to look up how to do that through the Developer Training Series documentation but I didn't understand how to set it up. This is as far as I got and then I got stuck:
      Code:
      <mvt:assign name="l.training-item" value=" 'true' " />
      Thanks

      Comment


        #4
        Re: Help Writing Conditional

        Here is what it would look like.

        Code:
        <mvt:foreach iterator="item" array="basket:items">
            <mvt:if expr="'|'$l.settings:item:code$'|' CIN '|prod1|prod2|prod3|prod4|prod5|prod6|prod7|prod8|prod9|prod10|prod11|prod12|'">
         
                     //one of the products listed is in the cart. Set a flag.
                     <mvt:assign name="l.training-item" value=" 'true' " />
           
            </mvt:if>
        </mvt:foreach>
        Then we can check for our variable when you want to display the error message:


        Code:
        <mvt:if expr="l.training-item EQ 'true'">
          Display Custom Message Here
        </mvt:if>
        Last edited by Brennan; 01-17-14, 08:53 AM.
        Brennan Heyde
        VP Product
        Miva, Inc.
        [email protected]
        https://www.miva.com

        Comment


          #5
          Re: Help Writing Conditional

          I added this block of text where I had the Order Custom Field code before on the OCST page:
          Code:
          <mvt:foreach iterator="item" array="basket:items">    <mvt:if expr="'|'$l.settings:item:code$'|' CIN '|HrRgt911|BFE|DV|Stress|SI|Basic|CTP|Shooter|Liability|Callers|CS|BIO|'">           
                       <mvt:assign name="l.training-item" value=" 'true' " />
             
              </mvt:if>
          </mvt:foreach>
          
          
          <mvt:if expr="l.training-item EQ 'true'">
            <div class="&mvte:global:OrderCFM1_Row;">
          	
          <label class="required">Please enter names &amp;<br />emails of all students:</label> 
          <textarea name="OrderCFM1" value="" style="height:150px;width:170px;"></textarea>
          
          
          <input type="hidden" name="OrderCFM_Count" value="1">
          </div>
          </mvt:if>
          But now the field isn't showing up at all. I must have placed the code wrong.

          Comment


            #6
            Re: Help Writing Conditional

            Try this:

            Code:
            <mvt:foreach iterator="item" array="basket:items"> 
            
            <mvt:if expr="'|'$l.settings:item:code$'|' CIN '|HrRgt911|BFE|DV|Stress|SI|Basic|CTP|Shooter|Liability|Callers|CS|BIO|'">           
            	<mvt:assign name="l.trainingItem" value="'true'" />   
            </mvt:if>
            
            </mvt:foreach>
            
            
            <mvt:if expr="l.trainingItem EQ 'true'">
            
            <div class="&mvte:global:OrderCFM1_Row;">
            	<label class="required">Please enter names &amp;<br />emails of all students:</label> 
            	<textarea name="OrderCFM1" value="" style="height:150px;width:170px;"></textarea>
            	<input type="hidden" name="OrderCFM_Count" value="1">
            </div>
            
            </mvt:if>
            Note: Variable Name syntax

            Names start with one of these prefixes and a period ( g., l., s., or d. as explained below ). Periods can only be used after the prefix.
            Names are case in-sensitive (g.name and g.NAME are the same variable).
            Variable names consist of the letters a through z (upper and lower case), the digits 0 through 9, or the underscore ( _ )
            Brackets characters are use to designate array indexes [ ]

            (You had a hypen in the variable name.)

            Also, us IN instead of CIN when you know the exact case of what you are testing. yea, its easier to use CIN but you should be able to use the exact ProductCode case. And IN is much faster.
            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


              #7
              Re: Help Writing Conditional

              That works - thank you so much Andreas, Brennan and Bruce!

              Comment


                #8
                Re: Help Writing Conditional

                If I may, I'd like to ask a few questions about this conditional. I'm trying to accomplish a very similar result, display a message during checkout that displays when when there's any one of 200 different products in the basket. My hope is to be able to use the product name rather than the product code because these 200 products have a common word in their names. The word "Lumber". However, all of these products are also loaded into a category together so maybe that might be a good way to approach?

                I'm moderately capable with SMT, but only through years of trial and error (mostly error!) so I don't understand the characters |'$ in the sample mvt:if above. Can someone explain or point me to the doc?

                Based on what I read above, here's the code I used to try to accomplish my message. Didn't work out. Thought I'd post here and ask for help:

                Code:
                <mvt:foreach iterator="item" array="basket:items">
                <mvt:if expr="'|'$l.settings:item:name$'|' IN '|Lumber|'">           
                    <mvt:assign name="l.trainingItem" value="'true'" />   
                </mvt:if>
                </mvt:foreach>
                <mvt:if expr="l.trainingItem EQ 'true'">
                <div class="LumberMessage">Message Here</div>
                </mvt:if>
                Thank you,
                Mark
                Last edited by Mark Stephens; 07-07-14, 01:09 PM.

                Comment


                  #9
                  Re: Help Writing Conditional

                  If you are just looking for the word LUMBER, you need:
                  Code:
                  <mvt:if expr=" 'lumber CIN l.settings:item:name'">
                  The '|$l.variable is meant to create an "EXACT" match. So, your statement was looking for |Lumber| in |This is my product name|. You use the exact matching when you need to match a specific variable (such as a product code or screen name) against a group of names. For example |This Product code| in |This Product Code|That Product Code|Some Other Product Code|...but not |This product code again|Or This Product Code|
                  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


                    #10
                    Re: Help Writing Conditional

                    Very nice, thanks Bruce! I'm impressed at how fast this was answered for me!

                    For posterity, I do ought to point out that the last single quote in your code sample is misplaced. It should go like this, below. Thanks for your help.
                    Code:
                    <mvt:if expr=" 'lumber' CIN l.settings:item:name">

                    Comment

                    Working...
                    X