Example #1
0
 /**
  * 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->setPageSize(Mage::getStoreConfig('vc_miniblog/menu_link/recent_post'));
     }
     return $this->_postCollection;
 }
 /**
  * Join url rewrite table to eav collection
  *
  * @param Mage_Eav_Model_Entity_Collection_Abstract $collection
  * @param int $storeId
  * @return Mage_Catalog_Helper_Category_Url_Rewrite
  */
 public function joinTableToEavCollection(Mage_Eav_Model_Entity_Collection_Abstract $collection, $storeId)
 {
     if ($this->_helper()->OptimizeCategoriesLeftJoin($storeId)) {
         $collection->joinTable('urlindexer/url_rewrite', 'category_id=entity_id', array('request_path'), "{{table}}.is_system=1 AND " . "{{table}}.store_id='{$storeId}' AND " . "{{table}}.id_path LIKE 'category/%'", 'left');
         return $this;
     }
     return parent::joinTableToEavCollection($collection, $storeId);
 }
Example #3
0
 /**
  * Add Join with option value for collection select
  *
  * @param Mage_Eav_Model_Entity_Collection_Abstract $collection
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @param Zend_Db_Expr $valueExpr
  *
  * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Option
  */
 public function addOptionValueToCollection($collection, $attribute, $valueExpr)
 {
     $attributeCode = $attribute->getAttributeCode();
     $optionTable1 = $attributeCode . '_option_value_t1';
     $optionTable2 = $attributeCode . '_option_value_t2';
     $collection->getSelect()->joinLeft(array($optionTable1 => $this->getTable('eav/attribute_option_value')), "`{$optionTable1}`.`option_id`={$valueExpr}" . " AND `{$optionTable1}`.`store_id`='0'", array())->joinLeft(array($optionTable2 => $this->getTable('eav/attribute_option_value')), "`{$optionTable2}`.`option_id`={$valueExpr}" . " AND `{$optionTable1}`.`store_id`='{$collection->getStoreId()}'", array($attributeCode => "IFNULL(`{$optionTable2}`.`value`, `{$optionTable1}`.`value`)"));
     return $this;
 }
 /**
  * Retrieve loaded category collection
  *
  * @return Mage_Eav_Model_Entity_Collection_Abstract
  */
 protected function _getProductCollection()
 {
     if (is_null($this->_productCollection)) {
         $this->_productCollection = Mage::getModel('vc_shopbybrands/product')->getCollection();
         $this->_productCollection->setPageSize(Mage::getStoreConfig('vc_shopbybrands/menu_link/recent_product'));
     }
     return $this->_productCollection;
 }
 /**
  * Apply filter to collection and add not skipped attributes to select.
  *
  * @param Mage_Eav_Model_Entity_Collection_Abstract $collection
  * @return Mage_Eav_Model_Entity_Collection_Abstract
  */
 protected function _prepareEntityCollection(Mage_Eav_Model_Entity_Collection_Abstract $collection)
 {
     if (!isset($this->_parameters[Mage_ImportExport_Model_Export::FILTER_ELEMENT_GROUP]) || !is_array($this->_parameters[Mage_ImportExport_Model_Export::FILTER_ELEMENT_GROUP])) {
         $exportFilter = array();
     } else {
         $exportFilter = $this->_parameters[Mage_ImportExport_Model_Export::FILTER_ELEMENT_GROUP];
     }
     $exportAttrCodes = $this->_getExportAttrCodes();
     foreach ($this->filterAttributeCollection($this->getAttributeCollection()) as $attribute) {
         $attrCode = $attribute->getAttributeCode();
         // filter applying
         if (isset($exportFilter[$attrCode])) {
             $attrFilterType = Mage_ImportExport_Model_Export::getAttributeFilterType($attribute);
             if ($attrCode == 'sku') {
                 $collection->addAttributeToFilter($attrCode, array('in' => $exportFilter[$attrCode]));
             } elseif (Mage_ImportExport_Model_Export::FILTER_TYPE_SELECT == $attrFilterType) {
                 if (is_scalar($exportFilter[$attrCode]) && trim($exportFilter[$attrCode])) {
                     $collection->addAttributeToFilter($attrCode, array('eq' => $exportFilter[$attrCode]));
                 }
             } elseif (Mage_ImportExport_Model_Export::FILTER_TYPE_INPUT == $attrFilterType) {
                 if (is_scalar($exportFilter[$attrCode]) && trim($exportFilter[$attrCode])) {
                     $collection->addAttributeToFilter($attrCode, array('like' => "%{$exportFilter[$attrCode]}%"));
                 }
             } elseif (Mage_ImportExport_Model_Export::FILTER_TYPE_DATE == $attrFilterType) {
                 if (is_array($exportFilter[$attrCode]) && count($exportFilter[$attrCode]) == 2) {
                     $from = array_shift($exportFilter[$attrCode]);
                     $to = array_shift($exportFilter[$attrCode]);
                     if (is_scalar($from) && !empty($from)) {
                         $date = Mage::app()->getLocale()->date($from, null, null, false)->toString('MM/dd/YYYY');
                         $collection->addAttributeToFilter($attrCode, array('from' => $date, 'date' => true));
                     }
                     if (is_scalar($to) && !empty($to)) {
                         $date = Mage::app()->getLocale()->date($to, null, null, false)->toString('MM/dd/YYYY');
                         $collection->addAttributeToFilter($attrCode, array('to' => $date, 'date' => true));
                     }
                 }
             } elseif (Mage_ImportExport_Model_Export::FILTER_TYPE_NUMBER == $attrFilterType) {
                 if (is_array($exportFilter[$attrCode]) && count($exportFilter[$attrCode]) == 2) {
                     $from = array_shift($exportFilter[$attrCode]);
                     $to = array_shift($exportFilter[$attrCode]);
                     if (is_numeric($from)) {
                         $collection->addAttributeToFilter($attrCode, array('from' => $from));
                     }
                     if (is_numeric($to)) {
                         $collection->addAttributeToFilter($attrCode, array('to' => $to));
                     }
                 }
             }
         }
         if (in_array($attrCode, $exportAttrCodes)) {
             $collection->addAttributeToSelect($attrCode);
         }
     }
     return $collection;
 }
 /**
  * Add Join with option value for collection select
  *
  * @param Mage_Eav_Model_Entity_Collection_Abstract $collection
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @param Zend_Db_Expr $valueExpr
  * @return Mage_Eav_Model_Resource_Entity_Attribute_Option
  */
 public function addOptionValueToCollection($collection, $attribute, $valueExpr)
 {
     $adapter = $this->_getReadAdapter();
     $attributeCode = $attribute->getAttributeCode();
     $optionTable1 = $attributeCode . '_option_value_t1';
     $optionTable2 = $attributeCode . '_option_value_t2';
     $tableJoinCond1 = "{$optionTable1}.option_id={$valueExpr} AND {$optionTable1}.store_id=0";
     $tableJoinCond2 = $adapter->quoteInto("{$optionTable2}.option_id={$valueExpr} AND {$optionTable2}.store_id=?", $collection->getStoreId());
     $valueExpr = $adapter->getCheckSql("{$optionTable2}.value_id IS NULL", "{$optionTable1}.value", "{$optionTable2}.value");
     $collection->getSelect()->joinLeft(array($optionTable1 => $this->getTable('eav/attribute_option_value')), $tableJoinCond1, array())->joinLeft(array($optionTable2 => $this->getTable('eav/attribute_option_value')), $tableJoinCond2, array($attributeCode => $valueExpr));
     return $this;
 }
