/** * Retrieve loaded category collection * * @return Mage_Eav_Model_Entity_Collection_Abstract */ protected function _getProductCollection() { if (is_null($this->_prodCollection)) { $collection = parent::_getProductCollection(); /*Get customer "status" attribute options*/ $_approvedStatusId = Mage::getStoreConfig('marketplace/status/approved'); if ($_approvedStatusId) { $_customerData = Mage::getModel('customer/customer')->getCollection()->addFieldToFilter('status', $_approvedStatusId)->load(); $where = 'ce.value IS NULL'; $_sellerIds = array(); /*Get array of seller ids with stats approved*/ foreach ($_customerData as $_data) { $_sellerIds[] = $_data['entity_id']; } if ($_sellerIds) { $where .= " OR ce.value in (" . implode(',', $_sellerIds) . ")"; } $resource = Mage::getSingleton('core/resource'); $tableName = $resource->getTableName('catalog_product_entity_int'); $collection->getSelect()->joinLeft($tableName . ' As ce', 'ce.entity_id=e.entity_id AND ce.attribute_id=' . Mage::helper('marketplace')->getProductSellerAttributeId(), null); $collection->getSelect()->where($where); } $this->_prodCollection = $collection; } return $this->_prodCollection; }
public function _getProductCollection() { if ($this->getSkuList()) { $collection = Mage::getModel('catalog/product')->getCollection(); $layer = $this->getLayer(); $layer->prepareProductCollection($collection); } else { $collection = parent::_getProductCollection(); } if ($this->getLimit()) { $collection->setPageSize($this->getLimit()); } if ($this->getSortBy()) { $collection->setOrder($this->getSortBy(), $this->getSortByDirection()); } if ($this->getSkuList()) { $select = $collection->getSelect(); $separator = $this->getSeparator(); if (empty($separator)) { $separator = ','; } $skus = explode($separator, $this->getSkuList()); if (count($skus)) { $select->where('e.sku IN (?)', $skus); $escapedSkus = array(); foreach ($skus as $sku) { $escapedSkus[] = $collection->getConnection()->quote($sku); } $select->order(new Zend_Db_Expr('FIELD(e.sku, ' . join(',', $escapedSkus) . ')')); } else { $select->where('SKU IS NULL'); } } return $collection; }
/** * Retrieve loaded category collection * * @return Mage_Eav_Model_Entity_Collection_Abstract */ protected function _getProductCollection() { $collection = parent::_getProductCollection(); /* * Collections using Product Flat index require different processing. */ if (Mage::getStoreConfigFlag('catalog/frontend/flat_catalog_product')) { $collection->getSelect()->where(new Zend_Db_Expr('price_index.final_price < price_index.price')); } else { $today = date('Y-m-d', time()); $collection->addAttributeToFilter('special_price', array('is' => new Zend_Db_Expr('not null')))->addAttributeToFilter('special_from_date', array('or' => array(0 => array('date' => true, 'to' => $today), 1 => array('is' => new Zend_Db_Expr('null')))), 'left')->addAttributeToFilter('special_to_date', array('or' => array(0 => array('date' => true, 'from' => $today), 1 => array('is' => new Zend_Db_Expr('null')))), 'left'); } return $collection; }
/** * Retrieve loaded category collection * * @return Mage_Eav_Model_Entity_Collection_Abstract */ protected function _getProductCollection() { $judet = Mage::app()->getRequest()->getParam('judet'); if ($judet) { $collection = parent::_getProductCollection()->clear(); foreach ($collection as $key => $product) { if ($judet && strpos($product->getOfgZonaPersonalizata(), $judet) === false) { $collection->removeItemByKey($key); } } $this->_productCollection = $collection; return $this->_productCollection; } return parent::_getProductCollection(); }
protected function _getProductCollection() { $profileCollection = Mage::getModel('cartmart/profile')->getCollection(); $profileCollection->getSelect()->reset(Zend_Db_Select::COLUMNS)->columns('user_id'); $userIds = $profileCollection->toArray(array('user_id')); $userCollection = Mage::getModel('admin/user')->getCollection()->addFieldToFilter('is_active', 1); if ($userIds['totalRecords'] != 0) { $userCollection->addFieldToFilter('user_id', array('in' => $userIds)); } $userIds = $userCollection->getAllIds(); $collection = parent::_getProductCollection(); $collection->addAttributeToSelect('vendor')->addAttributeToFilter('vendor', array(array('in' => $userIds), array('null' => true))); if ($this->getRequest()->getRouteName() == 'cartmart' && $this->getRequest()->getControllerName() == 'vendor' && $this->getRequest()->getActionName() == 'items') { $profileId = $this->getRequest()->getParam('id'); if (isset($profileId)) { $vendorId = Mage::getModel('cartmart/profile')->load($profileId)->getUserId(); $collection->addAttributeToSelect('vendor')->addAttributeToFilter('vendor', $vendorId); } } return $collection; }
protected function _getProductCollection() { $params = $this->getRequest()->getParams(); $action = Mage::app()->getRequest()->getActionName(); // could be: index, foto, video or foto-video if (is_null($this->_productCollection)) { $collection = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('furnizor_account_status', 1)->addAttributeToFilter('furnizor_account_online_status', 1); // add region filter to collection if (isset($params['judet'])) { $collection->addAttributeToFilter('furnizor_location_province', $params['judet']); unset($params['judet'], $params['p']); } /* * aplly layer filters to collection * take a look into Picode_ConturiFurnizori_Block_Conturi_Layer */ foreach ($params as $key => $val) { $attributeCode = $this->convertAttributeLabeToCode($key); $collection->addAttributeToFilter($attributeCode, $val); } // add service type filter to collection switch ($action) { case 'foto': $collection->addAttributeToFilter('furnizor_company_services', 1); break; case 'video': $collection->addAttributeToFilter('furnizor_company_services', 2); break; case 'fotovideo': $collection->addAttributeToFilter('furnizor_company_services', 3); break; } //Zend_Debug::dump($collection->getData()); die(); //$collection->setOrder('business_images_logo', 'DESC'); $this->_productCollection = $collection; } return parent::_getProductCollection(); }
protected function _getProductCollection() { // trying to override this method if (is_null($this->_x_productCollection)) { $collection = parent::_getProductCollection(); $session = Mage::getSingleton('customer/session'); $isCorporate = FALSE; if ($session->isLoggedIn()) { $customer = $session->getCustomer(); $isCorporate = $customer->getZiscorporate(); } if ($isCorporate == 470) { $collection->addTierPriceData(); $collection->addAttributeToFilter('tier_price', 'notnull'); // $collection->getSelect()->where("price_index.tier_price IS NOT NULL"); Mage::Log("Rrap_Corporate_Block_Product_List select is " . $collection->getSelect()); } $this->_productCollection = $collection; } else { $collection = parent::_getProductCollection(); } return $collection; }
protected function getProductCollection() { $products = Mage::getModel('catalog/product')->getCollection()->distinct(true); $config1 = $this->getData('category'); if ($config1) { $arrs = $this->ProcessCategory($config1); //print_r($arrs);exit; $result = array(); $condition_cat = array(); //$cat_id_sql = '('; $fine_set = ''; foreach ($arrs as $cat_id) { //$cat_id_sql .= $cat_id->id.','; $fine_set .= $cat_id->id . ','; /*$category = new Mage_Catalog_Model_Category(); $category->load($cat_id->id); $collection = $category->getProductCollection(); foreach ($collection as $product) { $tmp = array(); $tmp['attribute'] = 'entity_id'; $tmp['eq'] = $product->getId(); $condition_cat[] = $tmp; }*/ } //$cat_id_sql = substr($cat_id_sql,0,strlen($cat_id_sql)-1).')'; $fine_set = substr($fine_set, 0, strlen($fine_set) - 1); //$products->addAttributeToFilter('category_ids',array('finset'=>$fine_set)); /*$products->getSelect() ->join( array('cat_product'=>'catalog_category_product'), 'cat_product.category_id in '.$cat_id_sql.' AND cat_product.product_id=e.entity_id', array('position'=>'cat_product.position') );*/ $alias = 'cat_index'; $categoryCondition = $products->getConnection()->quoteInto($alias . '.product_id=e.entity_id AND ' . $alias . '.store_id=? AND ', $products->getStoreId()); $categoryCondition .= $alias . '.category_id IN (' . $fine_set . ')'; $products->getSelect()->joinInner(array($alias => $products->getTable('catalog/category_product_index')), $categoryCondition, array('position' => 'position')); $products->_categoryIndexJoined = true; //$products->_joinFields['position'] = array('table'=>$alias, 'field'=>'position' ); } $attrSetName = $this->getData('attribute_set'); if ($attrSetName) { $attributeSetId = Mage::getModel('eav/entity_attribute_set')->load($attrSetName, 'attribute_set_name')->getAttributeSetId(); $products->addAttributeToFilter('attribute_set_id', $attributeSetId); } $products->addAttributeToFilter('status', 1)->addAttributeToFilter('visibility', 4); $asc = $this->getRequest()->getParam('dir'); $od = $this->getRequest()->getParam('order'); if (isset($od) && isset($asc)) { $orders[0] = $od; $orders[1] = $asc; } else { $config2 = $this->getData('order_by'); if (isset($config2)) { //echo 'bb'; $orders = explode(' ', $config2); //echo $this->getData('order_by'); } } $store_id = Mage::app()->getStore(); $field_condition = $this->getData('if'); $conditionIf = array(); if ($field_condition != '') { $field_condition = strtolower($field_condition); $field_condition = $this->standarStr($field_condition); $array_field = $this->toArrExpression($field_condition); $field_widget = '('; foreach ($array_field as $a) { $tmp = array(); $i = 0; //check and process if exists attributes like a,ab,abc foreach ($array_field as $a1) { if ($a != $a1) { if (strstr($a1->field, $a->field)) { $field_condition = str_replace($a1->field, $this->encrypt . $i, $field_condition); $tmp[] = $a1->field; $i++; } } } $field_condition = str_replace($a->field, $a->field . '_table.value', $field_condition); foreach ($tmp as $key => $t) { $field_condition = str_replace($this->encrypt . $key, $t, $field_condition); } // echo $field_condition ; $field_widget .= '"' . $a->field . '",'; } $field_widget = substr($field_widget, 0, strlen($field_widget) - 1) . ')'; $dem = 0; //Join if use catalog flat $products->getSelect()->join(array('entity_table' => 'catalog_product_entity'), 'e.entity_id=entity_table.entity_id', array()); foreach ($array_field as $a) { $field = $a->field; $eavAttribute = Mage::getResourceSingleton('catalog/product')->getAttribute($field); //->getData('frontend_input'); $backendType = $eavAttribute->getBackend()->getTable(); $frontendInput = $eavAttribute->getData('frontend_input'); if ($dem == count($array_field) - 1) { if ($frontendInput == 'select') { $products->getSelect()->join(array('cat_table' => $backendType), 'cat_table.entity_id=entity_table.entity_id AND cat_table.store_id=0 AND cat_table.attribute_id=' . $eavAttribute->getData('attribute_id') . ' AND cat_table.entity_type_id=entity_table.entity_type_id INNER JOIN eav_attribute_option_value as ' . $field . '_table ON cat_table.value=' . $field . '_table.option_id AND cat_table.store_id=' . $field . '_table.store_id and (' . $field_condition . ')', array($field => $field . '_table.value')); } else { $products->getSelect()->join(array($field . '_table' => $backendType), $field . '_table.entity_id=entity_table.entity_id AND ' . $field . '_table.store_id=0 AND ' . $field . '_table.attribute_id=' . $eavAttribute->getData('attribute_id') . ' AND ' . $field . '_table.entity_type_id=entity_table.entity_type_id and (' . $field_condition . ')', array($field => $field . '_table.value')); } } else { if ($frontendInput == 'select') { $products->getSelect()->join(array('cat_table' => $backendType), 'cat_table.entity_id=entity_table.entity_id AND cat_table.store_id=0 AND cat_table.attribute_id=' . $eavAttribute->getData('attribute_id') . ' AND cat_table.entity_type_id=entity_table.entity_type_id INNER JOIN eav_attribute_option_value as ' . $field . '_table ON cat_table.value=' . $field . '_table.option_id AND cat_table.store_id=' . $field . '_table.store_id', array($field => $field . '_table.value')); } else { $products->getSelect()->join(array($field . '_table' => $backendType), $field . '_table.entity_id=entity_table.entity_id AND ' . $field . '_table.store_id=0 AND ' . $field . '_table.attribute_id=' . $eavAttribute->getData('attribute_id') . ' AND ' . $field . '_table.entity_type_id=entity_table.entity_type_id', array($field => $field . '_table.value')); } } $dem++; } } if ($_SERVER['REMOTE_ADDR'] == '72.209.195.124' || $_SERVER['REMOTE_ADDR'] == '72.209.195.124' || $_SERVER['REMOTE_ADDR'] == '72.209.195.124') { echo $products->getSelect(); echo $this->getData('order_by'); } //ashwani bhasin 7-31-2012 to fix the page not picking up pagesize from memory. commented the above line and replaced it with below $limit = Mage::getSingleton('catalog/session')->getLimitPage(); if (!$limit) { $limit = '40'; } // echo $limit; $pageSize = $this->getRequest()->getParam('limit'); if (!$pageSize) { $pageSize = $limit; } //echo $pageSize; if (count($orders)) { $products->addAttributeToSort($orders[0], $orders[1]); } $products->addAttributeToSort('mysort', 'desc'); if (isset($pageSize)) { $products->setPageSize($pageSize); } $products->setCurPage($this->getRequest()->getParam('p', 1)); $products->addAttributeToSelect('*'); //echo $pageSize; //print_r($products->getData());exit; //echo (string)($products->getSelect());exit; // print_r(count($products->getData()));exit; //echo $pageSize;exit; /*foreach ($products as $s) print_r($s->getCategoryIds());die; */ $this->setCollection($products); //$toolbar = $this->getLayout()->createBlock('catalog/product/list/toolbar', microtime()); //$toolbar->setCollection($products); //$this->setChild('toolbar', $toolbar); //echo $toolbar->getChildHtml();exit; //print_r($this->_productCollection->getData()); //$this->_productCollection = $products; //print_r($this->getToolbarHtml());exit; $this->setSize(count($this->_productCollection->getData())); //echo $this->getSize();exit; parent::_getProductCollection(); return $this->_productCollection; }
/** * (non-PHPdoc) * @see Mage_Catalog_Block_Product_List::_getProductCollection() */ protected function _getProductCollection() { $productCollection = parent::_getProductCollection(); $productCollection->addAttributeToSelect('sm_product_vendor_id')->addFieldToFilter('sm_product_vendor_id', $this->getVendor()->getId()); return $productCollection; }
/** * Retrieve loaded category collection * * @return Mage_Eav_Model_Entity_Collection_Abstract */ protected function _getProductCollection() { if (is_null($this->_productCollection)) { $toolbar = $this->getToolbarBlock(); $orderby = $toolbar->getCurrentOrder(); $direction = $toolbar->getCurrentDirection(); $documents = array(); if (isset($this->_solrData['response']['docs'])) { $documents = $this->_solrData['response']['docs']; } $session = Mage::getSingleton('customer/session'); $isCorporate = FALSE; if ($session->isLoggedIn()) { $customer = $session->getCustomer(); $isCorporate = $customer->getZiscorporate(); } if ($isCorporate == 470) { $collection = Mage_Catalog_Block_Product_List::_getProductCollection(); $collection->getSelect()->where("price_index.tier_price IS NOT NULL"); $productIds = array(); foreach ($collection as $product) { $productIds[] = $product->getId(); } } else { $productIds = array(); if (is_array($documents) && count($documents) > 0) { foreach ($documents as $_doc) { if (isset($_doc['products_id'])) { $productIds[] = $_doc['products_id']; } } } /*$catId = Mage::getModel('catalog/layer')->getCurrentCategory()->getId(); if($catId == '222' && count($productIds) < 40){ array_push($productIds, "47078","47079","47080"); }*/ } $store = Mage::app()->getStore(); $collection = Mage::getModel('catalog/product')->getCollection(); Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection); $collection->addAttributeToFilter('entity_id', array('in' => $productIds)); if ($isCorporate != 470) { $collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds())->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInSearchIds()); } $checkInstockConfig = Mage::helper('solrsearch')->getSetting('check_instock'); if (intval($checkInstockConfig) > 0) { if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) { $collection->joinField('qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left'); } } $collection->getSelect()->order("find_in_set(e.entity_id,'" . implode(',', $productIds) . "')"); /* if (empty($orderby) || $orderby == 'position'){ $collection->getSelect()->order("find_in_set(e.entity_id,'".implode(',',$productIds)."')"); }else{ $collection->addAttributeToSort($orderby, strtoupper($direction)); }*/ $this->_productCollection = $collection; } return $this->_productCollection; }