/** * Retrieve loaded category collection * * @return Mage_Eav_Model_Entity_Collection_Abstract */ public function getLoadedProductCollectionpro($id) { // benchmarking $memory = memory_get_usage(); $time = microtime(); 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(); /** @var $collection Mage_Catalog_Model_Resource_Product_Collection */ $category = Mage::getModel('catalog/category')->load($this->_theCat); $this->_productCollection = Mage::getResourceModel('catalog/product_collection'); // join sales order items column and count sold products $expression = new Zend_Db_Expr("SUM(oi.qty_ordered)"); $condition = new Zend_Db_Expr("e.entity_id = oi.product_id AND oi.parent_item_id IS NULL"); $this->_productCollection->addAttributeToSelect('*')->getSelect()->join(array('oi' => $this->_productCollection->getTable('sales/order_item')), $condition, array('sales_count' => $expression))->group('e.entity_id'); //->order('sales_count' . ' ' . 'desc'); $this->_productCollection->addFieldToFilter('status', '1'); //join brand if ($this->getRequest()->getParam('brands_ids') != null and $this->getRequest()->getParam('brands_ids') != 0) { $brand_id = $this->getRequest()->getParam('brands_ids'); $condition = new Zend_Db_Expr("br.option_id = {$brand_id} AND br.product_ids = e.entity_id"); $this->_productCollection->getSelect()->join(array('br' => $this->_productCollection->getTable('shopbybrand/brand')), $condition, array('brand_id' => 'br.option_id')); } // join category $condition = new Zend_Db_Expr("e.entity_id = ccp.product_id"); $condition2 = new Zend_Db_Expr("c.entity_id = ccp.category_id"); $this->_productCollection->getSelect()->join(array('ccp' => $this->_productCollection->getTable('catalog/category_product')), $condition, array())->join(array('c' => $this->_productCollection->getTable('catalog/category')), $condition2, array('cat_id' => 'c.entity_id')); $condition = new Zend_Db_Expr("c.entity_id = cv.entity_id AND ea.attribute_id = cv.attribute_id"); // cutting corners here by hardcoding 3 as Category Entiry_type_id $condition2 = new Zend_Db_Expr("ea.entity_type_id = 3 AND ea.attribute_code = 'name'"); $this->_productCollection->getSelect()->join(array('ea' => $this->_productCollection->getTable('eav/attribute')), $condition2, array())->join(array('cv' => $this->_productCollection->getTable('catalog/category') . '_varchar'), $condition, array('cat_name' => 'cv.value')); $id = $this->getRequest()->getParam('id'); $this->_productCollection->getSelect()->where('c.entity_id = ?', $id)->limit(20); } return $this->_productCollection; }
/** * Retrieve loaded category collection * * @return Mage_Eav_Model_Entity_Collection_Abstract */ protected function _getPostCollection() { if (is_null($this->_postCollection)) { $this->_postCollection = Mage::getModel('vc_miniblog/post')->getCollection(); $this->_postCollection->getSelect()->columns(array('num_comment' => '(SELECT COUNT(*) FROM ' . Mage::getSingleton('core/resource')->getTableName('vc_miniblog/comment') . ' WHERE post_id = main_table.post_id)')); $tag = $this->getRequest()->getParam('tag'); $cat = $this->getRequest()->getParam('cat'); if (strlen($tag) > 0) { $this->_postCollection->addFieldToFilter('tags', array('like' => '%' . $tag . '%')); } if (strlen($cat) > 0) { $select = new Zend_Db_Select(Mage::getSingleton('core/resource')->getConnection('read')); $select->from(array('pc' => Mage::getSingleton('core/resource')->getTableName('vc_miniblog/post_category')), array('post_id'))->joinInner(array('c' => Mage::getSingleton('core/resource')->getTableName('vc_miniblog/category')), 'pc.category_id = c.category_id', array())->where('c.identifier = ?', $cat); $this->_postCollection->addFieldToFilter('post_id', array('in' => new Zend_Db_Expr($select))); } $select2 = new Zend_Db_Select(Mage::getSingleton('core/resource')->getConnection('read')); $select2->from(array('ps' => Mage::getSingleton('core/resource')->getTableName('vc_miniblog/post_store')), array('post_id'))->where('ps.store_id = ?', Mage::app()->getStore()->getId())->orWhere('ps.store_id = ?', 0); $this->_postCollection->addFieldToFilter('post_id', array('in' => new Zend_Db_Expr($select2))); } return $this->_postCollection; }
public function addStatusFilter(Mage_Eav_Model_Entity_Collection_Abstract $collection, Mage_Adminhtml_Block_Widget_Grid_Column $column) { // echo $column->getFilter()->getValue();die; $collection->addFieldToFilter('main_table.status', array('eq' => $column->getFilter()->getValue())); // echo $collection->getSelect();die; }