按属性集ID过滤类别产品

时间:2018-12-08 12:17:12

标签: php magento zend-framework magento-1.9

我创建了一个自定义模块,该模块重写了Mage_Catalog_Block_Product_List类,现在我想按attribute_set_id筛选Category产品集合。下面是我的代码:

 protected function _getProductCollection()
        {
            if (is_null($this->_productCollection)) {
                $layer = $this->getLayer();
                /* @var $layer Mage_Catalog_Model_Layer */
                if ($this->getShowRootCategory()) {
                    $this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());
                }

                // if this is a product view page
                if (Mage::registry('product')) {
                    // get collection of categories this product is associated with
                    $categories = Mage::registry('product')->getCategoryCollection()
                        ->setPage(1, 1)
                        ->load();
                    // if the product is associated with any category
                    if ($categories->count()) {
                        // show products from this category
                        $this->setCategoryId(current($categories->getIterator()));
                    }
                }

                $origCategory = null;
                if ($this->getCategoryId()) {
                    $category = Mage::getModel('catalog/category')->load($this->getCategoryId());
                    if ($category->getId()) {
                        $origCategory = $layer->getCurrentCategory();
                        $layer->setCurrentCategory($category);
                        $this->addModelTags($category);
                    }
                }
                $this->_productCollection = $layer->getProductCollection();

                /** Filter I used to filter collection by attribute_set_id**/               
                $this->_productCollection->addAttributeToFilter('attribute_set_id', array('eq' => 4));
                $this->prepareSortableFieldsByCategory($layer->getCurrentCategory());

                if ($origCategory) {
                    $layer->setCurrentCategory($origCategory);
                }
            }

            return $this->_productCollection;
        }

但是在那之后我出现了以下错误:

  

“ SQLSTATE [42S22]:找不到列:1054未知列   “ where子句”中的“ e.attribute_set_id”,

0 个答案:

没有答案