@@ -6,7 +6,8 @@ class Order_model extends CI_Model {
}
publicfunctiongetOrders(){
$this->db->select("ORD.format_order_id,ORD.quantity,ORD.amount,ORD.status,PRD.product_name,TRIM(CONCAT(CUST.first_name,' ' ,IFNULL(CUST.last_name,''))) as customer_name,ORD.order_id");
$this->db->select("ORD.*,PRD.product_name,
TRIM(CONCAT(CUST.first_name,' ',IFNULL(CUST.last_name,''))) as customer_name");
$this->db->from('orders AS ORD');
$this->db->join('products AS PRD','PRD.product_id = ORD.product_id');
$this->db->join('customers AS CUST','CUST.customer_id = ORD.customer_id');
...
...
@@ -20,7 +21,8 @@ class Order_model extends CI_Model {
if($order_id==''){
return0;
}
$result=$this->db->query("SELECT ORD.*,PRD.product_name,PRD.short_description,PRDB.brand_name,TRIM(CONCAT(CUST.first_name,' ' ,IFNULL(CUST.last_name,''))) as customer_name,
PRD.product_name,PRD.short_description,ORDS.format_order_id,ORDS.quantity,ORDS.expected_delivery,ORDS.delivered,ORDS.status AS odr_status
PRD.product_name,PRD.short_description,ORDS.format_order_id,ORDS.quantity,ORDS.expected_delivery,ORDS.delivered,ORDS.status AS odr_status,PRDR.id AS review_id
FROM transaction TRANS
JOIN orders ORDS ON ORDS.order_id = TRANS.booking_id
JOIN products PRD ON PRD.product_id = ORDS.product_id
LEFT JOIN product_rating PRDR ON (ORDS.product_id = PRDR.product_id AND ORDS. customer_id = PRDR.customer_id)
$respArr=array('status'=>'error','message'=>'Something Went Wrong.');
$lmt='';
if($start!=0||$per_page!=0){
$lmt.="LIMIT $start,$per_page";
}
$sql=$this->db->query("SELECT COUNT(ORDS.product_id) as count,PRD.product_id FROM products PRD LEFT JOIN orders AS ORDS ON ORDS.product_id = PRD.product_id WHERE PRD.status='1' GROUP BY PRD.product_id ORDER BY count DESC $lmt ");
if(!empty($sql)&&$sql->num_rows()>0){
foreach($sql->result_array()as$key=>$value){
$result=$this->db->query("SELECT ROUND(AVG(REV.rating),2) AS rating,
COUNT(REV.id) AS reviews,PRD.*,PI.image as product_image
FROM products AS PRD
LEFT JOIN product_images AS PI ON
(PI.id=(SELECT MIN(id)
FROM product_images
WHERE product_id= PRD.product_id AND
PRD.status='1'))
LEFT JOIN product_rating AS REV ON REV.product_id = PRD.product_id
WHERE PRD.status='1' AND PRD.product_id =".$value['product_id']);