好的,我想在類別頁面上添加一個排序變量,即按製造商排序。 運行在1.5.3.1並試圖這樣: 1.目錄/控制器/產品/ category.php 加入下列:Opencart按類別製造商排序頁面
$this->data['sorts'][] = array(
'text' => $this->language->get('text_manufacturer_asc'),
'value' => 'manufacturer-ASC',
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=manufacturer&order=ASC' . $url)
);
$this->data['sorts'][] = array(
'text' => $this->language->get('text_manufacturer_desc'),
'value' => 'manufacturer-DESC',
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=manufacturer&order=DESC' . $url)
);
目錄/語言/ * /產品/ category.php 補充:
$ _ ['text_manufacturer_asc'] ='▲ -Proizvođaču-▲'; $ _ ['text_manufacturer_desc'] ='▼ -Proizvođaču-▼';
目錄/模型/目錄/ product.php 之前: 'p.date_added' 我插入的線:
'製造商'
和幾行下面我與改變了塊如下:
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'] == 'manufacturer') {
$sql .= " SELECT * FROM". DB_PREFIX . "product p ORDER BY manufacturer";
} else {
$sql .= " ORDER BY " . $data['sort'];
}
} else {
$sql .= " ORDER BY p.sort_order";
}
但它不工作。 錯誤說:
PHP Notice: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT * FROMproduct p ORDER BY manufacturer ASC,...
,另外一個我發現:
PHP Notice: Error: Unknown column 'special' in 'order clause'<br />Error No: 1054<br />SELECT p.product_id, (SELECT AVG(rating) AS total FROM review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id)...
有人能幫忙嗎?
感謝您的幫助。現在沒有錯誤,但它默認排序。我正在爲這個改變做一個vqmod,所以我現在才發現我錯過了你所引用的OC 1.5.5.1的89行......在1.5.3.1中沒有這樣的行 - 看起來似乎。 – user1688303
然後你需要找到放置這條新線的地方。它必須位於'LEFT JOIN's和'WHERE'子句之間...它之間沒有這樣的空間來填充該行,然後選擇SQL並將其放入獲取產品的主要SQL部分(我相信您瞭解SQL語法和子句)。 – shadyyx
好吧,vqmod沒有在catalog/model/catalog/product.php文件中進行更改,所以我確實將其更改爲manualy。現在有一個錯誤說:PHP注意:錯誤:'訂單子句中的未知列'm.name' – user1688303