简体   繁体   中英

Fatal error: Call to a member function isVirtual() on a non-object

We are facing fatal error in the cart page:

Fatal error: Call to a member function isVirtual() on a non-object in return $this->getConfig()->isEnabled() && !$this->getProduct()->isVirtual();

Full code : app/code/community/WebDevlopers/ProductPageShipping/Block/Estimate/Abstract.php

<?php
abstract class WebDevlopers_ProductPageShipping_Block_Estimate_Abstract extends Mage_Catalog_Block_Product_Abstract
{

    protected $_estimate = null;



    protected $_config = null;



    protected $_session = null;


    protected $_carriers = null;


    public function getEstimate()
    {
        if ($this->_estimate === null) {
            $this->_estimate = Mage::getSingleton('webdevlopers_productpageshipping/estimate');
        }

        return $this->_estimate;
    }


    public function getConfig()
    {
        if ($this->_config === null) {
            $this->_config = Mage::getSingleton('webdevlopers_productpageshipping/config');
        }

        return $this->_config;
    }


    public function getSession()
    {
        if ($this->_session === null) {
            $this->_session = Mage::getSingleton('webdevlopers_productpageshipping/session');
        }

        return $this->_session;
    }


    public function isEnabled()
    {
        return $this->getConfig()->isEnabled() && !$this->getProduct()->isVirtual();
    }
}

Being that your model extends from a Product model, the getProduct() method should be valid. You may be using it outside of the regular Magento product view context which may be causing this error.

You should check that the product exists before trying to use it:

return $this->getConfig()->isEnabled() && $this->getProduct() && !$this->getProduct()->isVirtual();

To avoid modifying community code, you should extend this class into the local pool and make the change in a local class.

I've submitted a pull request to the main repository to get this fixed for future. It's a harmless change for regular use, so wouldn't hurt to have it in there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM