我想更新购物车的数量。我已经谷歌了很多但不能这样做。
显示我不想要的最大页数。完全解决方案我没有得到。希望我能来到这里。请帮我做。这是我的查看页面。
**<table class="table table-hover table-bordered table-striped snipcart-details "> <thead>
<tr>
<th style="color:#FF0033; font-weight:bolder; text-align:center;" >Delete Cart</th>
<th style="color:#FF0033; font-weight:bolder; text-align:center;" >Product Name</th>
<th style="color:#FF0033; font-weight:bolder; text-align:center;" >Image</th>
<th style="color:#FF0033; font-weight:bolder; text-align:center;" >Price</th>
<th style="color:#FF0033; font-weight:bolder; text-align:center;" >Quantity</th>
<th colspan="2" style="color:#FF0033; font-weight:bolder; text-align:center;" >Total</th>
</tr>
</thead>
<tbody>
<?php foreach ($this->cart->contents() as $items) { ?>
<tr>
<td style="color:#000000; font-weight:bolder; text-align:center;" >
<a href="#" class="remove_cart" title="delete" row_id="<?php echo $items['rowid']; ?>" rel="1">
<i class="fa fa-times fa-2x" style="color:red;" aria-hidden="true"></i> </a></td>
<td style="color:#000000; font-weight:bolder; text-align:center;" ><?php echo $items['name']; ?></td>
<td align="center"><img src="<?php echo base_url('resource/allproduct/'.$items['productImage']);?>" height="50px;" /></td></td>
<td style="color:#000000; font-weight:bolder; text-align:center;"><?php echo $items['price']; ?></td>
<td align="center"><input type="number" name="qty" id="qty" value="<?php echo $items['qty']; ?>"></td>
<td colspan="2" style="color:#000000; font-weight:bolder; text-align:center;">TK <?php echo $this->cart->format_number($items['subtotal']); ?></td>
</tr>
<?php } ?>
</tbody>
<tbody>
<tr>
<th scope="row"><a href=""> <input type="button" name="submit" value="Update" class="button" /> </a></th>
<td align="center"><a href="<?php echo site_url('home'); ?>"> <input type="button" name="submit" value="Continue Shopping" class="button" /></a></td>
<td colspan="3" class="button" align="center" >
<?php if(!empty($userid)){?>
<a href="<?php echo site_url("checkout"); ?>"><input class="button" type="submit" value="Place Order"></a>
<?php } else {?>
<a href="<?php echo site_url("login"); ?>"><input class="button" type="submit" value="Place Order"></a>
<?php }?>
</td>
<td align="center" style="color:#000000;" > <h4>Grand Total</h4> </td>
<td style="font-size:24px; font-weight:800; color:green;">TK <?php echo $this->cart->format_number($this->cart->total()); ?></td>
</tr>
</tbody>
</table>**
这是控制器。
public function index()
{
$data['basicinfo'] = $this->M_cloud->basicall('basic_info');
$where = array('status' => 1);
$data['categoryinfo'] = $this->M_cloud->categoryinfo('item_manage', $where);
$data['rows'] = count($this->cart->contents());
$data['userid'] = $this->session->userdata('user_id');
$data['subcategoryinfo'] = $this->M_cloud->findAll2('sub_category', array('status' => 1));
$data['menuinformation'] = $this->M_cloud->findReport('our_service', array('serviceType'=> 2), 'menuname asc');
$data['menuservice'] = $this->M_cloud->findReport('our_service', array('serviceType'=> 1), 'menuname asc');
$data['socialmedia'] = $this->M_cloud->findAll('social_tbl', 'name asc');
$data['newsinfo'] = $this->M_cloud->findAll('news_table', 'newstitle DESC');
$this->load->view('cartPage', $data);
}
public function buy()
{
$proId = $this->input->post('proId');
$Qty = $this->input->post('Qty');
$prosize = $this->input->post('prosize');
$result = $this->M_cloud->find('product_manage', array('proid' => $proId));
$data2 = array(
'id' => $proId,
'qty' => $Qty,
'name' => $result->proName,
'price' => $result->price,
'prosize' => $prosize,
'productImage' => $result->proimg1,
'product_code' => $result->procode
);
$this->cart->insert($data2);
redirect('cart');
}
public function deleteCartItem() {
$row_id = $this->input->post('row_id');
$data = array(
'rowid' => $row_id,
'qty' => 0
);
$this->cart->update($data);
}
请帮我更新购物车数量。在此先感谢。
答案 0 :(得分:0)
更新购物车项目:
function updateCartItem(){
$data=array(
'rowid'=>$this->input->post('rowid',TRUE),
'qty'=> $this->input->post('quantity',TRUE)
);
if ($this->cart->update($data)) {
echo "Success";
}else{
echo "Faliure";
}
}
要从购物车中删除商品:
function deleteCartItem(){
$row_id = $this->input->post('row_id',TRUE);
if ($rowid) {
return $this->cart->remove($rowid);
}
}