簡體   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