[eluser]@Frédéric Quié - bleekom.org[/eluser]
Hello,
I think you forgot something from the user guide example on Cart in CI 1.7.2 :
Here is the controller :
Code:
<?php
class testcart extends Controller {
function __construct() //constructeur
{
parent::Controller(); // appel l'objet parent Controller
$this->load->library('cart');
$this->load->helper(array('form', 'url'));
//$this->load->library('form_validation');
}
function index()
{
//$this->load->library('form');
$this->output->enable_profiler(TRUE);
$data = array(
array(
'id' => 'sku_123ABC',
'qty' => 1,
'price' => 39.95,
'name' => 'T-Shirt',
'options' => array('Size' => 'L', 'Color' => 'Red')
),
array(
'id' => 'sku_567ZYX',
'qty' => 1,
'price' => 9.95,
'name' => 'Coffee Mug'
),
array(
'id' => 'sku_965QRS',
'qty' => 1,
'price' => 29.95,
'name' => 'Shot Glass'
)
);
$this->cart->insert($data);
$this->load->view('v_cart');
}
function update()
{
//$this->load->library('form');
$this->output->enable_profiler(TRUE);
$this->cart->update($_POST[1]);
$this->cart->update($_POST[2]);
$this->cart->update($_POST[3]);
$this->load->view('v_cart');
}
}
?>
And the view :
Code:
<?php echo form_open('testcart/update'); ?>
<table cellpadding="6" cellspacing="1" style="font-size:12px;width:50%" border="0">
<tr BGCOLOR="#AAA">
<th style="text-align:left">Item Description</th>
<th style="width:10%;text-align:left">QTY</th>
<th style="width:15%;text-align:right">Item Price</th>
<th style="width:15%;text-align:right">Sub-Total</th>
</tr>
<?php $i = 1; ?>
<?php foreach($this->cart->contents() as $items): ?>
<?php echo form_hidden($i.'[rowid]', $items['rowid']); ?>
<tr BGCOLOR="#CCC">
<td>
<?php echo $items['name']; ?>
<?php if ($this->cart->has_options($items['rowid']) == TRUE): ?>
<br>
<?php foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value): ?>
<strong><?php echo $option_name; ?>:</strong> <?php echo $option_value; ?><br />
<?php endforeach; ?>
<?php endif; ?>
</td>
<td valign="top"><?php echo form_input(array('name' => $i.'[qty]', 'value' => $items['qty'], 'maxlength' => '3', 'size' => '2')); ?></td>
<td valign="top" style="text-align:right"><?php echo $this->cart->format_number($items['price']); ?> €</td>
<td valign="top" style="text-align:right"><?php echo $this->cart->format_number($items['subtotal']); ?> €</td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>
<tr>
<td colspan="2"> </td>
<td BGCOLOR="#111" style="color:#fff;text-align:center"><strong>Total</strong></td>
<td BGCOLOR="#111" style="color:#fff;text-align:right"><strong><?php echo $this->cart->format_number($this->cart->total()); ?> €</strong></td>
</tr>
</table>
<p><?php echo form_submit('', 'Update your Cart'); ?></p>
I guess it's the '$i' you got rid of... Because for me it works perfectly well !!! ;-)