0

好的,我想在类别页面上再添加一个排序变量,即按制造商排序。在 1.5.3.1 上运行并尝试过: 1. catalog/controller/product/category.php 添加了以下内容:

$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)
            );
  1. 目录/语言/*/product/category.php 添加:

    $_['text_manufacturer_asc'] = '▲ -Proizvođaču- ▲'; $_['text_manufacturer_desc'] = '▼ -Proizvođaču- ▼';

  2. catalog/model/catalog/product.php before: '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)...

有人可以帮忙吗?

4

1 回答 1

1

您快到了,但您将不得不对其进行更多修改。

首先,您真的不想通过存储的制造商 IDproduct.manufacturer_id 而是通过制造商名称来订购。在这种情况下,我们需要catalog\model\catalog\product.php在方法中修改模型中的查询getProducts- 找到这一行:

$sql .= " LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'";

(应该是OC 1.5.5.1中的第89行)和之前添加:

$sql .= " LEFT JOIN " . DB_PREFIX . "manufacturer m ON p.manufacturer_id = m.manufacturer_id";

此外,您需要允许制造商作为排序选项:

$sort_data = array(
    'pd.name',
    'p.model',
    'p.quantity',
    'p.price',
    'rating',
    'p.sort_order',
    'p.date_added',
    'manufacturer', // <== this is 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') { // <== this is added
        $sql .= " ORDER BY m.name";              // <== this is added
    } else {
        $sql .= " ORDER BY " . $data['sort'];
    }
} else {
    $sql .= " ORDER BY p.sort_order";   
}

就是这样。

于 2013-10-24T10:34:53.090 回答