Example #7
0
 /**
  * Retrieve loaded Giveaway Product Collection
  *
  * @return Mage_Eav_Model_Entity_Collection_Abstract
  */
 protected function _getGiveawayCollection()
 {
     if (is_null($this->_productCollection)) {
         $oProduct = Mage::getModel('catalog/product');
         /* @var $oCollection Mage_Catalog_Model_Resource_Product_Collection */
         $this->_productCollection = $oProduct->getResourceCollection();
         $oSitewardsGiveawayHelper = Mage::helper('sitewards_giveaway');
         $sGiveawayAttributeCode = $oSitewardsGiveawayHelper->getGiveawayIdentifierName();
         $this->_productCollection->addAttributeToFilter($sGiveawayAttributeCode, true);
         $this->_productCollection->addAttributeToSelect('*');
     }
     return $this->_productCollection;
 }
Example #8
0
 /**
  * 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);
                 }
             }
         }
     }
 }
Example #9
0
 function getListMostViewedProducts($perPage = NULL, $currentPage = 1)
 {
     /* 
     	Always set de $perPage, by template or by config 
     	if $perPage eq 0 (zero) not limit the list
     */
     if ($perPage === NULL) {
         $perPage = (int) $this->_config['qty'];
     }
     /*
     	Show all the product list in the current store			
     */
     $storeId = Mage::app()->getStore()->getStoreId();
     $this->setStoreId($storeId);
     $this->_productCollection = Mage::getResourceModel('reports/product_collection')->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())->addMinimalPrice()->addFinalPrice()->addTaxPercents()->addViewsCount()->setStoreId($storeId)->addStoreFilter($storeId)->setPageSize($perPage);
     if ($this->_config['catsid']) {
         $this->addCategoryIdsFilter($this->_productCollection);
     }
     Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_productCollection);
     Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection);
     $this->_productCollection->setPageSize($perPage)->setCurPage($currentPage);
     if (method_exists($this->_productCollection, "setMaxSize")) {
         $this->_productCollection->setMaxSize($perPage);
     }
     if ($this->_productCollection && $this->_productCollection->getSize()) {
         if (method_exists($this->_productCollection, "setMaxSize")) {
             $this->_productCollection->setMaxSize($perPage);
         }
     }
     return $this->_productCollection;
 }
 /**
  * Unserialize additional_information in each item
  * @return Mage_Sales_Model_Mysql4_Order_Payment_Collection
  */
 protected function _afterLoad()
 {
     foreach ($this->_items as $item) {
         $this->getResource()->unserializeFields($item);
     }
     return parent::_afterLoad();
 }
Example #11
0
 /**
  * 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;
 }
Example #12
0
 /**
  * Retrieve quote items collection
  *
  * @param   bool $loaded
  * @return  Mage_Eav_Model_Entity_Collection_Abstract
  */
 public function getItemsCollection($useCache = true)
 {
     if (is_null($this->_items)) {
         $this->_items = Mage::getModel('sales/quote_item')->getCollection();
         $this->_items->setQuote($this);
     }
     return $this->_items;
 }
 /**
  * Retrieve loaded category collection
  *
  * @return Mage_Eav_Model_Entity_Collection_Abstract
  */
 protected function _getProductCollection()
 {
     if (is_null($this->_productCollection)) {
         $layer = $this->getLayer();
         /* @var $layer Mage_Catalog_Model_Layer */
         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->_productCollection = $layer->getProductCollection();
         // Start of Code to force Magento to numerically sort decimal attributes rather than alphabetically
         if ($this->getRequest()->getParam('order')) {
             $filterAttribute = $this->getRequest()->getParam('order');
         } else {
             $filterAttribute = 'website_special';
         }
         if ($this->getRequest()->getParam('dir')) {
             $filterAttributeDir = $this->getRequest()->getParam('dir');
         } else {
             $filterAttributeDir = 'asc';
         }
         $attributeType = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', $filterAttribute)->getFrontendClass();
         // If a Sort By option is selected on category page and attribute has frontend_class = validate-number or validate-digits
         // then CAST the attribute values as signed integers
         if (isset($filterAttribute) && ($attributeType == 'validate-digits' || $attributeType == 'validate-number')) {
             $this->_productCollection->getSelect()->reset(Zend_Db_Select::ORDER);
             $this->_productCollection->getSelect()->order('CAST(`' . $filterAttribute . '` AS SIGNED) ' . $filterAttributeDir . "'");
         }
         if ($this->getRequest()->getParam('q')) {
             $q = $this->getRequest()->getParam('q');
             //$this->_productCollection->getSelect()->where("name LIKE '%".$q."'%");
         }
         //echo $this->_productCollection->getSelect();
         // End of code to force Magento to numerically sort....
         $this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
         if ($origCategory) {
             $layer->setCurrentCategory($origCategory);
         }
     }
     return $this->_productCollection;
 }
 /**
  * Add an object to the collection
  *
  * @param Varien_Object $object
  * @return Mage_Eav_Model_Entity_Collection_Abstract
  */
 public function addItem(Varien_Object $object)
 {
     if (get_class($object) !== $this->_itemObjectClass) {
         throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Attempt to add an invalid object'));
     }
     try {
         return parent::addItem($object);
     } catch (Exception $ex) {
     }
 }
