I\'m working on the display of the stock availability on the (individual) product page of my Magento theme, and there\'s something I don\'t completely understand about this.
If I'm not mistaken, the difference in these checks has to do with reservations of products for placed orders. When a customer adds products to an order, these products will still be in your stock, so they are still available. Though, they aren't saleable, because they have already been ordered by another customer.
So the semantic difference is:
You could try to validate this by placing an order for a product. And doing the same check as you already did. This should cause a difference between the amount of available products and the amount of saleable products.
Edit: More info here:
https://blog.magestore.com/magento-multi-source-inventory-msi/#a3
isSeable()
looks like it's checking if it reaches 0
isAvailable()
looks like it's counting
As far as my concern, isSaleable()
means you are checking the top most product that is ready for sale. While isAvailable()
means you are checking the product from the lists that are available.
isAvailable() is used to decide whether to display the product as in stock or out of stock, while isSaleable() is used to decide whether to show an Add to cart button or not.
I see those having semantic differences. An item that is not in stock can still be saleable if said item is set to allow backorders.
As far as I can tell, it looks like isAvailable
checks a product type instance to see if the product type could be for sale if it is indeed available.
So, to venture a guess at when you might choose one over the other:
If you are checking an individual product to see if said product is actually ready for sale, you should use isSalable()
, as it will call isAvailable()
.
To check if a product (whose type you don't know off hand) could be sold, and I suppose skipping the step of checking the product's type, you could call isAvailable()
on the product.
isAvailable()
checks if a product's type is salable.
isSalable()
checks if a product is salable.
isSaleable()
is an alias of isSalable()
.