Showing results for 
Search instead for 
Did you mean: 

Product's "is in stock" method erroneous?


Product's "is in stock" method erroneous?

Hello fellow community members,


Today I raised a GitHub issue regarding the isInStock() method of the Product model. This is highlighting the seemingly erroneous functionality of this method. The assumption that I have made, and which I have seen made in other places by other people, is that this method will return whether or not a product is in stock in the current context. However, inspecting the code it would seem this is not the case, and that instead it's just another method of retrieving whether the product is enabled:


* Whether product available in stock
* @return bool
public function isInStock()
return $this->getStatus() == \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED;

This seems counterintuitive. The response from the Magento Community Engineering team to the issue report is "this seems to be correct Magento behaviour". Surely it makes more sense for this method to return the actual stock status of the product, given the name of 'isInStock'? At the very least this is going to cause confusion and errors due to assumptions made based on the name and even comment of this method.


What do you think?





Tags (3)

Re: Product's "is in stock" method erroneous?

Hey Jamie!


Hah, you've stumbled across a Magento gem which I've had the pleasure of being surprised before as well. You probably get that response because it's been the way that Magento have thought about this all the way back to Magento 1.1:

If you've found one of my answers useful, please give "Kudos" or "Accept as Solution" as appropriate. Thanks!

Re: Product's "is in stock" method erroneous?

Hey Tom!


Thanks for the reply. Well I'll be... I hadn't realised it was also this way in M1. I guess it really is the Magento way!