简体   繁体   English

致命错误:在 magento 中的非对象上调用成员函数 getLevel()

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

I am new to magento,recently developed one site but in search box if i search anything it shows this message我是 magento 的新手,最近开发了一个网站,但在搜索框中,如果我搜索任何内容,它会显示此消息

Fatal error: Call to a member function getLevel() on a non-object in /home/bjcprod2/public_html/app/design/frontend/amazon/default/template/catalog/product/list.phtml on line 32致命错误:在第 32 行的/home/bjcprod2/public_html/app/design/frontend/amazon/default/template/catalog/product/list.phtml 中的非对象上调用成员函数getLevel()


 <?php
    $productOnLine = 4;
    $_productCollection=$this->getLoadedProductCollection();
    $_collectionSize = $_productCollection->count();
?>
<?php 
$_category = Mage::registry('current_category');
if($_category) {
    $id = $_category->getId();
    $name = $_category->getName();
    //Zend_Debug::dump($id);
    $styletemplate = (int)$_category->getStyletemplate();   //echo $styletemplate;
    $totalPerPage = ($this->show_total) ? $this->show_total :4;
    $counter = 1;
    $visibility = array(
            Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
            Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
    );
    $storeId = Mage::app()->getStore()->getId();

    $_productCollection1 = Mage::getResourceModel('reports/product_collection')
    ->addAttributeToSelect('*')
    ->addOrderedQty()
    ->addAttributeToFilter('visibility', $visibility)
    ->setStoreId($storeId)
    ->addCategoryFilter(Mage::getModel('catalog/category')->load($id))
    ->setOrder('ordered_qty', 'desc');
    $categoryc = Mage::getModel('catalog/category')->load($id);
    $children = explode(',', $categoryc->getChildren());
}
if($_category->getLevel() == 2){    include('category_'.$styletemplate.'.phtml');   }else{  include('list_'.$styletemplate.'.phtml');}
?>

please help.请帮忙。

Thanks in advance.提前致谢。

In the posted code, $_category is set by loading the current category out of the registry:在发布的代码中, $_category 是通过从注册表中加载当前类别来设置的:

$_category = Mage::registry('current_category');

On the next line, notice that it tests whether $_category has loaded an object before proceeding:在下一行,请注意它在继续之前测试 $_category 是否已加载对象:

if($_category) {. . .

Later the code calls getLevel() on $_category, but in this case it does not test first to see if $_category is an object.稍后代码在 $_category 上调用 getLevel(),但在这种情况下,它不会首先测试 $_category 是否是一个对象。

if($_category->getLevel() == 2). . .

This allows the error you are getting to occur.这允许您发生错误。

You could modify the code to check that $_category is an object.您可以修改代码以检查 $_category 是否为对象。 Something like:就像是:

if($_category && $_category->getLevel() == 2)
{
    include('category_'.$styletemplate.'.phtml');
} else {
    include('list_'.$styletemplate.'.phtml');
}

暂无
暂无

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

相关问题 Magento:致命错误:在非对象上调用成员函数 getMethodInstance() - Magento : Fatal error: Call to a member function getMethodInstance() on a non-object Magento致命错误-在非对象上调用成员函数getId() - Magento Fatal Error - Call to a member function getId() on a non-object Magento致命错误:在非对象上调用成员函数save() - Magento Fatal error: Call to a member function save() on a non-object 致命错误:在Magento中的非对象上调用成员函数getIdFieldName() - Fatal error: Call to a member function getIdFieldName() on a non-object in Magento Magento:致命错误:在非对象上调用成员函数 load() - Magento: Fatal error: Call to a member function load() on a non-object 致命错误:在magento中的非对象上调用成员函数getEmail() - Fatal error: Call to a member function getEmail() on a non-object in magento Magento致命错误:在非对象上调用成员函数addFieldToFilter() - Magento Fatal error: Call to a member function addFieldToFilter() on a non-object Magento致命错误:在非对象上调用成员函数getSku() - Magento Fatal Error: Call to member function getSku() on a non-object Magento:致命错误:在非对象上调用成员函数getItems() - Magento: Fatal error: Call to a member function getItems() on a non-object Magento PHP致命错误:在非对象上调用成员函数setName() - Magento PHP Fatal error: Call to a member function setName() on a non-object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM