Monday 20 June 2011

Display Magento Available Quantity in DropDown on list.phtml

 <select name="qty">
  <?php $i = 1 ?>
  <?php do { ?>
    <option value="<?php echo $i?>">
      <?php echo $i?>
      <?php $i++ ?>
    </option>
    <?php } while ($i <= (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()) ?>
</select>

Or try this


Set min_sale_qty of a product in backend, go to product inventory tab and find 'Minimum Qty Allowed in Shopping Cart' put desarable quantity there, we have to do this because we have to give equal interval between quantity in dropdow.

note: path can differ according to templete

app\design\frontend\base\default\template\checkout\cart\item\default.phtml

found quantity text box in that file and replace it with code below.

<?php $min_sale_qty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($this->getProduct())->getData('min_sale_qty');
    $total_qyt = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($this->getProduct())->getQty();
     ?>
    <select name="cart[<?php echo $_item->getId() ?>][qty]">
    <?php for($i = $min_sale_qty; $i <= $total_qyt; $i = $i + $min_sale_qty)
      {
      ?>
    <option value="<?php echo $i?>">
      <?php echo $i?>
    </option>
   <?php }?>
   </select>

1 comment:

  1. Hi there,

    Is it possible to change the quanitity text input in the add to cart page into drop down box at the same time the value of the drop down box is different depending on the product?

    I want something to be like this.

    Example.

    An Apple Product should have a drop down box that has this values:
    - 10
    - 20
    - 30

    A Mango Product should have a drop down box that has this values:
    - 30
    - 75
    - 100

    Is there something to be configured or to be coded to have this result.

    Thank You in advance and have a Good Day!

    ReplyDelete