通过后端排序特色图像

时间:2012-04-02 23:40:28

标签: magento

以下是在主页上获取精选产品的功能。它获得了特色产品,但我想通过属性“featured_placement”对其进行排序。但它不适合我。

我附上了精选页面代码及其调用的代码。

  $_productCollection=$this->getLoadedProductCollection();
    $_productCollection->addAttributeToSort('featured_placement', 'asc');



    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->_productCollection = $layer->getProductCollection();

            $this->prepareSortableFieldsByCategory($layer->getCurrentCategory());

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

        return $this->_productCollection;
    }



  public function getLoadedProductCollection()
    {
        return $this->_getProductCollection();
    }

由于 抗体

0 个答案:

没有答案