[英]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.