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;?>