我正在使用 codeigniter 购物车来存储多行。这是一个预订系统网站。
这是我检索购物车的代码:
<?php if ($cart = $this->cart->contents()): ?>
<table class="booking">
<tr>
<td>#</td>
<td>Room Type</td>
<td>Check In</td>
<td>Checkout</td>
<td>Nights</td>
<td align="right">Price/Night</td>
<td width="10">Rooms</td>
<td align="right">Amount</td>
<td>Options</td>
</tr>
<?php $grand_total = 0; $i = 0; ?>
<?php foreach ($cart as $item): ?>
<tr bgcolor="#FFFFFF">
<td><?php echo $i+1; ?></td>
<td><?php echo $item['name']; ?></td>
<td><?php echo $item['checkin']; ?></td>
<td><?php echo $item['checkout']; ?></td>
<td align="center"><?php echo $item['nights']; ?></td>
<td align="right"><?php echo number_format($item['subtotal'],2); ?></td>
<td><input type="text" name="booking<?php echo $item['id'] ?>" value="<?php echo $item['qty'] ?>" maxlength="3" size="1" style="text-align: right" /></td>
<?php $amount = $item['subtotal'] * $item['qty']; ?>
<?php $grand_total = $grand_total + $amount; ?>
<td align="right"><?php echo number_format($amount,2) ?></td>
<td><?php echo anchor('bookings/remove/'.$item['rowid'],'Cancel'); ?></td>
<?php endforeach; ?>
</tr>
<tr>
<td colspan="2"><b>Order Total: <?php echo number_format($grand_total,2); ?></b></td>
<td colspan="7" align="right">
<input type="button" value="Clear Cart" onclick="clear_cart()">
<input type="button" value="Update Cart" onclick="update_cart()">
<?php
/*if(isset($_SESSION['sess_user_id']) || (trim($_SESSION['sess_user_id']) <> '')) {
$location='booking_checkout.php';
}else{
$location='billing_info.php';
}*/
?>
<input type="button" value="Place Order" onclick="window.location='<?php //echo $location; ?>'"></td>
</tr>
</table>
<?php endif; ?>
该clear_cart()
函数适用于以下代码:
<script>
function clear_cart() {
var result = confirm('Are you sure want to clear all bookings?');
if(result) {
window.location = "http://localhost/reservation/bookings/remove/all";
}else{
return false; // cancel button
}
}
</script>
这是我的控制器中的删除功能:
function remove($rowid) {
if ($rowid=="all"){
$this->cart->destroy();
}else{
$data = array(
'rowid' => $rowid,
'qty' => 0
);
$this->cart->update($data);
}
redirect('bookings');
}
但是如果我有超过 1 行,我不知道如何更新购物车。这里重要的是更新购物车中的房间数量(即数量)。