Magento Merge 2 Categories Into 1 Collection -
i have site sells car parts. have set categories make -> model -> year, here filtering done attributes. brakes, wheels, engine etc…
this filters collection i’d expect, once year want include items universal category. i.e. collection should include items particular car, plus “universal” items across cars.
i found magento: how merge 2 product collections one? seems want, can’t seem figure out should implemented.
there getcollection() methods in list.php, layer.php , category.php , i’ve tried implement code in link above no success. if include in list.php collections seem merged, attribute filtering isn’t applied on universal products.
i've tried editing getproductcollection function in category.php so:
public function getproductcollection() { $collection = mage::getresourcemodel('catalog/product_collection') ->setstoreid($this->getstoreid()) ->addcategoryfilter($this); //return $collection; $universalcollection = mage::getmodel('catalog/category')->load(18)->getproductcollection(); $merged_ids = array_merge($collection->getallids(), $universalcollection->getallids()); // can use "getloadedids()" $merged_collection = mage::getresourcemodel('catalog/product_collection') ->addfieldtofilter('entity_id', $merged_ids) ->addattributetoselect('*'); return $merged_collection; } but gives me: "fatal error: maximum function nesting level of '200' reached, aborting!"
if can give advice appreciated.
you getting fatal error because causing infinite loop occur.
this due fact code sits inside category model getproductcollection() method , calling getproductcollection() on new category model again. resulting in infinite loop
so, need move code out of there. you should not editing these core files way anyway.
its entirely how extend model: rewrite, observer etc. dont change magento core code.
i have provided working example below merges 2 category product collections, externally category model:
$storeid = mage::app()->getstore()->getid(); $categoryoneid = 10; $categorytwoid = 13; $categoryone = mage::getmodel('catalog/category')->load($categoryoneid); $categorytwo = mage::getmodel('catalog/category')->load($categorytwoid); $collectionone = mage::getmodel('catalog/product')->getcollection() ->setstoreid($storeid) ->addcategoryfilter($categoryone); $collectiontwo = mage::getmodel('catalog/product')->getcollection() ->setstoreid($storeid) ->addcategoryfilter($categorytwo); $merged_ids = array_merge($collectionone->getallids(), $collectiontwo->getallids()); $mergedcollection = mage::getmodel('catalog/product')->getcollection() ->addfieldtofilter('entity_id', $merged_ids);
Comments
Post a Comment