cancel
Showing results for 
Search instead for 
Did you mean: 

Grouped product with drop down list

Grouped product with drop down list

In my store I change grouped product from table to drop down list but now the problem is when I for example select item 3 and then click the add to cart button, in basket item 1 is exist not item 3 !!!

I change grouped.phtml in:

 

app/design/frontend/base/default/template/catalog/product/view/type/grouped.phtml :

 

<?php $this->setPreconfiguredValue(); ?>
<?php $_product = $this->getProduct(); ?>
<?php $_associatedProducts = $this->getAssociatedProducts(); ?>
<?php $_hasAssociatedProducts = count($_associatedProducts) > 0; ?>
<?php if ($this->displayProductStockStatus()): ?>
    <?php if ($_product->isAvailable() && $_hasAssociatedProducts): ?>
        <p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></p>
    <?php else: ?>
        <p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('Out of stock') ?></span></p>
    <?php endif; ?>
<?php endif; ?>
<?php echo $this->getChildHtml('product_type_data_extra') ?>
        <table class="data-table grouped-items-table" id="super-product-table">
            <col />
            <col />
            <col width="1" />
            <!-- Table Header -->
            <thead>
                <tr>
                    <th><?php echo $this->__('Product Name') ?></th>
                    <?php if ($this->getCanShowProductPrice($_product)): ?>
                        <th class="a-right"><?php echo $this->__('Price') ?></th>
                    <?php endif; ?>
                    <?php if ($_product->isSaleable()): ?>
                        <th class="a-center"><?php echo $this->__('Qty') ?></th>
                    <?php endif; ?>
                </tr>
            </thead>
            <!-- Table Body -->
            <tbody>
                <?php if ($_hasAssociatedProducts): ?>
                    <tr>
                        <td class="a-center">
                            <select id="productsHolder">
                                <?php if ($_product->isSaleable()): ?>
                                        <?php 
                                        //$products = array();
                                        foreach ($_associatedProducts as $_item): ?>
                                            <?php $_finalPriceInclTax = $this->helper('tax')->getPrice($_item, $_item->getFinalPrice(), true) ?>
                                            <?php
                                            if ($this->getCanShowProductPrice($_product) && $this->getCanShowProductPrice($_item)) {
                                                $price = $this->getPriceHtml($_item, true);
                                                $tierPrice = $this->getTierPriceHtml($_item);
                                            } else {
                                                $price = 0;
                                                $tierPrice = 0;
                                            }
                                            ?>
                                            <?php if ($_item->isSaleable()) : ?>
                                                <option value="<?php echo $this->escapeHtml($_item->getName()) ?>" 
                                                    price="<?php echo $this->escapeHtml($_item->getPrice()) ?>"
                                                    tierprice="<?php echo $this->getTierPriceHtml($_item) ?>" <?php if ($row['selectedValue'] == $option): ?> selected="selected"<?php endif; ?>>
                                                    <?php echo $this->escapeHtml($_item->getName()) ?>
                                                </option>               
                                            <?php endif; ?>
                                            </option>
                                        <?php endforeach; ?>
                                <?php endif; ?>
                            </select>
                        </td>
                        <td class="price_of_item"><span id="priceHolder" class="price"></span></td>
                        <td class="a-center"">
                            <?php if ($_item->isSaleable()) : ?>
                                <input type="text" name="super_group[<?php echo $_item->getId() ?>]" maxlength="12" value="<?php echo $_item->getQty()*1 ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Qty')) ?>" class="input-text qty" />
                            <?php else: ?>
                                <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                            <?php endif; ?> 
                        </td>
                    </tr>
                <?php else: ?>
                    <tr>
                        <td colspan="<?php if ($_product->isSaleable()): ?>4<?php else : ?>3<?php endif; ?>"><?php echo $this->__('No options of this product are available.') ?></td>
                    </tr>
                <?php endif; ?>
            </tbody>
        </table>

    <script type="text/javascript">
        function setPrices() {
            var price = jQuery('#productsHolder option:selected').attr('price');
            var tierprice = jQuery('#productsHolder option:selected').attr('tierprice');
            var priceHolder = jQuery('#priceHolder');
            var tierpriceHolder = jQuery('#tierpriceHolder');

            if (tierprice == '') {
                priceHolder.removeClass('linethrogh');
                priceHolder.html(price);
                tierpriceHolder.html('');
                } 
                else {
                priceHolder.html(price);
                tierpriceHolder.html(tierprice);
                priceHolder.addClass('linethrogh');
                }
        }

        jQuery(window).load(function() {
            jQuery('#productsHolder').change(setPrices);
            setPrices();
        });
    </script>
<script type="text/javascript">decorateTable('super-product-table')</script>

 

 

Where I was wrong and how can I fix it?