0

我正在尝试为 opencart 进行动态产品过滤,用户可以在其中添加过滤器,将它们分配给类别并为产品分配过滤器值。

目前我有这些mysql表:

  1. 过滤器 - ID NAME
  2. Filters_categories - ID FILTER_ID CATEGORY_ID
  3. Filters_values - ID FILTER_ID VALUE
  4. Filters_products - ID FILTER_ID VALUE_ID PRODUCT_ID

问题在于这种结构,当激活多个过滤器时我无法获得产品,因为我得到的 MySQL 查询看起来像这样:

SELECT product_id FROM Filters_products WHERE ((name_id='1' OR name_id='2') AND filter_id='1') AND ((name_id='3' OR name_id='4') AND filter_id='2')

这没有任何意义。我不知道应该如何更改我的数据库结构以使动态过滤成为可能。我该如何解决这种情况?谢谢你。

4

3 回答 3

0

使用这个很棒的扩展,

http://www.opencart.com/index.php?route=extension/extension/info&extension_id=10098

希望这可以帮助。

于 2013-01-17T11:59:41.357 回答
0

在文件 /catalog/model/catalog/product.php 中找到第 nr 行。91 并用此代码替换“if {}”块...

if (!empty($data['filter_category_id'])) {
        if (!empty($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) {

                $filterSQL = $this->db->query("SELECT * FROM " . DB_PREFIX . "filter WHERE filter_id = ". $filter_id);

                $implode[$filterSQL->row['filter_group_id']][] = (int)$filter_id;

            }

            foreach($implode AS $implode2) {

                $sql .= " AND (";
                     foreach($implode2 AS $filterID) {
                        $sql .= "(SELECT count(*) FROM product_filter WHERE product_filter.product_id=p.product_id AND product_filter.filter_id=$filterID) OR ";
                     }
                     $sql = substr($sql, 0, -4);
                $sql .= ")";
            }

        }
    }
于 2013-01-24T22:12:37.247 回答
0

SELECT product_id FROM Filters_products WHERE (screen_id='1' OR screen_id='2') and (connection_id='1')

于 2012-07-22T09:57:48.853 回答