質問

On an anchor category page I'm trying to only show the products directly contained within the category. I don't want to show the products of child categories, it's not appropriate in this case. I really do need to filter the products in my current category, so I need layered navigation, which necessitates an anchor category.

Initially I thought to filter the products in the view.phtml template, but that only filters the products in the view and is not a sensible answer. When I do this I end up with big gaps on my page where child products are present, but simply not displayed. And the product counts (eg. "1-12 of 117 products") are "incorrect".

From what I've read, this is going to require a core rewrite. Probably of an index process. I don't really know where to start with this rewrite, and I'm sure it's going to be rather involved.

Are any of my assumptions wrong? Have you already solved this problem?

役に立ちましたか?

解決

Goto app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php

copy to app/code/local/Mage/Catalog/Model/Resource/Product/Collection.php

find function addCategoryFilter( and here you you find code

 public function addCategoryFilter(Mage_Catalog_Model_Category $category)
    {
        $this->_productLimitationFilters['category_id'] = $category->getId();
/*    start to comment here     
if ($category->getIsAnchor()) {
            unset($this->_productLimitationFilters['category_is_anchor']);
        } else {
            $this->_productLimitationFilters['category_is_anchor'] = 1;
        }*/
/* new line */

     $this->_productLimitationFilters['category_is_anchor'] = 1;

        if ($this->getStoreId() == Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID) {
            $this->_applyZeroStoreProductLimitations();
        } else {
            $this->_applyProductLimitations();
        }

        return $this;
    }

他のヒント

You don't need a single line of code if I have understood your condition correct. Magento provides the freedom to enter products in any category regardless of their hierarchy.

So consider the following scenario:

Category A->Category a

Then a product can be assigned to only category a and not to category A. This will work in harmony with the entire magento system including layered navigation and no of prouducts shown on page.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top