Pages

Thursday 15 January 2015

Magento:: Display Dropdown For Quantity Box

In the addtocart.phtml file find the following code(near line 34)
<input type="text" pattern="\d*" name="qty" id="qty" maxlength="12" value="<?php echo max($this->getProductDefaultQty() * 1, 1) ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
Replace with this code:
1-This code shows the “Available Qty for Product”.
<select class="input-text qty" name="qty" id="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>
2- This code shows the “Maximum Qty Allowed in Shopping Cart”.
<select class="input-text qty" name="qty" id="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)->getMaxSaleQty()) ?>
</select>

No comments:

Post a Comment