/** * Retrieve loaded category collection * * @return Mage_Eav_Model_Entity_Collection_Abstract */ protected function _getProductCollections($page_id) { if (is_null($this->_productCollection)) { $layer = $this->getLayer(); if ($this->getShowRootCategory()) { $this->setCategoryId(Mage::app()->getStore()->getRootCategoryId()); } // if this is a product view page if (Mage::registry('product')) { // get collection of categories this product is associated with $categories = Mage::registry('product')->getCategoryCollection()->setPage(1, 1)->load(); // if the product is associated with any category if ($categories->count()) { // show products from this category $this->setCategoryId(current($categories->getIterator())); } } $origCategory = null; if ($this->getCategoryId()) { $category = Mage::getModel('catalog/category')->load($this->getCategoryId()); if ($category->getId()) { $origCategory = $layer->getCurrentCategory(); $layer->setCurrentCategory($category); $this->addModelTags($category); } } /* @var $layer Mage_Catalog_Model_Layer */ /* @var $layer Mage_Catalog_Model_Layer */ $this->_productCollection = $layer->getProductCollection(); //Mage::getSingleton('core/session', array('name' => 'frontend')); $condition = new Zend_Db_Expr("special_price < price"); $this->_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())->addMinimalPrice()->addStoreFilter()->setPageSize(20)->addAttributeToFilter('upcomingproduct', 0); //->load(); Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection); Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection); Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($this->_productCollection); $todayDate = date('m/d/y'); $tomorrow = mktime(0, 0, 0, date('m'), date('d'), date('y')); $tomorrowDate = date('m/d/y', $tomorrow); $this->_productCollection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))->addAttributeToFilter('special_to_date', array('or' => array(0 => array('date' => true, 'from' => $tomorrowDate), 1 => array('is' => new Zend_Db_Expr('null')))), 'left'); $this->_productCollection->addAttributeToFilter('special_price', array('neq' => 'null')); //$this->_productCollection->addFieldToFilter('special_price', array('lt' => 'price')); if ($this->getRequest()->getParam('cat_id') != null) { //echo "hdjkdjdksjdks"; $categoryId = $this->getRequest()->getParam('cat_id'); $category = Mage::getModel('catalog/category')->load($categoryId); $this->_productCollection->addCategoryFilter($category); } $select = $this->_productCollection->getSelect(); $currentUrl = $this->helper('core/url')->getCurrentUrl(); $str = "sale"; $str1 = "superdeals"; if (strpos($currentUrl, $str) == true) { $select->where('price_index.final_price < price_index.price'); } elseif (strpos($currentUrl, $str1) == true) { $select->where('price_index.final_price < price_index.price AND (100 - (price_index.final_price/price_index.price) * 100) > 20'); } else { $select->where('price_index.final_price < price_index.price'); } //exit; //print_r($collection); //$this->_productCollection = $layer->getProductCollections(); //print_r($this->_productCollection); } return $this->_productCollection; }