0

I am confused between is_salable and is_in_stock field. in product listing page I print $product object by $product->getData() and when I print this data there is a field called is_salable I put somewhere condition for product isinstock or outof stock so can I check the product with like this condition $product->getIsSalable() ?

Your help would be appreaciated

0

is_in_stock uses the status on the product, so you can change the stock status to out of stock, but still have qty available.

is_saleable is heavily used for grouped, bundle and configurable products and uses the event catalog_product_is_salable_after to return availability

1
  • is_salable internally check product stock status or product status ? Aug 6 '21 at 21:58
0

Looking at the Magento core code

\Magento\Catalog\Model\Product::getIsSalable

The logic of the function says that if getIsSalable function exits or product has a value as is_saleable then the product is able to be purchased.

/**
     * Is product salable detecting by product type
     *
     * @return bool
     * @SuppressWarnings(PHPMD.BooleanGetMethodName)
     */
    public function getIsSalable()
    {
        $productType = $this->getTypeInstance();
        if (method_exists($productType, 'getIsSalable')) {
            return $productType->getIsSalable($this);
        }
        if ($this->hasData('is_saleable')) {
            return $this->getData('is_saleable');
        }

        return $this->isSalable();
    }

However, in this Magento Stackexchange, are some better explanation for what you are looking for: Differences between some stock methods

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.