繁体   English   中英

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

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

我们在购物车页面上面临致命错误:

致命错误:在非对象上调用成员函数isVirtual()以return $this->getConfig()->isEnabled() && !$this->getProduct()->isVirtual();

完整代码: 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();
    }
}

由于您的模型是从Product模型扩展而来的,因此getProduct()方法应该有效。 您可能在常规的Magento产品视图上下文之外使用它,这可能会导致此错误。

在尝试使用该产品之前,应检查该产品是否存在:

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

为了避免修改社区代码,您应该将此类扩展到本地池中,并在本地类中进行更改。

我已经向主存储库提交了拉取请求,以在将来修复此问题。 对于常规使用而言,这是无害的更改,因此将其放在其中不会有任何伤害。

暂无
暂无

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

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