/** * Remove hidden items from a product or category collection * * @param Mage_Eav_Model_Entity_Collection_Abstract|Mage_Core_Model_Mysql4_Collection_Abstract $collection */ public function _removeHiddenCollectionItems($collection) { // Loop through each category or product foreach ($collection as $key => $item) { $catData = Mage::getModel("catalog/category")->load($item->getEntityId()); // If it is a category if ($item->getEntityTypeId() == 3 && $item->getLevel() != 2) { if (strtolower($catData->getUrlKey()) != 'get-the-look' && strtolower($catData->getUrlKey()) != 'new-arrivals') { if ($this->getProductCountCustom($catData) <= 0) { $collection->removeItemByKey($key); } } } } }
/** * Filter collection by removing not available product types * * @param Mage_Core_Model_Mysql4_Collection_Abstract $collection * @return Mage_Core_Model_Mysql4_Collection_Abstract */ public function applySalableProductTypesFilter($collection) { $productTypes = Mage::getConfig()->getNode('adminhtml/sales/order/create/available_product_types')->asArray(); $productTypes = array_keys($productTypes); foreach ($collection->getItems() as $key => $item) { if ($item instanceof Mage_Catalog_Model_Product) { $type = $item->getTypeId(); } else { if ($item instanceof Mage_Sales_Model_Order_Item) { $type = $item->getProductType(); } else { if ($item instanceof Mage_Sales_Model_Quote_Item) { $type = $item->getProductType(); } else { $type = ''; } } } if (!in_array($type, $productTypes)) { $collection->removeItemByKey($key); } } return $collection; }