0

Can anyone tell me how to update the options (using a dropdown select) of a configurable product that is already in the cart in Magento.

I put the code to show the super attributes options (using a dropdown list) of a configurable product in the following file: magento\app\design\frontend\default\theme-name\template\checkout\cart\item\default.phtml.

I found a line with this code:

<?php if ($_options = $this->getOptionList()):?>

After that, I put my code to show the attribute dropdown list for configurable products, and its working fine, but I need to update the super attribute option values for that product when I select another option from the super attribute dropdown list. Below is my code to show the dropdown:

<?php
if($this->getProduct()->isConfigurable()){
    $_product = Mage::getModel('catalog/product')->load($this->getProduct()->getId());
    Mage::getBlockSingleton('catalog/product_view_type_configurable')->unsetData();
    $_configurable = Mage::getBlockSingleton('catalog/product_view_type_configurable')->setData('product', $_product);
    $_cdata = json_decode($_configurable->getJsonConfig());
    $_current = array();
    foreach((array)$this->getOptionList() as $_option) {
        $_current[$_option['label']]=$_option['value'];
    }
    foreach($_cdata->attributes as $attribute) {
        ?>
        <strong><?php echo $attribute->label;
        $catchlabel = $attribute->label;
        if($catchlabel == 'Clipboard Color'):
            $SelectOptions = "selectAtt";
        else:
            $SelectOptions = "selectFont";
        endif;
        ?>
        </strong>
        <select style="width: 150px;"
name="cart[<?php echo $_item->getId() ?>][option][<?php echo $attribute->id ?>]"
id="<?php  echo $_item->getId(); ?>_<?php echo $attribute->id;  ?>"
class="<?php echo $SelectOptions; ?>">
            <?php
            foreach($attribute->options as $option) {
                ?>
                <option
                <?php echo ($_current[$attribute->label]==$option->label) ? ' selected' : '' ?>
                    value="<?php echo $option->id ?>">
                    <?php echo $option->label ?>

                </option>
                <?php
            }
            ?>
        </select> 
        <script type="text/javascript">
            jQuery('#<?php  echo $_item->getId(); ?>_<?php echo $attribute->id;  ?>').change(function() {
                var getOption = jQuery('#<?php  echo $_item->getId(); ?>_<?php echo $attribute->id;  ?>').val();
                // something to do here for update attibute options for current product
                alert(getOption);
            });
        </script> <?php
    }
}
?>

please tell me how to update the super attribute options of the selected configurable product.

Expedito
  • 7,771
  • 5
  • 30
  • 43
developer
  • 1
  • 1
  • 4

1 Answers1

0

You need to submit the new configuration info to a controller action that handles the updates.

Magento has no such controller action, BUT, when you edit a single configurable product in the cart you get the product view with a slightly different markup. The form in that page is used to edit the product in the cart instead of adding a new one.

You should check the algorithm in that controller action and create a module with a controller that applies that algorithm on every product in your cart

barbazul
  • 608
  • 6
  • 8