2013-02-01 43 views
1

我只需要在类别页面中仅显示简单的产品,但我无法将“不可见”设置为可配置,因为我需要可配置的活动产品页面。如何从类别列表中仅删除可配置产品

我发现这个代码从列表中移除配置属性:

$_productCollection=$this->getLoadedProductCollection(); 
    $_productCollection = clone $this->getLoadedProductCollection(); 
    $_productCollection->clear() 
        ->addAttributeToFilter('type_id', 'simple') 
        ->load(); 

    $_helper = $this->helper('catalog/output'); 

它的工作原理,但是,在分层导航的配置产品仍在计算。它像“颜色:红色(2)”,但我只有1个红色(简单)。 如何完全删除可配置产品?

+1

为什么这些产品在这个类别中,如果你不想让他们在那里开始? – clockworkgeek

+0

因为当用户在产品页面(可配置)时,我需要完整的面包屑(主页>分类>子菜单>产品) 使用颜色色板模块。我想在类别页面中显示所有简单的产品,并且当用户点击某个产品时,他会转到该简单产品的可配置产品,使用完整面包屑 – Paulo

回答

2

分层导航使用单独加载的集合对象。

一种可能的方式,以确保未来的导航过滤器正确的计数是覆盖模型Mage_Catalog_Model_Layer和你的过滤器添加到其功能Mage_Catalog_Model_Layer::prepareProductCollection

public function prepareProductCollection($collection) 
    { 
     $collection 
      ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes()) 
      ->addMinimalPrice() 
      ->addFinalPrice() 
      ->addTaxPercents() 
      ->addUrlRewrite($this->getCurrentCategory()->getId()) 
      ->addAttributeToFilter('type_id', 'simple'); 

     Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection); 
     Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection); 

     return $this; 
    } 

要做到这一点你当地代码库创建一个模块。在​​3210文件中添加以下节点到节点global

<models> 
     <catalog> 
      <rewrite> 
       <layer>YourPackage_YourModule_Model_Rewrite_Layer</layer> 
      </rewrite> 
     </catalog> 
</models> 

在你的模块添加目录“重写”文件夹下的“样板”,并在其上创建文件Layer.php。在创建的文件Model/Rewrite/Layer.php添加一个类,定义如下:

class YourPackage_YourModule_Model_Rewrite_Layer extends Mage_Catalog_Model_Layer { 
} 

添加功能上面这个类,清除缓存。

+0

谢谢!但你能更具体地说我该怎么做?女巫的核心文件,我需要复制到'本地'? – Paulo

+0

不要将任何核心文件复制到本地,使用模型重写作为Magento中的首选。看到我的回答更新 –

+0

好吧,明白了。我创建了模块,Magento正在加载重写。它解决了部分问题,因为在此之前,我使用的无限ajax加载也试图加载可配置的,现在它不是。但是,分层导航仍在计算可配置(即使用magento 1.7.2) – Paulo

相关问题