Skip to content

Instantly share code, notes, and snippets.

@mklooss
Created October 22, 2014 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mklooss/24515432019ec8b65d13 to your computer and use it in GitHub Desktop.
Save mklooss/24515432019ec8b65d13 to your computer and use it in GitHub Desktop.
Show Attribute Name in Select Box on an Configurable Product
<script type="text/javascript">
Product.Config.prototype.fillSelect = function(element){
var attributeId = element.id.replace(/[a-z]*/, '');
var options = this.getAttributeOptions(attributeId);
this.clearSelect(element);
element.options[0] = new Option('', '');
element.options[0].innerHTML = this.config.attributes[attributeId].label + ' <?php echo $this->__('Choose') ?>';
var prevConfig = false;
if(element.prevSetting){
prevConfig = element.prevSetting.options[element.prevSetting.selectedIndex];
}
if(options) {
var index = 1;
for(var i=0;i<options.length;i++){
var allowedProducts = [];
if(prevConfig) {
for(var j=0;j<options[i].products.length;j++){
if(prevConfig.config.allowedProducts
&& prevConfig.config.allowedProducts.indexOf(options[i].products[j])>-1){
allowedProducts.push(options[i].products[j]);
}
}
} else {
allowedProducts = options[i].products.clone();
}
if(allowedProducts.size()>0){
options[i].allowedProducts = allowedProducts;
element.options[index] = new Option(this.getOptionLabel(options[i], options[i].price), options[i].id);
if (typeof options[i].price != 'undefined') {
element.options[index].setAttribute('price', options[i].price);
}
element.options[index].config = options[i];
index++;
}
}
}
};
var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment