Magento - 致命错误:在第 816 行的 app/code/core/Mage/Eav/Model/Entity/Abstract.php 中的非对象上调用成员函数 getBackend()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13070652/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:44:05  来源:igfitidea点击:

Magento - Fatal error: Call to a member function getBackend() on a non-object in app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 816

phpmagentomagento-1.7

提问by Mr Pablo

Getting this error when trying to use a custom filter inside a custom theme.

尝试在自定义主题中使用自定义过滤器时出现此错误。

I have set up the new attribute "is_featured" and its in an attribute set. I made a product that assigned it as featured (yes/no choice)

我已经设置了新属性“is_featured”及其在属性集中。我制作了一个产品,将其指定为特色(是/否选择)

My home page (in the CMS section) is including the following "panel"

我的主页(在 CMS 部分)包括以下“面板”

<block type="catalog/product" name="catalog.product_featured_list" template="catalog/product/featured_list.phtml" after="-"/>

featured_list.phtml looks like this:

features_list.phtml 看起来像这样:

<?php
$storeId = Mage::app()->getStore()->getId();
$_productCollection=Mage::getResourceModel('reports/product_collection')
        ->addAttributeToSelect(array('name', 'url', 'small_image', 'price', 'short_description'))
        ->addAttributeToFilter('is_featured', 1)
        ->addAttributeToFilter('status', 1)
        ->setPageSize(3)
        ->setStoreId($storeId)
        ->addStoreFilter($storeId);
$_helper = $this->helper('catalog/output');
?>
<?php if($_productCollection->count()): ?>

<section class="content-box clearfix">
    <header>
        <h2>Featured products</h2>
    </header>
    <ul class="featured-products">
            <?php foreach ($_productCollection as $_product): ?>
            <?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
            <li>
                <h3>
                    <a href="<?php echo $_product->getProductUrl(); ?>" title="<?php echo $_productNameStripped; ?>">
                        <?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?>
                    </a>
                </h3>
                <a href="<?php echo $_product->getProductUrl(); ?>" title="<?php echo $_productNameStripped; ?>">
                    <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(212); ?>" width="200" height="200" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
                </a>
                    <div>
                        <ul class="clearfix">
                            <li>From &pound;<?php echo number_format($_product->price, 2) ?></li>
                            <li>
                                <?php
                                $desct = nl2br($this->htmlEscape($_product->getShortDescription()));
                                $desct = strip_tags($_product->getShortDescription());
                                ?>
                                <p>
                                    <?
                                    echo Mage::helper('core/string')->truncate($desct, '100');
                                    ?>
                                    <a href="<?php echo $_product->getProductUrl(); ?>" title="<?php echo $_productNameStripped; ?>">
                                        <?php echo $this->__('more details'); ?>
                                    </a>
                                </p>
                            </li>
                            <li>
                                <form action="<?php echo $this->helper('checkout/cart')->getAddUrl($_product); //echo $this->getAddToCartUrl($_product); ?>" class="product-list-add-to-cart" method="get" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
                                    <?php if(!$_product->isGrouped()): ?>
                                    <label for="qty"><?php echo $this->__('Qty') ?>:</label>
                                    <input type="text" class="input-text qty" name="qty" id="qty" maxlength="12" value="<?php echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>" />
                                    <input type="hidden" name="product" value="<?php echo $_product->getId()?>" />
                                    <?php endif; ?>
                                    <button type="button" class="button" onclick="this.form.submit()"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
                                </form>
                            </li>
                        </ul>
                    </div>
            </li>
        <?php endforeach; ?>
    </ul>
</section>
<?php endif; ?>

It seems like the issue is with the collection at the start of the block. (I can remove this panel form the home page, and the site loads fine)

问题似乎出在块开头的集合上。(我可以从主页中删除此面板,并且站点加载正常)

I'm pretty sure I have all the mentioned attributes available (is_featured looks to be the only custom one)

我很确定我有所有提到的属性可用(is_featured 看起来是唯一的自定义属性)

(this theme was inherited, so I'm not 100% versed in how it works! I'm simply copying it across)

(这个主题是继承来的,所以我不是 100% 精通它的工作原理!我只是复制它)

回答by Jason

I'm currently using 1.7, and whenever I get the "Call to a member function getBackend() on a non-object..." error, it's usually due to calling up the wrong model, or applying a filter to an attribute that doesn't exist in that collection.

我目前使用的是 1.7,每当我收到“调用非对象上的成员函数 getBackend()...”错误时,通常是由于调用了错误的模型,或将过滤器应用于属性该集合中不存在。

After testing your code, it works without issue (mostly...) if I comment out this line:

测试您的代码后,如果我注释掉这一行,它就可以正常工作(主要是...):

->addAttributeToFilter('is_featured', 1)

My suggestion is to double-check that the product attribute id exists on your current installation, and it is set to the correct scope (Global / Correct Store?).

我的建议是仔细检查当前安装中是否存在产品属性 id,并将其设置为正确的范围(全局/正确的商店?)。

If it does exist correctly, another solution is to have the featured products selected manually, you may want to try using:

如果确实存在,另一种解决方案是手动选择特色产品,您可能需要尝试使用:

Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect(array('name', 'url', 'small_image', 'price', 'short_description'))
    ->addFieldToFilter('is_featured', 1)
    ->addFieldToFilter('status', 1)
    ->addStoreFilter($storeId)
    ->clear()->setPageSize(3)->load(); //setPageSize = How Many Products To Show

And see if that fixes it.

看看能不能解决。

回答by TonkBerlin

In my case it helped to out comment this line (Line 765)

在我的情况下,它有助于评论这一行(第 765 行)

$customer->changeResetPasswordLinkCustomerId($newResetPasswordLinkCustomerId);

in

/app/code/core/Mage/Customer/controllers/AccountController.php

/app/code/core/Mage/Customer/controllers/AccountController.php

I think it could be also important to check weather the update script updated your database correctly. F.e. upgrade-1.6.2.0.6-1.6.2.0.7.phpcreates a table called rp_customer_id

我认为检查更新脚本正确更新数据库的天气也很重要。Fe upgrade-1.6.2.0.6-1.6.2.0.7.php创建一个名为的表rp_customer_id