The following script will select yhe first opetion of each simple product:
1. Add the following function in the bottom script just after:
var spConfig = new Product.Config(<?php echo $_jsonConfig ?>);
app/design/frontend/rwd/hubsan/template/catalog/product/view/type/options/configurable.phtml
<script type="text/javascript"> var spConfig = new Product.Config(<?php echo $_jsonConfig ?>); function fireEvent(element,event) { if (document.createEventObject) { // dispatch for IE var evt = document.createEventObject(); return element.fireEvent('on'+event,evt); } else { // dispatch for firefox + others var evt = document.createEvent("HTMLEvents"); evt.initEvent(event, true, true ); return !element.dispatchEvent(evt); } } function setDefaultConfigOptions() { if (spConfigIndex >= spConfig.settings.length) { return; // stop } spConfig.settings[spConfigIndex].selectedIndex = 1; var obj = spConfig.settings[spConfigIndex]; ++spConfigIndex; Event.observe(obj,'change',function(){}); fireEvent(obj,'change'); //window.setTimeout("setDefaultConfigOptions()", 1); // Add a small delay before moving onto the next option } var spConfigIndex = 0; Event.observe(window, 'load', function() { setDefaultConfigOptions(); }); </script>
And add the following script just after to trigger fire click on selected simple product:
<?php if($_GET['color']==''):?> <script type="text/javascript"> jQuery(window).load(function(){ var firstopt; jQuery(".super-attribute-select option").each(function(){ if (jQuery(this).attr('value')!='') { firstopt = jQuery(this).attr('value'); return false; } }); jQuery(".aw-colorswatches-attribute-option").each(function(){ if (jQuery(this).attr('option-id') == firstopt) { jQuery(this).addClass('aw-colorswatches-attribute-option__state-selected'); jQuery(this).trigger('click'); } }); }); </script> <?php endif;?>
0 Comments