2011-12-13 139 views
0

Hy ,,我试图让Magento通过将所有产品用相同的类别进行分组并比较它们并将它们组合在一起进行比较,比较所有他们togher,我已经试过这个代码加入产品对比magento使用产品属性(类别)

 collection.php 

     class Mage_Catalog_Model_Resource_Product_Collection extends Mage_Catalog_Model_Resource_Collection_Abstract 

     public function addCategoryFilterH($request) 
     { 

     $this->_productLimitationFilters['category_id'] =$request; 
     unset($this->_productLimitationFilters['category_is_anchor']); 


     $this->_applyZeroStoreProductLimitations(); 

     $this->_applyProductLimitations(); 

      return $this; 


} 

那我就在产品的比较:

  list.phtml 
      $this_original=$this; 
      $cat15=$this->getItems()->addCategoryFilterH(15); 
      ...for loop throw this products .... 
      $this=$this_original; 
      $cat8=$this->getItems()->addCategoryFilterH(8); 
      ...for loop throw this products .... 
      ...next category id ... 
      ...for loop ... etc 

,但我的代码没有工作,任何帮助?

+0

你有一些页面,有多个类别或什么?或者您显示具有多个子类别的类别? –

+0

我只是想覆盖产品比较的默认功能,因此它可以按其类别显示比较产品 –

+1

这意味着什么现在的工作。请更具体地说明?你检查过日志吗? –

回答

0

在collection.php添加此功能,你不需要写类名和我一样,我写它确保您正在修改正确的文件

class Mage_Catalog_Model_Resource_Product_Collection extends Mage_Catalog_Model_Resource_Collection_Abstract 

    public function addCategoryFilterH($request) 
    { 

    $this->_productLimitationFilters['category_id'] =$request; 
    unset($this->_productLimitationFilters['category_is_anchor']); 


    $this->_applyZeroStoreProductLimitations(); 

    $this->_applyProductLimitations(); 

     return $this; 

在list.php的“应用程序/设计/前端/基/默认/模板/目录/产品/比较/ list.phtml” 在你的顶部添加此代码文件

<?php 
$thiscount=clone $this; 
$this1=clone $this; 
$comparecats=array(); 
?> 
<?php foreach($thiscount->getItems() as $_item): ?> 
     <?php 


$att=$_item->getCategoryIds(); 
array_push($comparecats,$att[0]); 

?> 
    <?php endforeach; 

echo "<br>"; 

?> 

<?php 

$comparecats = array_unique($comparecats); 

$this2= clone $this; 

?> 

<?php foreach ($comparecats as $cateid): 
unset($this); 
$this2=clone $this1; 
$this2->getItems()->addCategoryFilterByCategoryId($cateid); 
echo "<br>"; 
?> 
.........for loop your products using this ............... 
0

我只有一个想法。通过Store Manager for Magento导入产品到csv中,然后进行比较。我不确定你的代码对于这个动作来说是相当不错的。

+0

产品比较适用于使用我的网站的用户,,,不适用于系统管理员 –

1
yes ,, it give me the same output .. filter only work for the first time .. 

尝试重新加载集合。类似的问题可能是here

$collection->clear(); 
$collection->....//here you add some logic for filtering; 
$collection->load();//here collection with new filters will be loaded. 

更新1

所以我的建议是建立在你的块的其他的方法,该方法重置集合。甚至可以将重置添加到您的类别加载功能。那么这取决于你。

+1

具体而言,'$ this_original = $ this'不会创建'$ this'的备份副本,它只会为其创建第二个引用。 – clockworkgeek

+0

哦,是啊!伟大的加法clockworkgeek! –

+0

所以我怎么可以做一个副本? –

0

在collection.php添加此功能,您不需要像我一样写类名,我写它确保你正在修改正确的文件

class Mage_Catalog_Model_Resource_Product_Collection extends Mage_Catalog_Model_Resource_Collection_Abstract 

    public function addCategoryFilterH($request) 
    { 

    $this->_productLimitationFilters['category_id'] =$request; 
    unset($this->_productLimitationFilters['category_is_anchor']); 


    $this->_applyZeroStoreProductLimitations(); 

    $this->_applyProductLimitations(); 

     return $this; 
在list.php的

“应用程序/设计/前端/基/默认/模板/目录/产品/比较/ list.phtml” 在你的顶部添加此代码文件

<?php 
$thiscount=clone $this; 
$this1=clone $this; 
$comparecats=array(); 
?> 
<?php foreach($thiscount->getItems() as $_item): ?> 
     <?php 


$att=$_item->getCategoryIds(); 
array_push($comparecats,$att[0]); 

?> 
    <?php endforeach; 

echo "<br>"; 

?> 

<?php 

$comparecats = array_unique($comparecats); 

$this2= clone $this; 

?> 

<?php foreach ($comparecats as $cateid): 
unset($this); 
$this2=clone $this1; 
$this2->getItems()->addCategoryFilterByCategoryId($cateid); 
echo "<br>"; 
?> 
.........for loop your products using this ...............