Welcome Guest, Not a member yet? Register   Sign In
shoping cart problem
#1

[eluser]suku[/eluser]
hi iam having problem in updating the cart.
there is no passage of parameters as i have to pass two parameters rowid and qty,here is code

view file
Code:
<?php foreach ($this->cart->contents() as $items): ?>

<?php echo form_open('cart/update/'.$items['rowid']); ?>// i need to pass qty as well how to pass????

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

controller //only update function
Code:
function update($rowid,$qty)
  {
  
   $data = array(
                'rowid' => $rowid,
                'qty'   => $qty
             );
   print_r($data);
   exit;

  $this->cart->update($data);
  //redirect('cart/view');
  }
#2

[eluser]suku[/eluser]
Code:
&lt;?php foreach ($this->cart->contents() as $items): ?&gt;

&lt;?php echo form_open('cart/update/'.$items['rowid']); ?&gt;// i need to pass qty as well how to pass????

&lt;?php endforeach;?&gt;
<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>

controller //only update function

Code:
function update($rowid,$qty)
  {
  
   $data = array(
                'rowid' => $rowid,
                'qty'   => $qty
             );
   print_r($data);
   exit;

  $this->cart->update($data);
  //redirect('cart/view');
  }
#3

[eluser]jmadsen[/eluser]
Either use:

Code:
&lt;?php echo form_open('cart/update/'.$items['rowid'].'/'.$items[qty]); ?&gt;

or put it into hidden elements and use a post instead
#4

[eluser]suku[/eluser]
oh i run the code but it says error again. it says

A PHP Error was encountered

Severity: Notice

Message: Use of undefined constant qty - assumed 'qty'

Filename: cart/view.php

Line Number: 3
#5

[eluser]suku[/eluser]
idid the first one
Code:
&lt;?php echo form_open('cart/update/'.$items['rowid'].'/'.$items[qty]); ?&gt;
but got that error
#6

[eluser]suku[/eluser]
my controller:
Code:
&lt;?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:
&lt;?php foreach ($this->cart->contents() as $items): ?&gt;

&lt;?php echo form_open('cart/update/'.$items['rowid'].'/'.$items['qty']); ?&gt;


&lt;?php endforeach;?&gt;
<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




Theme © iAndrew 2016 - Forum software by © MyBB