/** * Add joins for eav field if needed for ordeding */ protected function _buildQueryOrder(&$query) { $order = $this->_db->getEscaped($this->getState('order')); // Ordering prefix for table column $prefix = 'value_'; // if order is requested on an eav column if (strpos($order, $prefix) === 0) { // Different table name for different joins! $attribute_alias = substr($order, strlen($prefix)); $tbl_key = $this->getTable()->getKeyName(); $eav_tbl_name = 'eav_' . $attribute_alias; $value_tbl_name = 'value_' . $attribute_alias; // we haven't already joined the tables, join them if ($this->getEavState($order, '') == '') { // Join the table based on the type of the value Tienda::load("TiendaHelperBase", 'helpers._base'); $eav_helper = TiendaHelperBase::getInstance('Eav'); $table_type = $eav_helper->getType($attribute_alias); // Join! $query->join('LEFT', '#__tienda_eavattributes AS ' . $eav_tbl_name . ' ON tbl.' . $tbl_key . ' = ' . $eav_tbl_name . '.eaventity_id'); $query->join('LEFT', '#__tienda_eavvalues' . $table_type . ' AS ' . $value_tbl_name . ' ON ' . $eav_tbl_name . '.eavattribute_id = ' . $value_tbl_name . '.eavattribute_id'); } $direction = $this->_db->getEscaped(strtoupper($this->getState('direction'))); // Order field is the eavvalue_value field $order = $value_tbl_name . '.eavvalue_value'; $query->order("{$order} {$direction}"); } else { // normal ordering, not on eav column parent::_buildQueryOrder($query); } }