0

I am new to Magento. I am displaying the attributes in table format using foreach in product detail page. Problem i am facing is when i enter the value in any quantity box, it takes the last quantity value to the cart page since i am using foreach loop to display the quantity box.I need to display the exact value which i have entered in the quantity box. Code:

    <table border="1" style="width:100%;">
            <thead>
                <tr>
                    <th>Fabric</th>
                    <th>Color</th>
                    <th>Required Qty</th>
                    <th>Total Cost</th>
                    <th>Cart</th>
                </tr>
            </thead>
            <?php

$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'fabric');
$buttonTitle = $this->__('Add to Cart');
$i=0;foreach ( $attribute->getSource()->getAllOptions(true, true) as $option){
    $i++;
if($i==1) continue;
?>

            <tbody>

                <tr>
                    <td>
                        <?php echo $attributeArray[$option['value']] = $option['label'];
?>
                    </td>
                    <td>
                        <select name="color" id="color">
                            <option>Select Color</option>
                        <?php 
                        $color = Mage::getModel('eav/config')->getAttribute('catalog_product', 'fabric_color');
$j=0;foreach ( $color->getSource()->getAllOptions(true, true) as $option_color){
    $j++;
    if($j==1) continue;?>
  <option value="<?php echo $option_color['value'];?>" price="<?php echo $option_color['price'];?>"><?php echo $option_color['label'];?></option>


<? }
                        ?>
                            </select>
                    </td>
                    <td>

                        <?php if($_product->isSaleable()): ?>
                        <div class="add-to-cart">
                            <?php if(!$_product->isGrouped()): ?>
                            <label for="qty"><?php echo $this->__('Qty:') ?></label>
                            <div class="qty_pan">
                                <input type="text" name="qty" id="qty<?=$i;?>" maxlength="12" value="1" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
                            </div>
                            <?php endif; ?>
                        </div>    
                        <?php endif; ?>

                    </td>
                    <td ><span class="qty<?=$i;?>" id=""><?php echo $_product->getPrice();?></span></td>
                    <td>
                        <button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
<!--                        <span id='ajax_loader' style='display:none'><img src='<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif')?>'/></span>-->

        <?php //echo $this->getChildHtml('', true, true) ?>

                    </td>
                </tr>

            </tbody>

<?php }?>
        </table>

Screenshot: https://imageshack.us/scaled/large/12/detailpage.png

Any help is appreciated!.

1 Answer 1

0

I Got The solution.

We can use Query String to fetch the quantity values to cart.

Yourdomain.com/checkout/cart/add?product=getId();?>&qty=1

You can use the above querystring in href.

Hope this Helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.