Hi all,
I currently have a search results page that compares the search string against the name and description of a Product model. A CActiveDataProvider is passed back to my results view and is utilised by a CListView.
I’ve added sorting for the name and dateAdded attributes of the Product model but I also want to add an option to sort using the Product “from price”.
The issue I’m having is the “from price” is a calculated attribute accessed via a method, getFromPrice(), in the Product model. There’s no way of using any columns in the MySQL database to generate the same from price, due to the price variables being fetched from a secondary SQL database.
Short of caching each Product “from price” against each record (something I don’t really want to do as the from price is changeable) is there any way of achieving this sort using the getFromPrice() method?
Here’s my code to return the CActiveDataProvider:
// create a new criteria object
$criteria = new CDbCriteria();
// add the comparison items to the criteria
$criteria->compare('name', $query, true, 'OR');
$criteria->compare('description', $query, true, 'OR');
$criteria->compare('orderID', 0, false, 'AND');
$criteria->compare('enabled', 1, false, 'AND');
// return the data provider
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'pagination' => array(
'pageSize' => 10,
),
'sort' => array(
'defaultOrder' => array(
'name' => CSort::SORT_ASC,
),
'attributes' => array(
'name',
'dateAdded',
),
),
)
);
Any help would be appreciated.
Thanks