2016-05-18 51 views
0

我們正面臨着致命的錯誤在購物車頁面:致命錯誤:調用一個成員函數isVirtual()一個非對象

Fatal error: Call to a member function isVirtual() on a non-object in 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(); 
    } 
} 
+0

首先,這是你自己的擴展?如果是這樣,你在什麼情況下調用該塊?因爲它從一個Product塊擴展而來,所以你應該總是能夠調用'$ this-> getProduct()'而不用返回false/null。快速獲勝將是'return $ this-> getConfig() - > isEnabled()&& $ this-> getProduct()&&!$ this-> getProduct() - > isVirtual();'a la check'getProduct() '在使用之前返回一個真理 –

+0

@RobbieAverill這不是我的擴展。你可以告訴我什麼代碼,我需要用'return $ this-> getConfig() - > isEnabled()&&!$ this-> getProduct() - > isVirtual();' – fresher

+0

代替我剛剛給你的代碼: )與任何人編寫擴展名,並讓他們修復它。如果你願意的話,我可以解釋一下你如何使一個*本地*模型覆蓋,以防止黑客攻擊一個社區類,但要確保這個修改是首先運行的,否則它不值得做。 –

回答

1

是指您模型從產品模型擴展而來,getProduct()方法應該是有效的。您可能會在可能導致此錯誤的常規Magento產品視圖上下文之外使用它。

您應檢查產品存在嘗試使用它之前:

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

避免修改社區的代碼,你應該繼承這個類到本地池,並在局部類的變化。

我已將a pull request提交到主存儲庫以便將來修復此問題。對於正常使用來說這是一個無害的改變,所以不會因爲它在那裏而受到傷害。

相關問題