cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the product from Stock Item?

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

How to get the product from Stock Item?

I make a dynamic quantity in a custom product and I need to get the product by id.

My class in my module:

 

class Item extends \Magento\CatalogInventory\Model\Stock\Item
{
	public function getQty()
	{
		$_product = $objectManager->get('Magento\Catalog\Model\Product')->load($productId);
	    $attr = $_product->getData('attribute_name');
	    
		return 123;
	}
}

 

 

But after calling "load" magenta freezes. This is because in the method of load caused by my method, and there is begins recursion.

 

How can I get my attribute?

2 REPLIES 2

Re: How to get the product from Stock Item?

Same problem here. Did you find any solutions ?

Re: How to get the product from Stock Item?

Yes. I created my code with sql-commands and didn't use the repository or model.