Last active
December 11, 2015 02:58
-
-
Save luzeduardo/4534103 to your computer and use it in GitHub Desktop.
Magento - Auto choose product attribute in produtct Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>); | |
spConfig.setInitialState = function(dropdown_id){ | |
var dropdown = $(dropdown_id);//select dropdown | |
dropdown[0].remove();//remove empty option from dropdown so it is not selectable after initial selection | |
for( index = 0; index < dropdown.length; index++ ){//change selections in dropdowns | |
if(dropdown[index].value != ""){ | |
dropdown.selectedIndex = index; | |
var element = dropdown; | |
var event = 'change'; | |
if(document.createEventObject){//fire events | |
var evt = document.createEventObject(); | |
return element.fireEvent('on'+event,evt) | |
} else { | |
var evt = document.createEvent("HTMLEvents"); | |
evt.initEvent(event, true, true ); | |
return !element.dispatchEvent(evt); | |
} | |
} | |
} | |
}; | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php foreach($_attributes as $_attribute): ?> | |
<script type="text/javascript"> | |
spConfig.setInitialState("attribute<?php echo $_attribute->getAttributeId() ?>") | |
</script> | |
<?php endforeach; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment