getNewsItems(); return $collection; } public function getNewsItems() { $this->_showFlag = 1; $collection = Mage::getModel('clnews/news')->getCollection(); $category = "news"; if ($category!=null) { $catCollection = Mage::getModel('clnews/category')->getCollection() ->addFieldToFilter('url_key', $category) ->addStoreFilter(Mage::app()->getStore()->getId()); $categoryId = $catCollection->getData(); if ($categoryId[0]['category_id']) { $tableName = Mage::getSingleton('core/resource')->getTableName('clnews_news_category'); $collection->getSelect()->join($tableName, 'main_table.news_id = ' . $tableName . '.news_id','category_id'); $collection->getSelect()->where($tableName . '.category_id =?', $categoryId[0]['category_id']); } } else { $collection->addStoreFilter(Mage::app()->getStore()->getId()); } $collection ->addEnableFilter(1) ->addFieldToFilter('publicate_from_time', array('or' => array( 0 => array('date' => true, 'to' => date('Y-m-d H:i:s')), 1 => array('is' => new Zend_Db_Expr('null'))), ), 'left') ->addFieldToFilter('publicate_to_time', array('or' => array( 0 => array('date' => true, 'from' => date('Y-m-d H:i:s')), 1 => array('is' => new Zend_Db_Expr('null'))), ), 'left') ->setOrder('news_time ', 'desc'); if ($this->_itemsLimit != null && $this->_itemsLimit < $collection->getSize()) { $this->_pagesCount = ceil($this->_itemsLimit / $this->_itemsOnPage); } else { $this->_pagesCount = ceil($collection->getSize() / $this->_itemsOnPage); } $collection->getSelect()->limit(4, 0); return $collection; } }