Opencart 2.2.0 启用按制造商搜索

2024-05-04

我正在使用 OC 2.2.0,并一直在努力解决以下问题:

示例:我在标题搜索中输入西门子,然后单击“显示所有结果”,我的搜索页面将显示所有结果。问题是 - 结果列表仅包含名称中包含西门子的产品。我需要的是展示all 搜索结果列表中属于该制造商的产品,在我们的示例中是西门子制造商。在我的search.php控制器文件,结果在这一行中定义:

$results = $this->model_catalog_product->getProducts($filter_data);

这告诉我getProducts($filter_data)model-catalog-product 中的product.php 文件的函数是我需要定义结果的地方。我尝试调整此函数中的查询,以便它也将制造商包含在搜索结果中,但没有成功。到目前为止,我的getProducts($filter_data)函数看起来像这样:

public function getProducts($data = array()) {
        $sql = "SELECT p.product_id, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special";

        if (!empty($data['filter_category_id'])) {
            if (!empty($data['filter_sub_category'])) {
                if(!empty($data['filter_sub_subcategory'])) {
                    $sql .= " FROM " . DB_PREFIX . "product_to_category p2c";
                } else {
                    $sql .= " FROM " . DB_PREFIX . "product_to_category p2c";
                }
                //$sql .= " FROM " . DB_PREFIX . "category_path cp LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (cp.category_id = p2c.category_id)";
            } else {
                $sql .= " FROM " . DB_PREFIX . "product_to_category p2c LEFT JOIN " . DB_PREFIX . "category cc ON (p2c.category_id = cc.category_id)";
            }

            if (!empty($data['filter_filter'])) {
                $sql .= " LEFT JOIN " . DB_PREFIX . "product_filter pf ON (p2c.product_id = pf.product_id) LEFT JOIN " . DB_PREFIX . "product p ON (pf.product_id = p.product_id)";
            } else {
                $sql .= " LEFT JOIN " . DB_PREFIX . "product p ON (p2c.product_id = p.product_id)";
            }
        } else {
            $sql .= " FROM " . DB_PREFIX . "product p";
        }

        $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') . "'";

        if (!empty($data['filter_category_id'])) {

            if (!empty($data['filter_sub_category'])) {
                if(!empty($data['filter_sub_subcategory'])) {
                    $sql .= " AND p2c.category_id = '" . (int)$data['filter_sub_subcategory'] . "'";
                } else {
                    $sql .= " AND p2c.category_id = '" . (int)$data['filter_sub_category'] . "'";
                }
                //$sql .= " AND cp.path_id = '" . (int)$data['filter_category_id'] . "'";
            } else {
                $sql .= " AND cc.parent_id = '" . (int)$data['filter_category_id'] . "'";
            }

            if (!empty($data['filter_filter'])) {
                $implode = array();

                $filters = explode(',', $data['filter_filter']);

                foreach ($filters as $filter_id) {
                    $implode[] = (int)$filter_id;
                }

                $sql .= " AND pf.filter_id IN (" . implode(',', $implode) . ")";
            }
        }

        if (!empty($data['filter_subcategory_id'])) {
            if (!empty($data['filter_sub_category'])) {
                $sql .= " AND p2c.category_id = '" . (int)$data['filter_sub_category'] . "'";
                //$sql .= " AND cp.path_id = '" . (int)$data['filter_category_id'] . "'";
            } else {
                $sql .= " AND p2c.category_id = '" . (int)$data['filter_category_id'] . "'";
            }

            if (!empty($data['filter_filter'])) {
                $implode = array();

                $filters = explode(',', $data['filter_filter']);

                foreach ($filters as $filter_id) {
                    $implode[] = (int)$filter_id;
                }

                $sql .= " AND pf.filter_id IN (" . implode(',', $implode) . ")";
            }
        }

        if (!empty($data['filter_sub_subcategory'])) {
            if (!empty($data['filter_sub_subcategory'])) {
                $sql .= " AND p2c.category_id = '" . (int)$data['filter_sub_subcategory'] . "'";
                //$sql .= " AND cp.path_id = '" . (int)$data['filter_category_id'] . "'";
            } else {
                $sql .= " AND p2c.category_id = '" . (int)$data['filter_category_id'] . "'";
            }

            if (!empty($data['filter_filter'])) {
                $implode = array();

                $filters = explode(',', $data['filter_filter']);

                foreach ($filters as $filter_id) {
                    $implode[] = (int)$filter_id;
                }

                $sql .= " AND pf.filter_id IN (" . implode(',', $implode) . ")";
            }
        }

        if (!empty($data['filter_name']) || !empty($data['filter_tag'])) {
            $sql .= " AND (";

            if (!empty($data['filter_name'])) {
                $implode = array();

                $words = explode(' ', trim(preg_replace('/\s+/', ' ', $data['filter_name'])));

                foreach ($words as $word) {
                    $implode[] = "pd.name LIKE '%" . $this->db->escape($word) . "%'";
                }

                if ($implode) {
                    $sql .= " " . implode(" AND ", $implode) . "";
                }

                if (!empty($data['filter_description'])) {
                    $sql .= " OR pd.description LIKE '%" . $this->db->escape($data['filter_name']) . "%'";
                }
            }

            if (!empty($data['filter_name']) && !empty($data['filter_tag'])) {
                $sql .= " OR ";
            }

            if (!empty($data['filter_tag'])) {
                $sql .= "pd.tag LIKE '%" . $this->db->escape($data['filter_tag']) . "%'";
            }

            if (!empty($data['filter_name'])) {
                $sql .= " OR LCASE(p.model) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";
                $sql .= " OR LCASE(p.sku) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";
                $sql .= " OR LCASE(p.upc) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";
                $sql .= " OR LCASE(p.ean) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";
                $sql .= " OR LCASE(p.wholesale) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";
                $sql .= " OR LCASE(p.isbn) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";
                $sql .= " OR LCASE(p.mpn) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";
            }

            $sql .= ")";
        }

        if (!empty($data['filter_manufacturer_id'])) {
            $sql .= " AND p.manufacturer_id = '".(int)$data['filter_manufacturer_id']."'";
        }


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

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

        if (isset($data['order']) && ($data['order'] == 'DESC')) {
            $sql .= " DESC, LCASE(pd.name) DESC";
        } else {
            $sql .= " ASC, LCASE(pd.name) ASC";
        }

        if (isset($data['start']) || isset($data['limit'])) {
            if ($data['start'] < 0) {
                $data['start'] = 0;
            }

            if ($data['limit'] < 1) {
                $data['limit'] = 20;
            }

            $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
        }

        $product_data = array();

        $query = $this->db->query($sql);

        foreach ($query->rows as $result) {
            $product_data[$result['product_id']] = $this->getProduct($result['product_id']);
        }

        return $product_data;
    }

