1

The following is edited code from the configurable products block on the detail page of each configurable product. It is the block that populates with the select drop downs such as "color". I am working on a unique project where there will be a specific vendor attached to each simple product.

<?php
$_product    = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
?>
<div id="caitlinVendors">
<?php if ($_product->isSaleable() && count($_attributes)):?>
    <dl>
    <?php foreach($_attributes as $_attribute){ ?>
                <div id="<?php echo $_attribute->getLabel() ?>Box" class="attributeBox">
                    <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() ?>" class="required-entry super-attribute-select">
                                <option><?php echo $this->__('Choose an Option...') ?></option>
                              </select>
                          </div>
                    </dd>
                </div>

    <?php }?>
    <a href="#" class="vendorsButton">Show Vendors</a>
    <div class="clear"></div>
    </dl>
    </div>
    <?php 

    $product_id = $_product->getId();
    $attrValue = Mage::getModel('catalog/product')->load($product_id)->getAttributeText('color');  ?>
    <script type="text/javascript">//Caitlin
        var $j= jQuery.noConflict();
        $j(".vendorsButton").on("click", function(event){
            event.preventDefault();
            $j('#vendorBox').css('visibility','show');
            //console.log($j('#color option').val());
            var secondToLast="#caitlinVendors .attributeBox select:nth-last-child(2)";
            if (!$j("secondToLast option:selected").length){
                var attributeValue=<?=json_encode($attrValue)?>;
                console.log("The value is " + attributeValue);
            }
            if ($j("#vendorBox").is(":hidden")) {
                $j("#vendorBox").slideDown("fast");
            } else {
                $j("#vendorBox").hide();
            }
        });


        var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);

    </script>
<?php endif;?>

I have the vendor select options hidden until "Show Vendors" is selected. I do NOT want "Show Vendors" to be clickable until the last option is selected. Therefore, what I am having trouble with currently is retrieving the value of the selected option. I am trying to retrieve it here:

<?php 

        $product_id = $_product->getId();
        $attrValue = Mage::getModel('catalog/product')->load($product_id)->getAttributeText('color');  ?>

I am then sending it to a javascript function to print to console. I am only getting the value "false". Any ideas?

1
  • I can also so just check that a value is selected. I just don't want the dropdown to be empty. Anyone? Bueller... bueller... Commented Apr 9, 2013 at 14:43

1 Answer 1

1

What about setting the .attr("disabled", true) while no value is selected for the first drop down.

** set this on page load.

1
  • Well how do I check that there is or is not a value in the drop down? Commented Apr 9, 2013 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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