按制造商搜索产品在Opencart 2.3.0.2

时间:2019-03-25 18:29:32

标签: opencart

我想在Opencart 2.3.0.2上搜索制造商的产品。

catalog/model/catalog/product.php

之前

$sql .= " LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id)

我输入了以下代码:

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

和该行之前:

$sql .= " OR LCASE(p.model) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";

我输入了这段代码

 $sql .= " ORDER BY p.quantity<1, LCASE(" . $data['sort'] . ")";

但这显示了我:

  

未知:无法将类DB的对象转换为字符串   catalog \ model \ catalog \ product.php

我如何在桌子制造商上搜索名称,并按制造商向客户显示产品

1 个答案:

答案 0 :(得分:0)

尝试使用此代码将为您提供帮助

您上次按代码排序是错误的-删除此

 $sql .= " ORDER BY p.quantity<1, LCASE(" . $data['sort'] . ")";

在下面执行此操作

之前

$sql .= " GROUP BY p.product_id";

输入此代码

  $sql .= " AND p.quantity > 0";

您必须注释此代码以获取大于零的数量

     /* comment this code 
       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)";
            } else {
                $sql .= " ORDER BY " . $data['sort'];
            }
        } else {
            $sql .= " ORDER BY p.sort_order";
        }
    */

并添加

   if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
        if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') {
            $sql .= " ORDER BY p.quantity, 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)";
        } else {
            $sql .= " ORDER BY p.quantity, " . $data['sort'];
        }
    } else {
        $sql .= " ORDER BY p.quantity, p.sort_order";
    }

Search product by manufacturer