Skip to content

Error: Call to a member function isSaleable() on null

I’m getting the below error:

[2022-09-20T20:10:16.753904+00:00] main.CRITICAL: Error: Call to a member function isSaleable() on null in C:xampphtdocsmagento2vendormagentomodule-catalogviewfrontendtemplatesproductlistaddtocompare.phtml:32

and the line 32 was contain a code:

<?php if ($product->isSaleable() && $block->isRecurringEnable($product)): ?>

also the $product contains:

public function getProduct()
{
    $product = parent::getProduct();
    if ($product && $product->getTypeInstance()->getStoreFilter($product) === null) {
        $product->getTypeInstance()->setStoreFilter($this->_storeManager->getStore(), $product);
    }
    return $product;
}