我似乎无法再添加任何项目,我添加的最新项目将替换现有项目。
public function addcart(){
if(isset($this->session->userdata)){
$type = $this->session->userdata('type');
$username = $this->session->userdata('username');
$this->db->select('id_product ,price');
$query = $this->db->get('product', array('title'=> $this->input->post('title')));
if($query->num_rows() >0){
$row = $query->row();
$data = array(
'id' => $row->id_product,
'qty' => $this->input->post('quantity'),
'price' => $row->price,
'name' => $this->input->post('title'),
//'options' => array('Size' => 'L', 'Color' => 'Red')
);
$this->cart->insert($data);
}
}
}
答案 0 :(得分:1)
public function addcart(){
if(isset($this->session->userdata)){
$type = $this->session->userdata('type');
$username = $this->session->userdata('username');
$this->db->select('id_product ,price');
$query = $this->db->get('product', array('title'=> $this->input->post('title')));
$cart['product'] = $this->cart->contents(); // get previous data from cart
if($query->num_rows() >0){
$row = $query->row();
$id = $row->id_product;
$cart['product'][$id] = array(
'id' => $row->id_product,
'qty' => $this->input->post('quantity'),
'price' => $row->price,
'name' => $this->input->post('title'),
//'options' => array('Size' => 'L', 'Color' => 'Red')
);
$this->cart->insert($cart); //update cart
}
}
}
答案 1 :(得分:0)
控制器:
$code = $this->input->post("idwheel");
$nama = $this->input->post("namawheel");
$base = $this->input->post("basewheel");
$desc = $this->input->post("descwheel");
$amountdefault = $this->input->post("amountwheel");
$data = array(
'id' => $code,
'qty' => 1,
'amountdefault' => $amountdefault,
'price' => $base,
'name' => $nama,
'desc' => $desc
);
$this->cart->insert($data);
redirect("selling",'refresh');
并查看
<?php foreach ($this->cart->contents() as $items): ?>
<tr>
<td><?php echo $items['id']; ?></td>
<td><?php echo $items['name']; ?></td>
<td><?php echo $items['desc']; ?></td>
</tr>
<?php endforeach; ?>
我希望这可以帮助