Example #15
0
 /**
  * Retrieve quote items collection
  *
  * @param   bool $loaded
  * @return  Mage_Eav_Model_Entity_Collection_Abstract
  */
 public function getItemsCollection($useCache = true)
 {
     if ($this->hasItemsCollection()) {
         return $this->getData('items_collection');
     }
     if (is_null($this->_items)) {
         $this->_items = Mage::getModel('buyback/quote_item')->getCollection();
         $this->_items->setQuote($this);
     }
     return $this->_items;
 }
Example #16
0
 /**
  * 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;
 }
Example #17
0
 protected $_attributeFilterBlockName;
 /**
  * Price Filter Block Name
  *
  * @var string
  */
 protected $_priceFilterBlockName;
 /**
  * Decimal Filter Block Name
  *
  * @var string
  */
 protected $_decimalFilterBlockName;
 /**
  * Internal constructor
  */
 protected function _construct()
 {
     parent::_construct();
     $this->_initBlocks();
 }
 /**
  * Initialize blocks names
  */
 protected function _initBlocks()
 {
     $this->_stateBlockName = 'catalog/layer_state';
     $this->_categoryBlockName = 'catalog/layer_filter_category';
     $this->_attributeFilterBlockName = 'catalog/layer_filter_attribute';
     $this->_priceFilterBlockName = 'catalog/layer_filter_price';
     $this->_decimalFilterBlockName = 'catalog/layer_filter_decimal';
 }
 /**
  * Retrieve loaded category collection
  *
  * @return Mage_Eav_Model_Entity_Collection_Abstract
  */
 protected function _getProductCollection()
 {
     if (is_null($this->_productCollection)) {
         $layer = $this->getLayer();
Example #18
0
 protected function getProductCollection()
 {
     $typeFilter = $this->getData('type_filter');
     $storeId = Mage::app()->getStore()->getId();
     if ($typeFilter == 'bestseller') {
         $products = Mage::getResourceModel('reports/product_collection')->addOrderedQty()->setStoreId($storeId)->addStoreFilter($storeId)->setOrder('ordered_qty', 'desc');
     } else {
         if ($typeFilter == 'halo_featured') {
             $products = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('halo_featured', 1);
         } else {
             if ($typeFilter == 'most_viewed') {
                 $products = Mage::getResourceModel('reports/product_collection')->addOrderedQty()->setStoreId($storeId)->addStoreFilter($storeId)->addViewsCount();
             } else {
                 if ($typeFilter == 'new_products') {
                     $todayStartOfDayDate = Mage::app()->getLocale()->date()->setTime('00:00:00')->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
                     $todayEndOfDayDate = Mage::app()->getLocale()->date()->setTime('23:59:59')->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
                     $products = Mage::getResourceModel('catalog/product_collection');
                     $products->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
                     $products->addStoreFilter()->addAttributeToFilter('news_from_date', array('or' => array(0 => array('date' => true, 'to' => $todayEndOfDayDate), 1 => array('is' => new Zend_Db_Expr('null')))), 'left')->addAttributeToFilter('news_to_date', array('or' => array(0 => array('date' => true, 'from' => $todayStartOfDayDate), 1 => array('is' => new Zend_Db_Expr('null')))), 'left')->addAttributeToFilter(array(array('attribute' => 'news_from_date', 'is' => new Zend_Db_Expr('not null')), array('attribute' => 'news_to_date', 'is' => new Zend_Db_Expr('not null'))))->addAttributeToSort('news_from_date', 'desc');
                 } else {
                     if ($typeFilter == 'sale_off') {
                         $todayStartOfDayDate = Mage::app()->getLocale()->date()->setTime('00:00:00')->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
                         $todayEndOfDayDate = Mage::app()->getLocale()->date()->setTime('23:59:59')->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
                         $products = Mage::getResourceModel('catalog/product_collection');
                         $products->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
                         $products->addStoreFilter()->addAttributeToFilter('special_price', array('gt' => 0))->addAttributeToFilter('special_from_date', array('or' => array(0 => array('date' => true, 'to' => $todayEndOfDayDate), 1 => array('is' => new Zend_Db_Expr('null')))), 'left')->addAttributeToFilter('special_to_date', array('or' => array(0 => array('date' => true, 'from' => $todayStartOfDayDate), 1 => array('is' => new Zend_Db_Expr('null')))), 'left')->addAttributeToFilter(array(array('attribute' => 'special_from_date', 'is' => new Zend_Db_Expr('not null')), array('attribute' => 'special_to_date', 'is' => new Zend_Db_Expr('not null'))));
                     } else {
                         $products = Mage::getModel('catalog/product')->getCollection();
                     }
                 }
             }
         }
     }
     if ($category = $this->getData('category')) {
         $products->addCategoryFilter(Mage::getModel('catalog/category')->load(str_replace('category/', '', $category)));
     }
     $this->_addProductAttributesAndPrices($products);
     Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
     Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
     /* For category page */
     if (Mage::registry('current_category')) {
         $products->addUrlRewrite(Mage::registry('current_category')->getId());
     }
     $pageSize = $this->getData('limit_count');
     if (isset($pageSize)) {
         $products->setPageSize($pageSize);
     }
     $products->setCurPage($this->getRequest()->getParam('p', 1));
     $this->setCollection($products);
     $this->setSize(count($this->_productCollection->getData()));
     return $this->_productCollection;
 }
Example #19
0
 /**
  * Retrieve loaded category collection
  *
  * @return Mage_Eav_Model_Entity_Collection_Abstract
  */
 protected function _getProductCollection()
 {
     if (is_null($this->_productCollection)) {
         $layer = $this->getLayer();
         /* @var $layer Mage_Catalog_Model_Layer */
         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->_productCollection = $layer->getProductCollection();
         $dateToday = date('m/d/y');
         $dateToday = date('m/d/y');
         $tomorrow = mktime(0, 0, 0, date('m'), date('d') + 1, date('y'));
         $dateTomorrow = date('m/d/y', $tomorrow);
         $this->_productCollection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $dateToday))->addAttributeToFilter('special_to_date', array('or' => array(0 => array('date' => true, 'from' => $dateTomorrow), 1 => array('is' => new Zend_Db_Expr('null')))), 'left');
         $this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
         if ($origCategory) {
             $layer->setCurrentCategory($origCategory);
         }
     }
     return $this->_productCollection;
 }
Example #20
0
 /**
  * Retrieve loaded category collection
  *
  * @return Mage_Eav_Model_Entity_Collection_Abstract
  */
 protected function _getProductCollection()
 {
     if (is_null($this->_productCollection)) {
         $layer = $this->getLayer();
         $origCategory = null;
         if ($this->getCategoryId()) {
             $category = Mage::getModel('catalog/category')->load($this->getCategoryId());
             if ($category->getId()) {
                 $origCategory = $layer->getCurrentCategory();
                 $layer->setCurrentCategory($category);
             }
         }
         $this->_productCollection = $layer->getProductCollection();
         $this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
         if ($sort = $this->getSortBy()) {
             $this->_productCollection->setOrder($sort);
         }
         if ($origCategory) {
             $layer->setCurrentCategory($origCategory);
         }
     }
     return $this->_productCollection;
 }
Example #21
0
 /**
  * Retrieve quote items collection
  *
  * @param   bool $loaded
  * @return  Mage_Eav_Model_Entity_Collection_Abstract
  */
 public function getItemsCollection($loaded = true)
 {
     if (is_null($this->_items)) {
         $this->_items = Mage::getResourceModel('sales/quote_item_collection')->addAttributeToSelect('*')->setQuote($this);
         if ($this->getId()) {
             foreach ($this->_items as $item) {
                 $item->setQuote($this);
             }
         } else {
             $this->_items->setQuote($this);
         }
     }
     return $this->_items;
 }
Example #22
0
 /**
  * Retrieve loaded category collection
  *
  * @return Mage_Eav_Model_Entity_Collection_Abstract
  */
 protected function _getProductCollection()
 {
     if (is_null($this->_productCollection)) {
         $layer = $this->getLayer();
         /* @var $layer Mage_Catalog_Model_Layer */
         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);
             }
         }
         $this->_productCollection = $layer->getProductCollection();
         $current_cat = Mage::getSingleton('catalog/layer')->getCurrentCategory();
         $path = $current_cat->getPath();
         $ids = explode('/', $path);
         $topParent = 0;
         if (isset($ids[2])) {
             $topParent = $ids[2];
         }
         if ($topParent == '16') {
             $userid = Mage::getSingleton('customer/session')->getId();
             $user_id = $userid ? $userid : 0;
             $this->_productCollection->addAttributeToFilter('customer_id', $user_id);
         }
         $this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
         if ($origCategory) {
             $layer->setCurrentCategory($origCategory);
         }
     }
     return $this->_productCollection;
 }
Example #23
0
 /**
  * Retrieve loaded category collection
  *
  * @return Mage_Eav_Model_Entity_Collection_Abstract
  */
 protected function _getProductCollection()
 {
     if (is_null($this->_productCollection)) {
         $layer = $this->getLayer();
         /* @var $layer Mage_Catalog_Model_Layer */
         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->_productCollection = $layer->getProductCollection();
         /* Custom code added to filter out-of-stock products*/
         // Start here - Added on 5th June by Anil
         if ($this->getRequest()->getParam('exclude_out_of_stock', 0)) {
             $oCollection = Mage::getModel('cataloginventory/stock_item')->getCollection()->addFieldToFilter('is_in_stock', 0);
             $oProducts = array();
             foreach ($oCollection as $_collection) {
                 $oProducts[] = $_collection->getProductId();
             }
             if (!empty($oProducts)) {
                 $this->_productCollection->addIdFilter($oProducts, true);
             }
         }
         // End here
         $this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
         if ($origCategory) {
             $layer->setCurrentCategory($origCategory);
         }
     }
     return $this->_productCollection;
 }
Example #24
0
 /**
  * Add Join with option value for collection select
  *
  * @param Mage_Eav_Model_Entity_Collection_Abstract $collection
  * @param Mage_Eav_Model_Entity_Attribute $attribute
  * @param Zend_Db_Expr $valueExpr
  *
  * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Option
  */
 public function addOptionValueToCollection($collection, $attribute, $valueExpr)
 {
     $adminStore = Mage_Core_Model_App::ADMIN_STORE_ID;
     $attributeCode = $attribute->getAttributeCode();
     $optionTable1 = $attributeCode . '_option_value_t1';
     $optionTable2 = $attributeCode . '_option_value_t2';
     $collection->getSelect()->joinLeft(array($optionTable1 => $this->getTable('eav/attribute_option_value')), "`{$optionTable1}`.`option_id`={$valueExpr}" . " AND `{$optionTable1}`.`store_id`='{$adminStore}'", $collection->getStoreId() != $adminStore ? array() : array($attributeCode . '_value' => "{$optionTable1}.value"));
     if ($collection->getStoreId() != $adminStore) {
         $collection->getSelect()->joinLeft(array($optionTable2 => $this->getTable('eav/attribute_option_value')), "`{$optionTable2}`.`option_id`={$valueExpr}" . " AND `{$optionTable1}`.`store_id`='{$collection->getStoreId()}'", array($attributeCode . '_value' => "IFNULL(`{$optionTable2}`.`value`, `{$optionTable1}`.`value`)"));
     }
     return $this;
 }
Example #25
0
 /**
  * Retrieve loaded category collection
  *
  * @return Mage_Eav_Model_Entity_Collection_Abstract
  */
 protected function _getVendorCollection()
 {
     if (is_null($this->_vendorCollection)) {
         $vendorIds = array();
         $model = Mage::getModel('csmarketplace/vshop')->getCollection()->addFieldToFilter('shop_disable', array('eq' => Ced_CsMarketplace_Model_Vshop::DISABLED));
         if (count($model) > 0) {
             foreach ($model as $row) {
                 $vendorIds[] = $row->getVendorId();
             }
         }
         $this->_vendorCollection = Mage::getModel('csmarketplace/vendor')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('status', array('eq' => Ced_CsMarketplace_Model_Vendor::VENDOR_APPROVED_STATUS));
         if (($countryId = $this->getRequest()->getParam('country_id')) && $this->getRequest()->getParam('country_id') != '') {
             $this->_vendorCollection->addAttributeToFilter('country_id', $countryId);
         }
         if (($postCode = $this->getRequest()->getParam('estimate_postcode')) && $this->getRequest()->getParam('estimate_postcode') != '') {
             $this->_vendorCollection->addAttributeToFilter('zip_code', $postCode);
         }
         if (($region = $this->getRequest()->getParam('region')) && $this->getRequest()->getParam('region') != '') {
             $this->_vendorCollection->addAttributeToFilter('region', $region);
         }
         if (($region_id = $this->getRequest()->getParam('region_id')) && $this->getRequest()->getParam('region_id') != '') {
             $this->_vendorCollection->addAttributeToFilter('region_id', $region_id);
         }
         $char = $this->getRequest()->getParam('char');
         if (strlen($char)) {
             $this->_vendorCollection->addAttributeToFilter('public_name', array('like' => '%' . $char . '%'));
         }
         if (count($vendorIds) > 0) {
             $this->_vendorCollection = $this->_vendorCollection->addAttributeToFilter('entity_id', array('nin' => $vendorIds));
         }
         if (!Mage::helper('csmarketplace')->isSharingEnabled()) {
             $this->_vendorCollection->addAttributeToFilter('website_id', array('eq' => Mage::app()->getStore()->getWebsiteId()));
         }
         $this->prepareSortableFields();
     }
     /*echo $this->_vendorCollection->getSelect();die;*/
     return $this->_vendorCollection;
 }
Example #26
0
 /**
  * Add Value Sort To Collection Select
  *
  * @param Mage_Eav_Model_Entity_Collection_Abstract $collection
  * @param string $dir direction
  * @return Mage_Eav_Model_Entity_Attribute_Source_Abstract
  */
 public function addValueSortToCollection($collection, $dir = 'asc')
 {
     $attributeCode = $this->getAttribute()->getAttributeCode();
     $attributeId = $this->getAttribute()->getId();
     $attributeTable = $this->getAttribute()->getBackend()->getTable();
     if ($this->getAttribute()->isScopeGlobal()) {
         $tableName = $attributeCode . '_t';
         $collection->getSelect()->joinLeft(array($tableName => $attributeTable), "e.entity_id={$tableName}.entity_id" . " AND {$tableName}.attribute_id='{$attributeId}'" . " AND {$tableName}.store_id='0'", array());
         $valueExpr = $tableName . '.value';
     } else {
         $valueTable1 = $attributeCode . '_t1';
         $valueTable2 = $attributeCode . '_t2';
         $collection->getSelect()->joinLeft(array($valueTable1 => $attributeTable), "e.entity_id={$valueTable1}.entity_id" . " AND {$valueTable1}.attribute_id='{$attributeId}'" . " AND {$valueTable1}.store_id='0'", array())->joinLeft(array($valueTable2 => $attributeTable), "e.entity_id={$valueTable2}.entity_id" . " AND {$valueTable2}.attribute_id='{$attributeId}'" . " AND {$valueTable2}.store_id='{$collection->getStoreId()}'", array());
         $valueExpr = $collection->getConnection()->getCheckSql($valueTable2 . '.value_id > 0', $valueTable2 . '.value', $valueTable1 . '.value');
     }
     $collection->getSelect()->order($valueExpr . ' ' . $dir);
     return $this;
 }
