2

I have a problem with one of the products. For some reason it doesn't display a buy button. I dig into the core and I figured it out that the problem with this value. Inside function isSalable() It returns at the step

if ($this->hasData('salable')) {
    return $this->getData('salable');
}

And it returns 'false', but I don't know why. Other methods like isAvailable() or isInStock() or getStatus() return true. Anyone can help me with this?

Thanks.

  • maybe this helps: magento.stackexchange.com/q/5238/146 – Marius Sep 19 '17 at 9:08
  • Thank you @Marius, I've seen that, but it doesn't help. It's about magento 1. My question about magento2 – spiil Sep 19 '17 at 9:44
  • I think the code and explanation is very similar to m1. Just the syntax is different. – Marius Sep 19 '17 at 11:13
0

'salable' set from Magento/Catalog/Model/Product.php

Check function isSalable() from above file.

salable set from isSalable function with line,

$this->setData('salable', $object->getIsSalable()); 

Thanks.

0

I don't mean to repeat but to expand upon other answer.

https://github.com/magento/magento2/blob/00fb2aa3e258ab728f8e2fec1e99bc9b5f562221/app/code/Magento/Catalog/Model/Product.php#L1672-L1696

    public function isSalable()
    {
        if ($this->_catalogProduct->getSkipSaleableCheck()) {
            return true;
        }
        if (($this->getOrigData('status') != $this->getData('status'))
            || $this->isStockStatusChanged()) {
            $this->unsetData('salable');
        }
        if ($this->hasData('salable')) {
            return $this->getData('salable');
        }
        $this->_eventManager->dispatch('catalog_product_is_salable_before', ['product' => $this]);
        $salable = $this->isAvailable();
        $object = new \Magento\Framework\DataObject(['product' => $this, 'is_salable' => $salable]);
        $this->_eventManager->dispatch(
            'catalog_product_is_salable_after',
            ['product' => $this, 'salable' => $object]
        );
        $this->setData('salable', $object->getIsSalable());
        return $this->getData('salable');
    }

Not seeing any different in behavior in 2.1

https://github.com/magento/magento2/blob/2.1/app/code/Magento/Catalog/Model/Product.php#L1630-L1654

So it's checked. If exists it returns which is this part if ($this->hasData('salable')) {. If not exist it is set with $this->setData('salable', $object->getIsSalable()); part after event.

So it can be in a situation where it doesn't return before that line.

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.