If 5 is the minimum Qty on Advanced Inventory product level for a product then in Product detail page it should as 5 default selected.

How can I achieve this.

enter image description here


go to Catalog > Inventory > Product Stock Options.

enter image description here

In Product Stock Options, find 2 sections: Maximum Qty Allowed in Shopping Cart and Minimum Qty Allowed in Shopping Cart.

enter image description here

In Maximum Qty Allowed in Shopping Cart, enter a number to determine the maximum quantity for products added to cart.

In Minimum Qty Allowed in Shopping Cart, pick customer group and assign the minimum order quantity to that group.


namespace Vendor\Module\Block;
class getQty extends \Magento\Framework\View\Element\Template
    protected $_stockItemRepository;

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,        
        \Magento\CatalogInventory\Model\Stock\StockItemRepository $stockItemRepository,
        array $data = []
        $this->_stockItemRepository = $stockItemRepository;
        parent::__construct($context, $data);

    public function getStockItem($productId)
        return $this->_stockItemRepository->get($productId);

in template file

$id = 123;
$_productStock = $block->getStockItem($id);


<button type="button" title="<?php echo $this->__('Add to Cart') ?>" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
And just replace it with,

<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('Qty') ?>:</label>
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>" />
<?php endif; ?>
<button type="button" onclick="this.form.submit()"><span><span><span><?php echo $this->__('Add to Cart') ?></span></span></span></button>
  • I need it for product level so Catalog >> Products >> under Quantity Advanced Inventory I have provided the value but when I go to detail page its showing as 1 and not as 5 default selected I need to have the default Minimum Qty value selected in the QTY – fernandus Oct 8 '18 at 12:12
  • for particular product – Aditya Shah Oct 8 '18 at 12:12
  • Admin >> Catalog >> Product >> Open product which you want to add >> Inventory >> Minimum Qty Allowed in Shopping Cart. – Aditya Shah Oct 8 '18 at 12:12
  • and after that please flush the cache – Aditya Shah Oct 8 '18 at 12:13
  • Yes I did but it still shows 1 and not 5 – fernandus Oct 8 '18 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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