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' )"> [COLOR=#ff0000]<div id="swatch-&mvt:attribute:id;" class="swatches"></div>[/COLOR]
-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 )
{
[COLOR=#ff0000]this.swatches = document.getElementById('swatch-' + attribute.id);[/COLOR]
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;
}
[COLOR=#ff0000]AttributeMachine.prototype.oninitializeswatches = function( attributes, possible )[/COLOR]
[COLOR=#ff0000]{[/COLOR]
[COLOR=#ff0000] $(".swatches").empty();[/COLOR]
[COLOR=#ff0000] this.Initialize_Swatches( attributes, possible );[/COLOR]
[COLOR=#ff0000]}[/COLOR]
</script>
Add this to your Head Tag if you are currently not using jQuery:
Code:
[FONT=monospace]<script type="text/javascript" src="[URL="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"]//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js[/URL]">[/FONT][FONT=monospace]</script>[/FONT][COLOR=#000000][FONT=monospace][/FONT][/COLOR]
Comment