alexa-tracking

Tambah Keranjang dan proses chekcout

Main Content

1024
1024
KASKUS
51
244
https://www.kaskus.co.id/thread/5acc8f1ad9d770f2398b4568/tambah-keranjang-dan-proses-chekcout
Tambah Keranjang dan proses chekcout
Ane lagi belajar Framework CI tiba2 nemu error kegni gan saat mau bikin tambah ke keranjang .
jadi ketika sudah submit , malah tidak ada konten yang tampil dan data yang sudah disubmit juga tidak ada didalam db nya gan.

Mohon pencerahannya gan .
controllernya :
Code:
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Shopping extends CI_Controller {

public function __construct()
{
parent::__construct();
$this->load->library('cart');
$this->load->model('keranjang_model');
}

public function index()
{
$kategori=($this->uri->segment(3))?$this->uri->segment(3):0;
$data['produk'] = $this->keranjang_model->get_produk_kategori($kategori);
$data['kategori'] = $this->keranjang_model->get_kategori_all();
$this->load->view('front/header',$data);
    $this->load->view('front/navbar',$data);
$this->load->view('shopping/tampil_cart',$data);
$this->load->view('front/footer');
}
public function tampil_cart()
{
$data['kategori'] = $this->keranjang_model->get_kategori_all();
$this->load->view('front/header',$data);
    $this->load->view('front/navbar',$data);
$this->load->view('shopping/tampil_cart',$data);
$this->load->view('front/footer');
}

public function check_out()
{
$data['kategori'] = $this->keranjang_model->get_kategori_all();
    $this->load->view('front/header',$data);
    $this->load->view('front/navbar',$data);
$this->load->view('shopping/check_out',$data);
$this->load->view('front/footer');
}

function tambah()
{
$data_produk= array('id' => $this->input->post('id'),
'judul_produk' => $this->input->post('judul_produk'),
'harga' => $this->input->post('harga'),
'foto' => $this->input->post('foto'),
'qty' =>$this->input->post('qty')
);
$this->cart->insert($data_produk);
redirect('shopping');
}

function hapus($rowid)
{
if ($rowid=="all")
{
$this->cart->destroy();
}
else
{
$data = array('rowid' => $rowid,
    'qty' =>0);
$this->cart->update($data);
}
redirect('shopping/tampil_cart');
}

function ubah_cart()
{
$cart_info = $_POST['cart'] ;
foreach( $cart_info as $id => $cart)
{
$rowid = $cart['rowid'];
$harga = $cart['harga'];
$foto = $cart['foto'];
$amount = $price * $cart['qty'];
$qty = $cart['qty'];
$data = array('rowid' => $rowid,
'harga' => $harga,
'foto' => $foto,
'amount' => $amount,
'qty' => $qty);
$this->cart->update($data);
}
redirect('shopping/tampil_cart');
}

public function proses_order()
{
//-------------------------Input data pelanggan--------------------------
$data_pelanggan = array('nama' => $this->input->post('nama'),
'email' => $this->input->post('email'),
'alamat' => $this->input->post('alamat'),
'telp' => $this->input->post('telp'));
$id_pelanggan = $this->keranjang_model->tambah_pelanggan($data_pelanggan);
//-------------------------Input data order------------------------------
$data_order = array('tanggal' => date('Y-m-d'),
    'pelanggan' => $id_pelanggan);
$id_order = $this->keranjang_model->tambah_order($data_order);
//-------------------------Input data detail order-----------------------
if ($cart = $this->cart->contents())
{
foreach ($cart as $item)
{
$data_detail = array('order_id' =>$id_order,
'produk' => $item['id'],
'qty' => $item['qty'],
'harga' => $item['price']);
$proses = $this->keranjang_model->tambah_detail_order($data_detail);
}
}
//-------------------------Hapus shopping cart--------------------------
$this->cart->destroy();
$data['kategori'] = $this->keranjang_model->get_kategori_all();
$this->load->view('themes/header',$data);
$this->load->view('shopping/sukses',$data);
$this->load->view('themes/footer');
}
}
?>



Model nya : 
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Keranjang_model extends CI_Model {

public function get_produk_all()
{
$query = $this->db->get('produk');
return $query->result_array();
}

public function get_produk_kategori($kategori)
{
if($kategori>0)
{
$this->db->where('kategori',$kategori);
}
$query = $this->db->get('produk');
return $query->result_array();
}

public function get_kategori_all()
{
$query = $this->db->get('kategori');
return $query->result_array();
}

public  function get_produk_id($id)
{
$this->db->select('produk.*,judul_kategori');
$this->db->from('produk');
$this->db->join('kategori', 'kategori=kategori.id','left');
    $this->db->where('id',$id);
        return $this->db->get();
    }

public function tambah_order($data)
{
$this->db->insert('tbl_order', $data);
$id = $this->db->insert_id();
return (isset($id)) ? $id : FALSE;
}

public function tambah_detail_order($data)
{
$this->db->insert('tbl_detail_order', $data);
}
}
?>




