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

问题描述 投票:8回答:2

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

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

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

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

featured_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; ?>

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

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

(这个主题是继承的,所以我不是100%精通它是如何工作的!我只是简单地复制它)

php magento magento-1.7
2个回答
10
投票

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

在测试你的代码之后,如果我注释掉这一行,它的工作没有问题(主要是...):

->addAttributeToFilter('is_featured', 1)

我的建议是仔细检查当前安装中是否存在product属性id,并将其设置为正确的范围(Global / Correct Store?)。

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

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

并看看是否修复它。


0
投票

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

$customer->changeResetPasswordLinkCustomerId($newResetPasswordLinkCustomerId);

/app/code/core/mage/customer/controllers/account controller.PHP

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

© www.soinside.com 2019 - 2024. All rights reserved.