diff --git a/app/Controllers/Service.php b/app/Controllers/Service.php index 9f859fb..5412a59 100755 --- a/app/Controllers/Service.php +++ b/app/Controllers/Service.php @@ -219,24 +219,27 @@ class Service extends BaseController return $this->response->setJSON([]); } } - + public function get_product_by_cc(){ $cc_id = $this->request->getPost('cc_id'); $products = []; $model_ids = $this->BikemodelsModel->select('model_id')->where('cubic_capacity_id', $cc_id)->asArray()->findAll(); - foreach ($model_ids as $model) { - $modelId = $model['model_id']; - // echo $modelId; - $product = $this->ProductModel->select('products.*, manufacturer.manufacturer_name') - ->join('manufacturer', 'manufacturer.manufacturer_id = products.manufacturer_id') - ->where('JSON_CONTAINS(products.models_id, \'["' . $modelId . '"]\')', null, false) - ->where('products.isactive', 1) - ->findAll(); - // echo( $this->ProductModel->getLastQuery()->getQuery()); - $products = array_merge($products, $product); - } - $products = array_unique($products, SORT_REGULAR); + $mid[] = 0; // default zero. because general.. + foreach($model_ids as $model){ + $mid[] = $model['model_id']; + } + $products = []; + foreach ($mid as $id) { + $sql = "SELECT products.*, manufacturer.manufacturer_name + FROM products + JOIN manufacturer ON manufacturer.manufacturer_id = products.manufacturer_id + WHERE JSON_CONTAINS(products.models_id, ?) + AND products.isactive = 1"; + + $result = $this->ProductModel->query($sql, ['"' . $id . '"'])->getResult(); + $products = array_merge($products, $result); + } return $this->response->setJSON($products); } diff --git a/app/Views/job_card_form.php b/app/Views/job_card_form.php index a9fba7f..6256648 100755 --- a/app/Views/job_card_form.php +++ b/app/Views/job_card_form.php @@ -90,8 +90,8 @@