4

When I tried following code, it will just print empty string. How can I get product min sale quantity on this page?

catalog/product/list.phtml

<?php echo $_product->getStockItem()->getMinSaleQty(); ?>
newbie
  • 24,286
  • 80
  • 201
  • 301

3 Answers3

9

This code solved my problem, because I use quantity increments:

$productData = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);
$qtyIncrements = $productData->getQtyIncrements();
newbie
  • 24,286
  • 80
  • 201
  • 301
  • Works brilliantly, thank you for sharing. Used it to edit AW's iphone template code. They look for minimum qty, but not increments. I changed the qty input type from hidden and also used your code to pre-populate the field in their `addtocart.phtml` file. *all this info is for the next googler* – Krista K Jul 29 '15 at 02:03
1
$_stock_data = $product->getStockItem()->getData();

$_qtde_min = (intval($_stock_data['min_sale_qty'])) ? intval($_stock_data['min_sale_qty']) : 1;
Brandon
  • 68,708
  • 30
  • 194
  • 223
  • Consider adding some comments to your code. Check this [metaSO question](http://meta.stackexchange.com/questions/7656/how-do-i-write-a-good-answer-to-a-question) and [Jon Skeet: Coding Blog](http://msmvps.com/blogs/jon_skeet/archive/2009/02/17/answering-technical-questions-helpfully.aspx) on how to give a correct answer. – Yaroslav Oct 26 '12 at 06:50
  • This code doesn't check for required increment quantity, so it won't help when min qty is 1 (valid) but increments are >1. `getMinSaleQty()` should check for increments and adjust itself accordingly. – Krista K Jul 29 '15 at 02:06
0
<?php $loadProduct = Mage::getModel('catalog/product')->load( $_product->getId() ); ?>
                    <label for="qty"><?php echo $this->__('Minimum Quantity:') ?><span class="h1">
                    <?php echo $this->getMinimalQty($loadProduct); ?></span>Piece/s </label>

This code is Working 100% OK!