What is the difference between isSaleable() and isAvailable()?

后端 未结 5 1718
无人共我
无人共我 2021-01-30 19:46

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.

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-30 20:50

    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().

提交回复
热议问题