<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Mkeranjang extends CI_Model{

  /**

  * @author Fendrik Nurul Jadid <fendrik1311@gmail.com>

  * @since v.1.0

  **/


  public function __construct()
  {
    parent::__construct();
    //Codeigniter : Write Less Do More
  }

  public function get_data($id_user){
    return $this->db
    ->select("*, '0' as pilih, '0' as pilih_toko")
    ->join("barang","barang.idbarang=keranjang.barang_idbarang")
    ->join("mitra","mitra.idmitra=barang.mitra_idmitra")
    ->where("keranjang.data_user_iddata_user",$id_user)
    ->order_by("idmitra","DESC")
    // ->order_by("idkeranjang","DESC")
    ->get("keranjang")->result();
  }

  public function getMitra($id_barang)
  {
    return $this->db
    // ->select("mitra.idmitra")
    ->join("barang","barang.idbarang = keranjang.barang_idbarang")
    ->join("mitra","mitra.idmitra = barang.mitra_idmitra")
    ->where_in("keranjang.barang_idbarang",$id_barang)
    ->group_by("keranjang.mitra_idmitra")
    ->get("keranjang");
  }

  public function cekBarang($iduser, $id_barang)
  {
    return $this->db
    ->where("data_user_iddata_user", $iduser)
    ->where("barang_idbarang", $id_barang)
    ->get("keranjang");
  }

  public function getBarang($idbarang, $idmitra)
{
  return $this->db
  // ->select("barang.nama_barang")
  ->join("barang","barang.idbarang=keranjang.barang_idbarang")
  ->join("mitra","mitra.idmitra = barang.mitra_idmitra")
  ->where("keranjang.barang_idbarang",$idbarang)
  ->where("mitra.idmitra",$idmitra)
  ->group_by("mitra.idmitra")
  ->get("keranjang");
}





}
