public function setOrder($attribute, $dir = 'desc') { $storeId = AO::app()->getStore()->getId(); $websiteId = AO::app()->getStore()->getWebsiteId(); if ($attribute == 'price' && $storeId != 0) { $customerGroup = AO::getSingleton('customer/session')->getCustomerGroupId(); if ($this->isEnabledFlat()) { $priceColumn = 'e.display_price_group_' . $customerGroup; $this->getSelect()->order("{$priceColumn} {$dir}"); } else { $priceAttributeId = $this->getAttribute('price')->getId(); $entityCondition = '_price_order_table.entity_id = e.entity_id'; $storeCondition = $this->getConnection()->quoteInto('_price_order_table.website_id = ?', $websiteId); $groupCondition = $this->getConnection()->quoteInto('_price_order_table.customer_group_id = ?', $customerGroup); $attributeCondition = $this->getConnection()->quoteInto('_price_order_table.attribute_id = ?', $priceAttributeId); $this->getSelect()->joinLeft(array('_price_order_table' => $this->getTable('catalogindex/price')), "{$entityCondition} AND {$storeCondition} AND {$groupCondition} AND {$attributeCondition}", array()); $this->getSelect()->order('_price_order_table.value ' . $dir); /** * Distinct we are using for remove duplicates of products which have * several rows in price index (like grouped products) */ $this->getSelect()->distinct(true); } } else { if ($this->isEnabledFlat()) { if ($sortColumn = $this->getEntity()->getAttributeSortColumn($attribute)) { $this->getSelect()->order("e.{$sortColumn} {$dir}"); } } else { parent::setOrder($attribute, $dir); } } return $this; }