>控制器
在我的控制器中,我像这样添加产品,购物车正在重定向但不添加产品,如何解决此问题?
function tambah()
{
$data_produk= array('id' => $this->input->post('id'),
'nama_produk' => $this->input->post('nama_produk'),
'harga' => $this->input->post('harga'),
'gambar' => $this->input->post('gambar'),
//'seller' => $this->input->post('seller'),
'qty' => $this->input->post('qty')
);
//die(print_r($data_produk));
$this->cart->insert($data_produk);
$cart = $this->cart->contents();
if(!empty($cart)){
// print_r($cart);
}
redirect('product');
}
视图;
<div class="col-md-8">
<div class="product_list">
<div class="row">
<?php foreach($shopall as $row){ ?>
<div class="col-lg-6 col-sm-6">
<div class="single_product_item">
<img src="assets/img/categori/product1.png" alt="" class="img-fluid">
<div class="card_area">
<form action="<?php echo base_url();?>cart/tambah" method="post" accept-charset="utf-8">
<div class="product_count_area" style="margin:-40PX -35PX 0PX 0PX;">
<p style="text-align:center;">Rp. <?php echo number_format($row['harga'],0,",",".");?></p>
<div class="product_count d-inline-block">
<span class="product_count_item inumber-decrement"> <i class="ti-minus"></i></span>
<input class="product_count_item input-number" name="qty" type="number" value="1" min="1" max="99">
<span class="product_count_item number-increment"> <i class="ti-plus"></i></span>
</div>
</div>
<p><a href="<?php echo base_url('cart/detail/'.$row['id']) ?>"><?php echo $row['nama_produk'] ?></a></p>
<input type="hidden" name="id" value="<?php echo $row['id']; ?>" />
<input type="hidden" name="nama_produk" value="<?php echo $row['nama_produk']; ?>" />
<input type="hidden" name="harga" value="<?php echo $row['harga']; ?>" />
<input type="hidden" name="gambar" value="<?php echo $row['gambar']; ?>" />
<div style="text-align:center; margin:-20px;" class="add_to_cart">
<!--<button type="submit" class="btn_3">add to cart</button>-->
<button type="submit" class="btn btn-sm btn-success"><i class="glyphicon glyphicon-shopping-cart"></i> Beli</button>
</div>
</form>
</div>
</div>
</div>
<?php } ?>
</div>
<div class="load_more_btn text-center">
<a href="#" class="btn_3">Load More</a>
</div>
</div>
</div>
在我的上一个项目中,我可以使用它的购物车功能,但在这个项目中,购物车仍然是空的,你能指出我的代码哪里有问题吗?
代码点火器购物车 在数组键中使用英语,(除非您以某种方式修改了它(
这应该有效 - 注意:在选项下添加您可能需要保存的任何额外数据,不要定义自己的数组键。 查看此处了解更多信息 编码购物车
$data_produk = array(
'id' => 'sku_123ABC',
'qty' => 1,
'price' => 39.95,
'name' => 'T-Shirt',
'options' => array('Size' => 'L', 'Color' => 'Red')
);
而不是这个
$data_produk= array('id' => $this->input->post('id'),
'nama_produk' => $this->input->post('nama_produk'),
'harga' => $this->input->post('harga'),
'gambar' => $this->input->post('gambar'),
//'seller' => $this->input->post('seller'),
'qty' => $this->input->post('qty')
);
尝试根据您的语言进行映射