0

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

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>
  • Can you provide some more detail on the size attribute please, what type of input is required in Magento admin? In my example the batch attribute isn't a super attribute, and is a text field. Also is your product a configurable product? – boombap123 May 9 '16 at 9:30
  • Added screenshots. "Catalog input type for store owner" is "dropdown". In the Properties section "apply to" I have it set for simple and configurable products. Seeing the amounts of sizes I have to deal with, if you figure out how to do this with a spreadsheet, please let me know. I downloaded the product .csv and it includes super-attributes that I have not been able to correctly update for other products. – all4learning May 9 '16 at 12:50
  • This is where we differ, as my attribute is a text field I cannot add options like you have, but rather in the product page a text value has to be entered. So what I am trying to do is create a dropdown for an attribute that is a text field. But so that this dropdown changes in accordance with what colour is chosen in the first dropdown. As for your own question I'd recommending creating a separate question for wider reach if you haven't already. – boombap123 May 9 '16 at 13:33
  • I already created my own question both about configurable products and super-attributes and no one has answered. Hope you get your answer. – all4learning May 9 '16 at 13:47

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.