• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
shoping cart problem

#6
[eluser]suku[/eluser]
my controller:
Code:
<?php  
class Cart extends CI_Controller{

       public function __construct()
       {
            parent::__construct();
  
   $this->load->helper('url');
   $this->load->helper('form');
   $this->load->helper('array');
   $this->load->library('pagination');
   $this->load->model('category_model');
   $this->load->model('cart_model');
   $this->load->model('menu_model');
   $this->load->library('cart');
   $this->load->library('session');
        }
  function index()
  {
   echo "test";
  }
  function menu_display()
  {
   $config['base_url'] = base_url(). 'cart/menu_display';
   $config['per_page'] = 1;
   $config['total_rows'] = $this->menu_model->count_record();
   $config['uri_segment'] = 3;
   $config['num_links'] = 3;
   $this->pagination->initialize($config);
   $data['rows'] = $this->menu_model->get_data($config['per_page'], $this->uri->segment(3));
  
   $this->load->view('cart/details_item',$data);
  }
  function insertCartItems()
  {
  
  
   $cartitems = $this->cart->contents();
  
   $total_cart_items =  $this->cart->total_items();
   //print_r($total_cart_items);
   //exit;
   //$data['rows']=$this->menu_model->select_two($Id);
   foreach ($cartitems as $Items)
   {
    $rowId = $Items['rowid'];
    $itemId = $Items['id'];
    $quantity = $Items['qty'];
    $price = $Items['price'];
    $cartitems = array
         (
        'fld_rowid' => $rowId,
        'fldid' => $itemId,      //fldid==itemid
        'fldquantity' => $quantity,
        'fldprice' => $price
         );
        
   }
   //print_r($cartitems);
   //exit;
   $this->cart_model->insert_cartitems($cartitems);  
  }
  
  function delete($rowid)
  {
     $data = array(
     'rowid' => $rowid,
     'qty'   => 0
     );  
  
   $this->cart->update($data);
   redirect('cart/view');
  }
  
  function view()
  {
   $this->load->view('cart/view');
  }
  function viewtest()
  {
   $this->load->view('cart/cart_view');
  }
  function viewCart()
  {
   $data['cart1']= $this->get_post_data_cart();
   //print_r($data);
   //exit;
   $this->cart->insert($data);
   redirect('cart/view');
  }
  function get_post_data_cart()
  {
   //$data['rows']=$this->menu_model->select_two($Id);
   $data=array(
      'id'=>$this->input->post('fldid'),
      'qty'=>1,
      'name'=>$this->input->post('fldmenuitemname'),
      'price'=>$this->input->post('fldprice')
     );
   //print_r($data);
   //exit;  
   return $data;  
  }
  
  function update($rowid,$qty)
  {
  
   $data = array(
                  'rowid' => $rowid,
                  'qty'   => $qty
             );
   //print_r($data);
   //exit;

  $this->cart->update($data);
  redirect('cart/view');
  }
}
and view:
Code:
<?php foreach ($this->cart->contents() as $items): ?>

<?php echo form_open('cart/update/'.$items['rowid'].'/'.$items['qty']); ?>


<?php endforeach;?>
<table cellpadding="4" cellspacing="0" border="1">

<tr>
  <th>Delete_Items</th>
  <th>QTY</th>
  <th>Item Description</th>
  <th>Item Price</th>
  <th>Sub-Total</th>
</tr>

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

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

&lt;?php echo form_hidden( 'hdrow' . $i, $items['rowid']); ?&gt;
<tr>
<td><a href="&lt;?php echo base_url().'cart/delete/'. $items['rowid'] ;?&gt;">Delete</a></td>
   <td>&lt;?php echo form_input(array('name' => 'row'. $i, 'value' => $items['qty'], 'maxlength' => '3', 'size' => '5','class' => 'num_only')); ?&gt;</td>
   <td>
  &lt;?php echo $items['name']; ?&gt;
  
   &lt;?php if ($this->cart->has_options($items['rowid']) == TRUE): ?&gt;

    <p>
     &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;
    </p>

   &lt;?php endif; ?&gt;

   </td>
   <td>&lt;?php echo $this->cart->format_number($items['price']); ?&gt;</td>
   <td>$&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 class="right"><strong>Total</strong></td>
  <td class="right">$&lt;?php echo $this->cart->format_number($this->cart->total()); ?&gt;</td>
</tr>

</table>

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

i want to update the quantity......so please i would be glad if i get that possible and hope you will run the code and send me the result.
thanks,
suku


Messages In This Thread
shoping cart problem - by El Forum - 06-28-2012, 03:21 AM
shoping cart problem - by El Forum - 07-08-2012, 09:52 PM
shoping cart problem - by El Forum - 07-09-2012, 01:51 AM
shoping cart problem - by El Forum - 07-09-2012, 03:39 AM
shoping cart problem - by El Forum - 07-09-2012, 03:41 AM
shoping cart problem - by El Forum - 07-09-2012, 03:49 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.