If you have every worked with swatches and have tried to setup a product where there are multiple swatch drop downs on a single product (color, material, etc) you will know that by default Miva groups all swatches into a single "swatches" container.
Here is how you can change it so each swatch group displays next to its corresponding drop down:
1. Add a swatches div for each attribute
- Go to PROD, edit the Product Attribute Template
- Look for the code that starts the swatches drop down:
add this line below the line above:
2. Modify the Generate Swatch Function:
-Go to PROD, then Attribute Machine Tab
- In the Head section replace what is there with this (new code in red):
The code above uses jQuery to empty the swatches div when you change a selection. In order for that to work correctly you also need to have jQuery being called in:
Add this to your Head Tag if you are currently not using jQuery:
Here is how you can change it so each swatch group displays next to its corresponding drop down:
1. Add a swatches div for each attribute
- Go to PROD, edit the Product Attribute Template
- Look for the code that starts the swatches drop down:
Code:
<mvt:elseif expr="( l.settings:attribute:type EQ 'select' ) OR ( l.settings:attribute:type EQ 'swatch-select' )">
Code:
<mvt:elseif expr="( l.settings:attribute:type EQ 'select' ) OR ( l.settings:attribute:type EQ 'swatch-select' )">
<div id="swatch-&mvt:attribute:id;" class="swatches"></div>
-Go to PROD, then Attribute Machine Tab
- In the Head section replace what is there with this (new code in red):
Code:
<script> AttributeMachine.prototype.Generate_Swatch = function( product_code, attribute, option ) { this.swatches = document.getElementById('swatch-' + attribute.id); var swatch = document.createElement( 'li' ); var span = document.createElement( 'span' ); // to vertically center the swatch images var img = document.createElement( 'img' ); img.src = option.image; swatch.appendChild( span ); swatch.appendChild( img ); return swatch; } AttributeMachine.prototype.oninitializeswatches = function( attributes, possible ) { $(".swatches").empty(); this.Initialize_Swatches( attributes, possible ); } </script>
Add this to your Head Tag if you are currently not using jQuery:
Code:
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
Comment