public function setOrder($attribute, $dir = 'desc') { if ($attribute == 'relevance') { $this->getSelect()->order("on_top DESC")->order("relevance {$dir}"); } else { parent::setOrder('on_top', 'DESC'); parent::setOrder($attribute, $dir); } return $this; }
public function setOrder($attribute, $dir = 'desc') { if ($attribute == 'directresult_position') { $directsearchResultData = Mage::registry('direct_search_result_products'); usort($directsearchResultData, array($this, '_sortByOrder')); $productIds = array(); foreach ($directsearchResultData as $item) { $productIds[] = $item['entity_id']; } if (count($productIds)) { $this->getSelect()->order(new Zend_Db_Expr("FIELD(e.entity_id," . implode(',', $productIds) . ")")); } } else { parent::setOrder($attribute, $dir); } return $this; }
public function getSelectCountSql() { $select = parent::getSelectCountSql(); $select->reset(Zend_Db_Select::GROUP); return $select; }
/** * Load entities records into items * * Removed page limiting SQL from this method to prevent issues with paging and Klevu. * * @throws Exception * @return Mage_Eav_Model_Entity_Collection_Abstract */ public function _loadEntities($printQuery = false, $logQuery = false) { if (!$this->isExtensionConfigured()) { return parent::_loadEntities($printQuery, $logQuery); } // API results are already filtered, so include only the products // returned by the API in the collection $this->getSelect()->reset(Zend_Db_Select::WHERE); $this->addFieldToFilter('entity_id', array('in' => $this->_getProductIds())); // API results are ordered using the selected sort order, so enforce // the collection order to match the API results $this->getSelect()->reset(Zend_Db_Select::ORDER); $this->getSelect()->reset(Zend_Db_Select::LIMIT_OFFSET); if (count($this->_getProductIds())) { // Use "FIELD (column, 1[,2,3,4]) ASC" for ordering, where "1[,2,3,4]" is the list of IDs in the order required $this->getSelect()->order(sprintf('FIELD(`e`.`entity_id`, %s) ASC', implode(',', $this->_getProductIds()))); } $this->printLogQuery($printQuery, $logQuery); try { /** * Prepare select query * @var string $query */ if (is_callable(array($this, "_prepareSelect"))) { $query = $this->_prepareSelect($this->getSelect()); } else { $query = $this->getSelect(); } $rows = $this->_fetchAll($query); } catch (Exception $e) { Mage::printException($e, $query); $this->printLogQuery(true, true, $query); throw $e; } foreach ($rows as $v) { $object = $this->getNewEmptyItem()->setData($v); $this->addItem($object); if (isset($this->_itemsById[$object->getId()])) { $this->_itemsById[$object->getId()][] = $object; } else { $this->_itemsById[$object->getId()] = array($object); } } return $this; }
/** * Retrieve collection last page number * * @return int */ public function getLastPageNumberParent() { return parent::getLastPageNumber(); }
public function addAttributeToSort($attribute, $dir = 'asc') { parent::addAttributeToSort($attribute, $dir); if ($attribute == 'position') { $orders = $this->getSelect()->getPart('order'); $this->getSelect()->reset('order'); foreach ($orders as $order) { $this->getSelect()->order(str_replace('cat_index_position', 'cat_index.position', $order[0]), $order[1]); } } return $this; }