cancel
Showing results for 
Search instead for 
Did you mean: 

Display "Max Order Limit: XX" in Product page?

Display "Max Order Limit: XX" in Product page?

I'm using 2.1.7. I'd like to have this on each products page:

Max Order Limit: XX

With XX being the Maximum Qty Allowed in Shopping Cart setting on the products settings page. Whats the code to add that to the product's page?

2 REPLIES

Re: Display "Max Order Limit: XX" in Product page?

Bump... Anyone know the call or this?

Re: Display "Max Order Limit: XX" in Product page?

Hello,

You can get Max Order limit by below way in product page,


First way,

Using directly Objectmanager,

 

You can get Max Sale Qty for each product using,

$productId = 10;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$stockManager = $objectManager->get('\Magento\CatalogInventory\Model\Stock\StockItemRepository')->get($productId);
$maxQtyForProduct = $stockManager->getMaxSaleQty();

<div class="maxorderlimit"><?php echo __("Max Order Limit: $maxQtyForProduct"); ?></div>

Second Way,
Create Block file,

<?php
namespace Test\Maxsale\Block;
class Test 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 getStockItemData($productId)
    {
        return $this->stockItemRepository->get($productId);
    }
}
?>

Create template file,

 

$productId = 10;
$itemStock = $block->getStockItemData($productId);
echo "<pre>";print_r($itemStock->getData()); 

 

if issue solved, Click Kudos/Accept as solutions.

If Issue Solved, Click Kudos/Accept As solutions.