Welcome Guest, Not a member yet? Register   Sign In
how to use cart.php on CI?
#9

[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>

&lt;?php $i = 1; ?&gt;

&lt;?php foreach($this->cart->contents() as $items): ?&gt;

    &lt;?php echo form_hidden($i.'[rowid]', $items['rowid']); ?&gt;
    
    <tr BGCOLOR="#CCC">
      <td>
        &lt;?php echo $items['name']; ?&gt;
                    
            &lt;?php if ($this->cart->has_options($items['rowid']) == TRUE): ?&gt;
                    
                <br>
                    &lt;?php foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value): ?&gt;
                        
                        <strong>&lt;?php echo $option_name; ?&gt;:</strong> &lt;?php echo $option_value; ?&gt;<br />
                                        
                    &lt;?php endforeach; ?&gt;
                
                
            &lt;?php endif; ?&gt;
                
      </td>
        <td valign="top">&lt;?php echo form_input(array('name' => $i.'[qty]', 'value' => $items['qty'], 'maxlength' => '3', 'size' => '2')); ?&gt;</td>
      <td  valign="top" style="text-align:right">&lt;?php echo $this->cart->format_number($items['price']); ?&gt; €</td>
      <td  valign="top" style="text-align:right">&lt;?php echo $this->cart->format_number($items['subtotal']); ?&gt; €</td>
    </tr>

&lt;?php $i++; ?&gt;

&lt;?php endforeach; ?&gt;

<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>&lt;?php echo $this->cart->format_number($this->cart->total()); ?&gt; €</strong></td>
</tr>

</table>

<p>&lt;?php echo form_submit('', 'Update your Cart'); ?&gt;</p>

I guess it's the '$i' you got rid of... Because for me it works perfectly well !!! ;-)


Messages In This Thread
how to use cart.php on CI? - by El Forum - 05-15-2009, 02:28 AM
how to use cart.php on CI? - by El Forum - 05-15-2009, 02:33 AM
how to use cart.php on CI? - by El Forum - 05-15-2009, 02:42 AM
how to use cart.php on CI? - by El Forum - 05-15-2009, 03:13 AM
how to use cart.php on CI? - by El Forum - 05-15-2009, 03:23 AM
how to use cart.php on CI? - by El Forum - 05-15-2009, 03:31 AM
how to use cart.php on CI? - by El Forum - 05-15-2009, 03:34 AM
how to use cart.php on CI? - by El Forum - 05-15-2009, 03:52 AM
how to use cart.php on CI? - by El Forum - 05-15-2009, 05:34 AM
how to use cart.php on CI? - by El Forum - 05-15-2009, 07:48 AM
how to use cart.php on CI? - by El Forum - 05-18-2009, 06:09 AM
how to use cart.php on CI? - by El Forum - 05-18-2009, 06:12 AM
how to use cart.php on CI? - by El Forum - 05-18-2009, 07:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB