I'm using the Argento Mall Theme
on Magento 1.9.1
and I am trying to overwrite functionality which causes the 2nd and 3rd attributes to revert to "Choose an Option..."
when the user makes a selection on the first drop down menu. What I'd like to happen is have all the drop down menus retain the current selection no matter which attribute is being changed.
For my sample configurable product, the default color
is set to "Orange", the default jacket
is set to "PVC", and the default pulling eye
is set to "no pulling eye". When I change the color
to "Blue", the other two attributes change to "Choose an Option...". I'd like them to stay as the defaults.
Attached are 3 images showing what the defaults are, what happens on a change and what I'd like to happen. See the code below the images.
This is what happens when the color is changed
This is what I'd like to happen
Javascript Code:
//we create new function
spConfig.setInitialState = function(dropdown_id) {
//select dropdown
var dropdown = $(dropdown_id);
//remove empty option from dropdown so it is not selectable after initial selection
dropdown[0].remove();
//change selections in dropdowns
for(index = 0; index < dropdown.length; index++) {
if(dropdown[index].value != "") {
dropdown.selectedIndex = index;
var element = dropdown;
var event = 'change';
//fire events
if(document.createEventObject) {
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);
}
}
}
};
spConfig.setInitialState("attribute92")
spConfig.setInitialState("attribute151")
spConfig.setInitialState("attribute161")
configurable.phtml Code: app/design/frontend/argento/default/template/catalog/product/view/type/options/configurable.phtml
<?php
$_product = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
?>
<?php if ($_product->isSaleable() && count($_attributes)):?>
<dl>
<?php foreach($_attributes as $_attribute): ?>
<dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt>
<dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
<div class="input-box">
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" onchange="update_<?php echo $_attribute->getAttributeId() ?>();" class="required-entry super-attribute-select">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
</div>
</dd>
<?php endforeach; ?>
</dl>
<script type="text/javascript">
var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
//we create new function
spConfig.setInitialState = function(dropdown_id) {
//select dropdown
var dropdown = $(dropdown_id);
//remove empty option from dropdown so it is not selectable after initial selection
dropdown[0].remove();
//change selections in dropdowns
for(index = 0; index < dropdown.length; index++) {
if(dropdown[index].value != "") {
dropdown.selectedIndex = index;
var element = dropdown;
var event = 'change';
//fire events
if(document.createEventObject) {
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);
}
}
}
};
<?php foreach($_attributes as $_attribute): ?>
spConfig.setInitialState("attribute<?php echo $_attribute->getAttributeId() ?>")
<?php endforeach; ?>
</script>
<?php endif;?>