1

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.

These are the default optionsThese are the default options

This is what happens when the color is changedThis is what happens when the color is changed

This is what I'd like to happenThis 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;?>
1

This isn't native Magento behavior or Argento behavior. It appears that it's custom coding that was added from this answer: https://stackoverflow.com/a/22006071/5900604

I would get rid of that code and search for an extension on Magento Connect or a module on GitHub. Otherwise, you're subject to issues when switching themes and inconsistent coding.

| improve this answer | |
  • 1
    I haven't found an extension or module that will make the dropdowns behave like I want them to but I appreciate the advice on getting rid of the code. Thanks! – NotJay Mar 11 '16 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.