Hy ,, Im trying to make Magento compare products by grouping all products with the same cateogry and compare them together ,and group the other and compare them together..etc instead of comparing all them togher, I have tried this code
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;
}
then i do in products compare 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
but my code did not work , any Help?
in collection.php add this function , you don't need to write class name as i did , i wrote it ensure that you are modifying the correct file
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;
in list.php "app/design/frontend/base/default/template/catalog/product/compare/list.phtml" add this code at the top of you file
<?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 ...............