任何人都可以帮助调整查询以便它可以显示all产品属于搜索到的制造商吗?

先感谢您。


所以,最后我意识到缺少的查询是什么。行前

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

我不得不把$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 .= " OR LCASE(m.name) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";

很明显我错过了制造商数据。通过这种方式,我从制造商表中提取数据并正确处理它。我希望这对某人有帮助,干杯!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Opencart 2.2.0 启用按制造商搜索 的相关文章

  • 提交简单 PHP 表单时出现禁止错误

    我有一个不复杂的问题 这似乎比应有的更复杂 我有一个简单的表单 用于向网站添加内容 有些字段需要输入html 然而 当您在表单的不同部分输入某些 html 元素时 它会认为它讨厌您并抛出禁止的 403 错误 这是下面的表格
  • 如何接收发送到 twilio 号码的短信

    我在 twilio 创建了一个免费帐户 用于通过我的网站发送短信 注册后 我得到了一个 twilio 号码 例如 XXX XXX XXXX 我可以向手机号码发送消息 但我不知道如何使用这个 twilio 号码接收短信 请帮我解决这个问题 T
  • Zend 框架会话丢失

    我有一个注册表单 当用户注册时 它会将他重定向到他的页面 在 Firefox 和 Chrome 中一切正常 但在 Internet Explorer 中则正常 看起来保存用户信息后 会话就关闭了 并且不会将用户重定向到他的页面 我该如何解决
  • php/symfony/doctrine 内存泄漏?

    我在使用 symfony 1 4 和原则 1 2 将对象批量插入数据库时 遇到问题 我的模型有一种称为 Sector 的对象 每个对象都有多个 Cupo 类型的对象 通常范围从 50 到 200000 这些物体非常小 只是一个短标识符字符串
  • 带摘要的 php curl 返回两个响应

    我发现了一个 奇怪 的 php CURL 行为 这让我抓狂 基本上我正在做的是使用curl 进行摘要身份验证的调用 这是我的代码的摘录 curl setopt this gt c CURLOPT HTTPAUTH CURLAUTH DIGE
  • PHP 多个 Ajax 请求:第一个请求阻止第二个请求

    我在一页上有 2 个 ajax 请求 我运行了第一个请求并单独启动了第二个请求 但第二个在第一个运行后停止工作 第一次结束后继续 第一个请求需要很长时间 大约 30 60 秒 此时我需要第二个请求来显示日志第一个请求发生的情况 我尝试使用
  • 如何在 MacOS 上卸载 Mysql Shell

    我错误地安装了 MySql Shellhttps dev mysql com doc mysql shell 8 0 en https dev mysql com doc mysql shell 8 0 en 在我的 MacBook Pro
  • ORDER BY 之后的 GROUP BY

    我需要去做GROUP BY after ORDER BY 我不明白为什么 MySQL 不支持这一点 这是我的代码 SELECT pages id contents id language ORDER BY FIND IN SET langu
  • 使用活动目录对 Intranet 站点上的用户进行身份验证

    我建立了一个 内联网 站点 它有自己的登录系统 用户注册为新用户 并使用其上的用户名 密码登录该站点 但是 现在我想扩展它 让 Intranet 站点使用现有的 ActiveDirectory 进行身份验证 这就是我正在寻找的 前进 当用户
  • Twitch API - 无法使用 PHP 获取身份验证令牌

    stackoverflow 的成员们大家好 我不是一个喜欢寻求帮助的人 但在这种情况下 我认为这是解决我的问题的唯一方法 谷歌并没有给我太大帮助 所以 我的问题 我想使用 Twitch API 获取一些数据 听起来很容易 我希望是这样 下面
  • 1:1 关系中的双向外键约束

    我正在使用 MySQL 数据库 在我的关系数据模型中 我有两个相互 1 1 关联的实体 在我的架构中 通过将 FK 字段放入两个表之一中来建立 1 1 关系 该字段与另一个表的 PK 相关 两个表都有 PK 并且都是自动递增的 BIGINT
  • php - 重定向ajax请求[关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 如何在 php wordpress 中重定向 ajax 请求 I tried header Location http redirect
  • MySQL:空间查询查找纬度/经度点是否位于给定边界内

    我正在研究谷歌地图搜索功能 其目的是找出 地理位置 点是否位于多边形内 如下图所示 我使用带有 Spatial 扩展的 mysql 5 6 20 我知道它内置有用的几何函数 因此我可以直接从数据库查询地理编码位置 我的目的是熟悉地理空间函数
  • PHP 何时实现了函数使用闭包? [复制]

    这个问题在这里已经有答案了 我在 PHP 手册中找不到解释的部分use 我有代码 num 0 array walk recursive REQUEST function mValue use num num 我的 Eclipse 抱怨 Pa
  • 如何检测iPhone是否有视网膜显示屏?

    如何检测 iPhone 是否配备视网膜显示屏 有靠谱的办法吗 要么是纯 PHP 要么最好是 Zend Framework 方式来执行此操作 我通过这个弄清楚了 var retina window devicePixelRatio gt 1
  • Symfony2 - 在自定义验证器中调用 EmailValidator

    我正在创建一个自定义验证器约束来验证 联系人 类似于 John Doe 电子邮件受保护 gt 遵循Cookbook http symfony com doc current cookbook validation custom constr
  • Google Drive V3、Google API 客户端 2.0 - 批量上传失败

    使用 Google Drive V3 和 API v2 0 主分支进行批量上传失败 我已经修改了https github com google google api php client blob master examples batch
  • Laravel 5 Eloquent 在多个级别上将关系附加到 JSON

    因此 在模型中包含关系非常容易 例如 class User extends Model protected with roles class Role extends Model protected with permissions 当有对
  • 将 docker-compose.yml 中的包安装到 docker 容器中

    我是 docker 和 docker compose 的初学者 我需要你的帮助 我正在使用 docker compose 制作 PHP NGINX PostgresQL symfony 开发环境 这里是 web image nginx 1
  • 在 Elasticsearch php API 中使用多种类型或索引

    我想使用查询多种类型和索引Elasticsearch PHP API 但我不知道怎么办 我应该将类型和索引的数组传递给 params params index index array of indices params type types

随机推荐