I want to check is "Manage Stock" is set as Yes or No with specific product. Can anyone help us to get value of product "Manage Stock" attribute value.


Please place below code in any block file.

namespace Meetanshi\HelloWorld\Block;
class HelloWorld 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);

You can call getStockItem(YOUR_PRODUCT_ID) by passing product Id as parameter.

If you are placing above code in block than do it as below.

$productStock = $block->getStockItem($id);

You will get manage stock value of passing product.


|improve this answer|||||
  • You are most welcome :) – Meetanshi Nov 18 '17 at 10:35

You can get Manage Stock attribute value using stock registry.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$stockRegistry = $objectManager->get('Magento\CatalogInventory\Api\StockRegistryInterface');


echo $stockItem->getData('manage_stock');

echo $stockItem->getData('use_config_manage_stock');
|improve this answer|||||

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.