Magento – Magento Configurable Product Page Update Custom Dropdown With Attribute Value

configurable-productdropdown-attributemagento-1productupgrade

So I have a configurable product which has a number of associated simple products.

I am trying to obtain functionality on product page where the user can choose a colour for the product, and then this accordingly updates a second dropdown with the set value for the attribute in the simple product. This second dropdown uses the batch attribute which is a text field attribute and applies to simple products only.

Clearly there needs to be some functionality so the batch value is received in relation to the colour selected, which is the stumbling block at the moment. The current code is just displaying a batch value, which turns out to be the one for the last colour.

At the moment as you can see from the below code, I can get the last batch to be visible in the dropdown, but as described earlier this is not the required functionality. Ideally I need this value to change to the correct batch value which is assigned in the simple products options in the magento admin panel.

<select name="super_attribute[<?php echo $_product->getAttributeText('brand') ?>]"
"class="required-entry" 
optitle="<?php echo strtolower($_product->getLabel()); ?>">
<option><?php echo $simple_product->getBatch();?></option>
</select>

This code is in the configurable.phtml file, all of which can be seen below

<?php

$_product    = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
?>

<?php if ($_product->isSaleable() && count($_attributes)):?>
<?php foreach($_attributes as $_attribute): ?>
<dt><label for="attribute<?php echo $_attribute->getAttributeId() ?>"><?php echo $_attribute->getLabel() ?></label></dt>
<dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]"
 id="attribute<?php echo $_attribute->getAttributeId() ?>" 
class="required-entry super-attribute-select" 
optitle="<?php echo strtolower($_attribute->getLabel()); ?>">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
</dd>

<?php

$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();

foreach($simple_collection as $simple_product)
{

echo  $simple_product->getName() .  "<br>" . $simple_product->getId() . "<br>" . $simple_product->getBatch() . "<br>" ;

}

?>

<select name="super_attribute[<?php echo $_product->getAttributeText('brand') ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>"
"class="required-entry" optitle="<?php echo strtolower($_product->getLabel()); ?>">

<option><?php echo $simple_product->getBatch(); ?></option>

</select>

<?php endforeach; ?>

<script type="text/javascript">
var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
</script>

<?php endif;?>

Best Answer

Screenshots added for the size attribute.

Step 1: Admin > Catalog Attributes > Manage Attributes > Properties

Edit, then "Save and continue edit"

Catalog-Attributes-Manage-Attributes-Properties

Step 2: Same area but click "Manage Label / Options" from left hand column Manage Label / Options


earlier response: Are you talking about this? I have it working but have to do each garment separately via Magento admin.

[![configurable product with two required choices][3]][3]

I copied this section of the code by viewing my working product page's browser developer tools. The page has color and size attributes dropdown boxes.

            <div class="clear"></div>
                                <div class="product-options" id="product-options-wrapper">

<dl>
                <dt><label class="required"><em>*</em>color</label></dt>
    <dd>
        <div class="input-box">
            <select name="super_attribute[85]" id="attribute85" class="required-entry super-attribute-select">
                <option>Choose an Option...</option>
              </select>
          </div>
    </dd>
                        <dt><label class="required"><em>*</em>size</label></dt>
    <dd class="last">
        <div class="input-box">
            <select name="super_attribute[155]" id="attribute155" class="required-entry super-attribute-select">
                <option>Choose an Option...</option>
              </select>
          </div>
    </dd>
            </dl>