我只会指导你,查询部分取决于你......
还编辑catalog/model/catalog/product.php
- 方法getProducts($data)
。检查这部分:
$sort_data = array(
'pd.name',
'p.model',
'p.quantity',
'p.price',
'rating',
'p.sort_order',
'p.date_added'
);
并添加您的新排序,例如bestsellers
,因此您最终会得到这个数组:
$sort_data = array(
'pd.name',
'p.model',
'p.quantity',
'p.price',
'rating',
'p.sort_order',
'p.date_added',
'bestsellers',
);
现在你必须编辑下一部分,if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
所以你应该最终得到:
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') {
$sql .= " ORDER BY LCASE(" . $data['sort'] . ")";
} elseif ($data['sort'] == 'p.price') {
$sql .= " ORDER BY (CASE WHEN special IS NOT NULL THEN special WHEN discount IS NOT NULL THEN discount ELSE p.price END)";
} elseif ($data['sort'] == 'bestsellers') { // <-- YOUR NEW SORTING
$sql .= " ORDER BY <ADD YOUR SORTING QUERY HERE>";
} else {
$sql .= " ORDER BY " . $data['sort'];
}
} else {
$sql .= " ORDER BY p.sort_order";
}
添加正确的查询而不是<ADD YOUR SORTING QUERY HERE>
You 后应该完成。