0

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?

John silver
  • 105
  • 1
  • 6
  • 14

4 Answers4

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

Try to reload collections. Similar problem might be here

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

UPDATE 1

So my advice is to create another method in your block which resets collection. Or even add reset to your category loading function. Well it is up to you.

Community
  • 1
  • 1
Jevgeni Smirnov
  • 3,787
  • 5
  • 33
  • 50
  • 1
    Specifically, `$this_original=$this` does not create a backup copy of `$this`, it only creates a second reference to it. – clockworkgeek Dec 13 '11 at 14:36
  • $this is not a collection. $this is a block. You shouldn't make a copy of block in your phtml. Better have another method which resets collection. – Jevgeni Smirnov Dec 14 '11 at 06:25
0

I have only one idea. Import product via Store Manager for Magento into csv and then compare them. I'm not sure that your code is quite good for this action.

Marianne
  • 23
  • 1
  • 9
0

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 ...............
John silver
  • 105
  • 1
  • 6
  • 14
0

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 ...............
John silver
  • 105
  • 1
  • 6
  • 14