Announcement

Collapse
No announcement yet.

conditional based on basket contents

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

    conditional based on basket contents

    Is there an if/else conditional I can use on the BASK page to check the contents of the basket for a specific product?

    #2
    Re: conditional based on basket contents

    Inside the Basket template of the Basket page,

    <mvt:foreach iterator="item" array="basket:items">

    <mvt:if expr="l.settings:item:code EQ 'product-code'">

    or

    <mvt:if expr="'this-portion-of-code' CIN l.settings:item: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


      #3
      Re: conditional based on basket contents

      That almost does it. But, it only works until I add more than one product to the basket. For instance, I tried this:

      Code:
      <mvt:foreach iterator="item" array="basket:items">
      <mvt:if expr="'testProduct' CIN l.settings:item:code">
      SCENARIO 1 (show nothing)
      <mvt:else>
      SCENARIO 2 (show some code)
      </mvt:if>
      </mvt:foreach>
      What happens is, if testProduct is the only product in the basket, SCENARIO 1 happens. If SomeOtherProduct is the only product in the basket, SCENARIO 2 happens. But, if testProduct and SomeOtherProduct are both in the basket, SCENARIO 2 SCENARIO 1 happens.

      What I need is for this to happen: when testProduct is in the basket (by itself OR with another product), SCENARIO 1 should happen and SCENARIO 2 should not happen.

      Comment


        #4
        Re: conditional based on basket contents

        I think you'll need to use a variable to store the status while you loop thru all the items. Something like this:
        Code:
        <mvt:foreach iterator="item" array="basket:items">
          <mvt:if expr="'testProduct' CIN l.settings:item:code">
            <mvt:assign name="g.FoundIt" value="1" />
          </mvt:if>
        </mvt:foreach>
        
        <mvt:if expr="g.FoundIt">
          SCENARIO 1 (show nothing)
        <mvt:else>
          SCENARIO 2 (show some code)
        </mvt:if>
        Last edited by Kent Multer; 11-27-14, 10:56 AM.
        Kent Multer
        Magic Metal Productions
        http://TheMagicM.com
        * Web developer/designer
        * E-commerce and Miva
        * Author, The Official Miva Web Scripting Book -- available on-line:
        http://www.amazon.com/exec/obidos/IS...icmetalproducA

        Comment


          #5
          Re: conditional based on basket contents

          Thank you, Kent. That works perfectly.

          Comment


            #6
            Re: conditional based on basket contents

            Is there a way to modify this code to detect whether a specific attribute of a specific product is in the basket, rather than just detecting a specific product?

            Comment


              #7
              Re: conditional based on basket contents

              Sure the same logic you use to detect a product can be applied to the attributes / options for each loop

              Code:
              <mvt:foreach iterator="option" array="item:options">
                  <mvt:if expr="l.settings:option:opt_code EQ 'my-option-code' ">
                       //do something.
                  </mvt:if>
              </mvt:foreach>
              Brennan Heyde
              VP Product
              Miva, Inc.
              [email protected]
              https://www.miva.com

              Comment


                #8
                Re: conditional based on basket contents

                but again, if you want to flip directly to an else, you have use the flag setting that kent showed...

                some times (ok, all time) ya gotta be specific if you want better directions. the logic of an IF/ELSE is completely different than an IF/END
                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


                  #9
                  Re: conditional based on basket contents

                  Thank you.

                  What I need specifically is something like this:

                  if l.settings:item:code EQ 'testProduct' AND l.settings:option:opt_code EQ 'variantA'

                  then // do something

                  Comment


                    #10
                    Re: conditional based on basket contents

                    How can I modify this code so that it detects exactly when a specific attribute option has been selected from a drop-down menu, and then displays an alert message on the page next to the drop-down menu? And, where in the template should the code go so that it works? Inside the Product Attribute Template or inside the Product Display Layout template? I currently require this on my OUS1 page.

                    Here's what I've tried and can't get it to work.

                    Code:
                    <mvt:foreach iterator="attribute" array="attributes">
                        <mvt:if expr="'my-attribute-code' CIN  l.settings:option:attr_code">
                            // do something
                        </mvt:if>
                    </mvt:foreach>

                    And I tried this:

                    Code:
                    <mvt:foreach iterator="option" array="item:options">
                        <mvt:if expr="l.settings:option:opt_code EQ 'my-option-code'">
                            // do something
                        </mvt:if>
                    </mvt:foreach>
                    Last edited by skepticwebguy; 02-06-15, 12:45 PM.

                    Comment


                      #11
                      Re: conditional based on basket contents

                      Sounds like a job for javascript...

                      <select name="fake" onchange="change(this);">
                      <option value="a" name="a">a</option>
                      <option value="b" name="b">b</option>
                      </select>

                      <script>
                      function change(selBox) {
                      for(var i, j = 0; i = selBox.options[j]; j++) {
                      if(i.value == "b" && selBox.selectedIndex != 0) {
                      alert("you've clicked b");
                      selBox.selectedIndex = 0;
                      }
                      }
                      }
                      </script>
                      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


                        #12
                        Re: conditional based on basket contents

                        Originally posted by Bruce - PhosphorMedia View Post
                        Sounds like a job for javascript...

                        Code:
                        <select name="fake" onchange="change(this);">
                           <option value="a" name="a">a</option>
                           <option value="b" name="b">b</option>
                        </select>
                        
                        <script>
                        function change(selBox) {
                            for(var i, j = 0; i = selBox.options[j]; j++) {
                                if(i.value == "b" && selBox.selectedIndex != 0) {
                                    alert("you've clicked b");
                                    selBox.selectedIndex = 0;
                                }
                            }
                            }
                        </script>
                        I am not actually hand-coding the attribute dropdown menu; Miva is creating it based on the product's attributes. So, I'm not sure where in the template code to place the script you suggested. I replaced "b" with the value I am wanting the script to target (based on viewing the source code and determining the value of the option I am targeting), but no luck. I can't get the alert to appear. Plus, ideally, I would like to target multiple values that all begin with the same word. So, instead of targeting just "b", I want to target all options in the list that begin with "b" like: "b*"

                        Suggestions?
                        Last edited by skepticwebguy; 02-10-15, 01:18 PM.

                        Comment


                          #13
                          Re: conditional based on basket contents

                          You'd need to place mvt expressions to build the JS on the fly for each attribute. This would be down in attribute template. Sorry, but its a bit more work than I can afford to do on the forum. Perhaps Miva could pitch in on it, otherwise, you'd need to get assistance from an integrator if you can't master it on you own.
                          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