简体   繁体   English

致命错误:在非对象上调用成员函数isVirtual()

[英]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(); 致命错误:在非对象上调用成员函数isVirtual()以return $this->getConfig()->isEnabled() && !$this->getProduct()->isVirtual();

Full code : app/code/community/WebDevlopers/ProductPageShipping/Block/Estimate/Abstract.php 完整代码: 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. 由于您的模型是从Product模型扩展而来的,因此getProduct()方法应该有效。 You may be using it outside of the regular Magento product view context which may be causing this error. 您可能在常规的Magento产品视图上下文之外使用它,这可能会导致此错误。

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. 对于常规使用而言,这是无害的更改,因此将其放在其中不会有任何伤害。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误:当它是一个对象时,调用非对象上的成员函数 - Fatal Error: Call to member function on non-object when it is an object 错误致命错误:在非对象上调用成员函数insert() - Error Fatal error: Call to a member function insert() on a non-object 致命错误:在非对象错误上调用成员函数prepare() - Fatal error: Call to a member function prepare() on a non-object ERROR 致命错误:在非对象错误上调用成员函数 query() - Fatal error: Call to a member function query() on a non-object Error Magento:致命错误:在非对象上调用成员函数 load() - Magento: Fatal error: Call to a member function load() on a non-object 致命错误:在非对象cakephp上调用成员函数save() - Fatal error: Call to a member function save() on a non-object cakephp 致命错误:在非对象中调用成员函数bindValue() - Fatal error: Call to a member function bindValue() on a non-object in 致命错误:在非对象中调用成员函数login() - Fatal error: Call to a member function login() on a non-object in 致命错误:在magento中的非对象上调用成员函数getEmail() - Fatal error: Call to a member function getEmail() on a non-object in magento 致命错误:在非对象上调用成员函数count() - Fatal error: Call to a member function count() on a non-object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM