Is there an if/else conditional I can use on the BASK page to check the contents of the basket for a specific product?
Announcement
Collapse
No announcement yet.
conditional based on basket contents
Collapse
X
-
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
-
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 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
-
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
-
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>
Comment
-
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/ENDBruce 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
-
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
-
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
-
Re: conditional based on basket contents
Originally posted by Bruce - PhosphorMedia View PostSounds 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>
Suggestions?Last edited by skepticwebguy; 02-10-15, 01:18 PM.
Comment
-
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
Comment