电子商务产品自动填充背后的逻辑?

时间:2017-08-10 10:00:24

标签: php mysql codeigniter e-commerce

我正在制作一个电子商务网络应用,我想提供自动填充建议。我有类别,子类别,子子类别和产品标题。那么这个逻辑应该适用于此。

以下是我目前正在使用的代码

if (strlen($productString) > 0) {
        $arrSearchString = explode(' ', $productString);
        $noSpaceSearchString = preg_replace('/\s+/', '', $productString);

        $whereConditionString = "";
        foreach ($arrSearchString as $string) {
            if (strlen($string) > 0)
                $whereConditionString .= "category_name like '%$string%' or ";
        }

        $whereConditionString .= "category_name like '%$noSpaceSearchString%' or category_name like '%$productString%' ";

        $this->db->select("DISTINCT(category_id)");
        $this->db->from('tbl_category');
        $this->db->where("($whereConditionString)");
        $this->db->where(array('is_deleted' => 0));
        $categoryIdQuery = $this->db->get_compiled_select();
        $this->db->flush_cache();
    }

    $this->db->select('distinct(p.product_title), c.category_name');
    $this->db->from('tbl_product p');
    $this->db->join('tbl_category c', 'p.product_category_id = c.category_id');

    $this->db->where("(p.product_category_id IN ($categoryIdQuery) or p.product_subcategory_id IN ($categoryIdQuery) or p.product_sub_subcategory_id IN ($categoryIdQuery) or p.product_title like '%$productString%' or p.search_tag like '%$productString%' )", NULL, FALSE);

    $this->db->where(array(
        'p.product_status' => 1,
        'p.is_deleted' => 0,
        'c.is_deleted' => 0,
    ));
    $this->db->order_by('p.product_title', 'asc');
    $result = $this->db->get();
    return $result->result();

这里将$ productString视为搜索字符串。我已经检查了字符串中的每个单词以及没有空格的字符串。

提前致谢

0 个答案:

没有答案