使用产品属性(类别)添加产品与magento相比

时间:2011-12-13 00:56:02

标签: magento-1.5 magento

Hy,我试图让Magento比较产品,将所有产品与相同的产品进行分组并将它们进行比较,并将另一组分组并将它们进行比较..等等而不是将它们全部比较,我试过这段代码< / p>

      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 

但是我的代码没有用,有什么帮助?

4 个答案:

答案 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 :(得分:0)

我只有一个想法。通过Store Manager for Magento将产品导入csv,然后进行比较。我不确定你的代码是否适用于此操作。

答案 2 :(得分: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&#34; app / design / frontend / base / default / template / catalog / product / compare / list.phtml&#34; 在您的文件顶部添加此代码

<?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 ...............

答案 3 :(得分: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中的

“app / design / frontend / base / default / template / catalog / product / compare / 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 ...............