Question: Search Products In Admin Panel By Custom Fields

Search Products In Admin Panel By Custom Fields

Hi can you tell me how to make it so that when creating sale on Sale -> Add Sale a product can be found not only by name and its code but also by custom fields?

A

Aleksandr

Asked

Hi can you tell me how to make it so that when creating sale on Sale -> Add Sale a product can be found not only by name and its code but also by custom fields?

  • EG

    Enyinnaya Gift

    Answered

    Hi, @Aleksandr

    Edit the Sales_model.php script and replace the getProductNames function in lines 444–471 with the function below.

    
        public function getProductNames($term, $warehouse_id, $pos = false, $limit = 5)
        {
            $wp = "( SELECT product_id, warehouse_id, quantity as quantity from {$this->db->dbprefix('warehouses_products')} ) FWP";
    
            $this->db->select('products.*, FWP.quantity as quantity, categories.id as category_id, categories.name as category_name', false)
                ->join($wp, 'FWP.product_id=products.id', 'left')
                // ->join('warehouses_products FWP', 'FWP.product_id=products.id', 'left')
                ->join('categories', 'categories.id=products.category_id', 'left')
                ->group_by('products.id');
            if ($this->Settings->overselling) {
                $this->db->where("({$this->db->dbprefix('products')}.name LIKE '%" . $term . "%' OR {$this->db->dbprefix('products')}.code LIKE '%" . $term . "%' OR  concat({$this->db->dbprefix('products')}.name, ' (', {$this->db->dbprefix('products')}.code, ')') LIKE '%" . $term . "%') OR {$this->db->dbprefix('products')}.cf1 LIKE '%" . $term . "%' OR {$this->db->dbprefix('products')}.cf2 LIKE '%" . $term . "%' OR {$this->db->dbprefix('products')}.cf2 LIKE '%" . $term . "%' OR {$this->db->dbprefix('products')}.cf3 LIKE '%" . $term . "%' OR {$this->db->dbprefix('products')}.cf4 LIKE '%" . $term . "%' OR {$this->db->dbprefix('products')}.cf5 LIKE '%" . $term . "%' OR {$this->db->dbprefix('products')}.cf6 LIKE '%" . $term . "%' ");
            } else {
                $this->db->where("((({$this->db->dbprefix('products')}.track_quantity = 0 OR FWP.quantity > 0) AND FWP.warehouse_id = '" . $warehouse_id . "') OR {$this->db->dbprefix('products')}.type != 'standard') AND "
                    . "({$this->db->dbprefix('products')}.name LIKE '%" . $term . "%' OR {$this->db->dbprefix('products')}.code LIKE '%" . $term . "%' OR  concat({$this->db->dbprefix('products')}.name, ' (', {$this->db->dbprefix('products')}.code, ')') LIKE '%" . $term . "%') OR {$this->db->dbprefix('products')}.cf1 LIKE '%" . $term . "%' OR {$this->db->dbprefix('products')}.cf2 LIKE '%" . $term . "%' OR {$this->db->dbprefix('products')}.cf2 LIKE '%" . $term . "%' OR {$this->db->dbprefix('products')}.cf3 LIKE '%" . $term . "%' OR {$this->db->dbprefix('products')}.cf4 LIKE '%" . $term . "%' OR {$this->db->dbprefix('products')}.cf5 LIKE '%" . $term . "%' OR {$this->db->dbprefix('products')}.cf6 LIKE '%" . $term . "%'");
            }
            // $this->db->order_by('products.name ASC');
            if ($pos) {
                $this->db->where('hide_pos !=', 1);
            }
            $this->db->limit($limit);
            $q = $this->db->get('products');
            if ($q->num_rows() > 0) {
                foreach (($q->result()) as $row) {
                    $data[] = $row;
                }
                return $data;
            }
        }
    

    My name is @Enyinnaya Gift . I am an Independent Software Developer with in-depth knowledge of SMA system. I have done a lot of customization for many happy clients across the globe.

    You can check out highlights and a demo of my latest customization by Clicking HERE - Highlights

    You can also reach me via any of the following mediums for a real-time discussion on your customization request:

    -Skype ID: enyinnayag -Wechat ID: genyinnaya -Email: [email protected] -WhatsApp: +2348068355192

  • MS

    Mian Saleem

    Answered

    Enyinnaya Gift Thank you for helping 😃

  • Login to Reply