Views nya :
Code:
<h2>Daftar Belanja</h2>
<form action="<?php echo base_url()?>shopping/ubah_cart" method="post" name="frmShopping" id="frmShopping" class="form-horizontal" enctype="multipart/form-data">
<?php
if ($cart = $this->cart->contents())
{
 ?>

<table class="table">
<tr id= "main_heading">
<td width="2%">No</td>
<td width="10%">Gambar</td>
<td width="33%">Item</td>
<td width="17%">Harga</td>
<td width="8%">Qty</td>
<td width="20%">Jumlah</td>
<td width="10%">Hapus</td>
</tr>
<?php
// Create form and send all values in "shopping/update_cart" function.
$grand_total = 0;
$i = 1;

foreach ($cart as $item):
$grand_total = $grand_total + $item['subtotal'];
?>
<input type="hidden" name="cart[<?php echo $item['id'];?>][id]" value="<?php echo $item['id'];?>" />
<input type="hidden" name="cart[<?php echo $item['id'];?>][rowid]" value="<?php echo $item['rowid'];?>" />
<input type="hidden" name="cart[<?php echo $item['id'];?>][name]" value="<?php echo $item['name'];?>" />
<input type="hidden" name="cart[<?php echo $item['id'];?>][price]" value="<?php echo $item['price'];?>" />
<input type="hidden" name="cart[<?php echo $item['id'];?>][gambar]" value="<?php echo $item['gambar'];?>" />
<input type="hidden" name="cart[<?php echo $item['id'];?>][qty]" value="<?php echo $item['qty'];?>" />
<tr>
<td><?php echo $i++; ?></td>
<td><img class="img-responsive" src="<?php echo base_url() . 'assets/images/'.$item['gambar']; ?>"/></td>
<td><?php echo $item['name']; ?></td>
<td><?php echo number_format($item['price'], 0,",","."); ?></td>
<td><input type="text" class="form-control input-sm" name="cart[<?php echo $item['id'];?>][qty]" value="<?php echo $item['qty'];?>" /></td>
<td><?php echo number_format($item['subtotal'], 0,",",".") ?></td>
<td><a href="<?php echo base_url()?>shopping/hapus/<?php echo $item['rowid'];?>" class="btn btn-sm btn-danger"><i class="glyphicon glyphicon-remove"></i></a></td>
<?php endforeach; ?>
</tr>
<tr>
<td colspan="3"><b>Order Total: Rp <?php echo number_format($grand_total, 0,",","."); ?></b></td>
<td colspan="4" align="right">
<a data-toggle="modal" data-target="#myModal" class ='btn btn-sm btn-danger'>Kosongkan Cart</a>
<button class='btn btn-sm btn-success'  type="submit">Update Cart</button>
<a href="<?php echo base_url()?>shopping/check_out" class ='btn btn-sm btn-primary'>Check Out</a>
</tr>

</table>
<?php
}
else
{
echo "<h3>Keranjang Belanja masih kosong</h3>";
}
?>
</form>


  <!-- Modal Penilai -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog modal-md">
      <!-- Modal content-->
      <div class="modal-content">
      <form method="post" action="<?php echo base_url()?>shopping/hapus/all">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">×</button>
          <h4 class="modal-title">Konfirmasi</h4>
        </div>
        <div class="modal-body">
Anda yakin mau mengosongkan Shopping Cart?

        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-sm btn-primary" data-dismiss="modal">Tidak</button>
          <button type="submit" class="btn btn-sm btn-default">Ya</button>
        </div>

        </form>
      </div>

    </div>
  </div>
  <!--End Modal-->




Mohon berkenaan gan jika dapat ada yang membantu ane ,terimakasih 
ketinggalan :

views nya 1 lagi :

Code:

<?php $this->load->view('front/header'); ?>
<?php $this->load->view('front/navbar'); ?>

<div class="container">
<div class="row">
<div class="col-lg-12">
<ol class="breadcrumb">
<li><a href="<?php echo base_url() ?>"><i class="fa fa-home"></i> Home</a></li>
<li><a >slug_kat ?>"><?php echo $produk->judul_kategori ?></a></li>
<li><a >slug_kat."/".$produk->slug_subkat ?>"><?php echo $produk->judul_subkategori ?></a></li>
<li><a >slug_kat."/".$produk->slug_subkat."/".$produk->slug_supersubkat ?>"><?php echo $produk->judul_supersubkategori ?></a></li>
<li class="active"><?php echo $produk->judul_produk ?></li>
</ol>
<?php echo $this->session->userdata('message') <> '' ? $this->session->userdata('message') : ''; ?>
</div>
<form method="post" action="<?php echo base_url();?>shopping/tambah" method="post" accept-charset="utf-8">
<div class="col-lg-9">
<h5><?php echo $produk->judul_produk ?></h5><hr>
<div class="row">
<div class="col-sm-5">
<?php
if(empty($produk->foto)) {echo "<img src='".base_url()."assets/images/no_image_thumb.png' width='400' height='400'>";}
else { echo " <img >foto.$produk->foto_type."' class='img-responsive' title='$produk->judul_produk' alt='$produk->judul_produk' id='myImg' width='400' height='400'> ";}
?>
<br>
</div>
<div class="col-sm-7">
<p><b>Spesifikasi</b></p>
<p>Harga: Rp <?php echo number_format($produk->harga) ?></p>
<p>Down Payment: Rp <?php echo number_format($produk->down_payment) ?></p>
<p>Tanggal Keberangkatan: <?php echo ($produk->tanggal_keberangkatan) ?></p>
<p>Tanggal Kembali: <?php echo ($produk->tanggal_kembali) ?></p>
<p>Sisa Jumlah Peserta: <?php echo ($produk->qty) ?></p>
<p>Kategori:
<a >slug_kat ?>">
<?php echo $produk->judul_kategori ?>
</a> /
<a >slug_kat."/".$produk->slug_subkat ?>">
<?php echo $produk->judul_subkategori ?>
</a> /
<a >slug_kat."/".$produk->slug_subkat."/".$produk->slug_supersubkat ?>">
<?php echo $produk->judul_supersubkategori ?>
</a>
</p>
</div>
<button class="btn btn-lg btn-success" type="submit"><i class="glyphicon glyphicon-shopping-cart"></i> Beli Produk Ini</button>
</div>
</form>
<hr>
<div class="row">
<div class="col-lg-12">
<b>Deskripsi Perjalanan</b>
<p><?php echo $produk->deskripsi ?></p>
</div>
</div>
<hr>

<h4>Diskusi Produk</h4>
<div class="row">
<div class="col-md-12">
<p><?php echo validation_errors(); ?></p>
<?php
if(!isset($_SESSION['username'])){
echo "Silahkan login terlebih dahulu, klik <a href='".base_url()."user/login'>disini</a> untuk login.";
}
else{
?>
<?php echo form_open("produk/komen/".$produk->username.'/'.$produk->slug_produk."");?>
<input type="hidden" name="produk_id" value="<?php echo $produk->id_produk ?>">
<div class="form-group">
<textarea class="form-control" name="isi_komentar" placeholder="Isikan pertanyaan Anda disini" required></textarea>
</div>
<div class="form-group">
<?php echo $cap_img; ?><br><br>
<input type="text" class="form-control" name="kode_captcha" placeholder="isikan captcha diatas" required>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Submit</button>
<button type="reset" class="btn btn-default">Cancel</button>
</div>
<?php echo form_close(); ?>
<?php } ?>

<hr>

<?php
if($get_komentar == NULL){
echo "Belum ada komentar";
}
else
{
foreach ($get_komentar as $komen)
{
?>
<b><?php echo $komen->nama ?></b>, berkata:
<p>" <?php echo $komen->isi_komentar ?> "</p>
<p align="right">pada <?php echo $komen->created ?></p>
<?php }} ?>
</div>
</div>

</div>
<hr>

<?php $this->load->view('front/sidebar'); ?>

<?php $this->load->view('front/footer'); ?>

<div id="myModal" class="modal">
<!-- The Close Button -->
<span class="close">×</span>

<!-- Modal Content (The Image) -->
<?php echo "<img >foto.$produk->foto_type."' class='modal-content' title='$produk->judul_produk' id='img'>" ?>

<!-- Modal Caption (Image Text) -->
<div id="caption">Tes</div>

[removed]
// Get the modal
var modal = document.getElementById('myModal');

// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById('myImg');
var modalImg = document.getElementById("img");
var captionText = document.getElementById("caption");
img.onclick = function(){
modal.style.display = "block";
modalImg.src = this.src;
captionText[removed] = this.alt;
}

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
[removed]
</div>