Example #27
0
 /**
  * Add Value Sort To Collection Select
  *
  * @param Mage_Eav_Model_Entity_Collection_Abstract $collection
  * @param string $dir
  *
  * @return Mage_Eav_Model_Entity_Attribute_Source_Table
  */
 public function addValueSortToCollection($collection, $dir = Varien_Db_Select::SQL_ASC)
 {
     $valueTable1 = $this->getAttribute()->getAttributeCode() . '_t1';
     $valueTable2 = $this->getAttribute()->getAttributeCode() . '_t2';
     $collection->getSelect()->joinLeft(array($valueTable1 => $this->getAttribute()->getBackend()->getTable()), "e.entity_id={$valueTable1}.entity_id" . " AND {$valueTable1}.attribute_id='{$this->getAttribute()->getId()}'" . " AND {$valueTable1}.store_id=0", array())->joinLeft(array($valueTable2 => $this->getAttribute()->getBackend()->getTable()), "e.entity_id={$valueTable2}.entity_id" . " AND {$valueTable2}.attribute_id='{$this->getAttribute()->getId()}'" . " AND {$valueTable2}.store_id='{$collection->getStoreId()}'", array());
     $valueExpr = $collection->getSelect()->getAdapter()->getCheckSql("{$valueTable2}.value_id > 0", "{$valueTable2}.value", "{$valueTable1}.value");
     Mage::getResourceModel('eav/entity_attribute_option')->addOptionValueToCollection($collection, $this->getAttribute(), $valueExpr);
     $collection->getSelect()->order("{$this->getAttribute()->getAttributeCode()} {$dir}");
     return $this;
 }
Example #28
0
 /**
  * Add image attribute and apply sort fields to product collection
  *
  * @param Mage_Eav_Model_Entity_Collection_Abstract $collection
  * @return Mage_XmlConnect_Block_Catalog_Product_List
  */
 protected function _prepareCollection($collection)
 {
     /**
      * Apply sort params
      */
     $request = $this->getRequest();
     $isOrderValueExist = false;
     foreach ($request->getParams() as $key => $value) {
         if (0 === strpos($key, parent::REQUEST_SORT_ORDER_PARAM_PREFIX)) {
             $key = str_replace(parent::REQUEST_SORT_ORDER_PARAM_PREFIX, '', $key);
             if ($value != 'desc') {
                 $value = 'asc';
             }
             if ($key == 'relevance') {
                 $collection->getSelect()->order("relevance {$value}");
             } else {
                 $collection->addAttributeToSort($key, $value);
             }
             $isOrderValueExist = true;
         }
     }
     if (!$isOrderValueExist && $collection instanceof Mage_CatalogSearch_Model_Resource_Fulltext_Collection) {
         $collection->getSelect()->order("relevance desc");
     }
     $collection->addAttributeToSelect(array('image', 'name', 'description'));
     return $this;
 }
 /**
  * Join url rewrite table to eav collection
  *
  * @param Mage_Eav_Model_Entity_Collection_Abstract $collection
  * @param int $storeId
  * @return Mage_Catalog_Helper_Category_Url_Rewrite
  */
 public function joinTableToEavCollection(Mage_Eav_Model_Entity_Collection_Abstract $collection, $storeId)
 {
     $collection->joinTable('core/url_rewrite', 'category_id=entity_id', array('request_path'), "{{table}}.is_system=1 AND " . "{{table}}.store_id='{$storeId}' AND " . "{{table}}.id_path LIKE 'category/%'", 'left');
     return $this;
 }
 /**
  * Reset left join
  *
  * @param int $limit
  * @param int $offset
  * @return Mage_Eav_Model_Entity_Collection_Abstract
  */
 protected function _getAllIdsSelect($limit = null, $offset = null)
 {
     $idsSelect = parent::_getAllIdsSelect($limit, $offset);
     $idsSelect->resetJoinLeft();
     return $idsSelect;
 }