当我尝试使用以下代码从特定类别中获取4种库存产品时
$_helper = $this->helper('catalog/output');
$_category = Mage::getModel('catalog/category')->load($this->getCategoryId());
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('is_in_stock', 1)
->addAttributeToFilter('qty', ">1")
->addCategoryFilter($_category)
->setVisibility(array(2,3,4));
$_productCollection->getSelect()->order(new Zend_Db_Expr('RAND()'));
$_productCollection->setPage(1, 4);
我收到了以下异常
Fatal error: Call to a member function getBackend() on a non-object in /home/xxx/public_html/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 816
答案 0 :(得分:1)
尝试获取这样的产品系列:
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addCategoryFilter($_category)
->setVisibility(array(2,3,4));
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($_productCollection); //this should filter in stock products only
$_productCollection->getSelect()->order(new Zend_Db_Expr('RAND()'));
$_productCollection->setPage(1, 4);
答案 1 :(得分:0)
此错误通常是由于调用了错误的模型或将过滤器应用于该集合中不存在的属性,请仔细检查当前magento上是否存在产品属性ID转到管理员检查您的属性并将键与
匹配->addAttributeToFilter('is_in_stock', 1)
->addAttributeToFilter('qty', ">1")
确保您的 is_in_stock 标识符的库存属性与数量
相同请注意,请在您的版本中标记您的问题 情况是1.4还是1.7? magento也正式支持Linux环境