[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>
<?php $i = 1; ?>
<?php foreach ($this->cart->contents() as $items): ?>
<?php echo form_hidden( 'hdrow' . $i, $items['rowid']); ?>
<tr>
<td><a href="<?php echo base_url().'cart/delete/'. $items['rowid'] ;?>">Delete</a></td>
<td><?php echo form_input(array('name' => 'row'. $i, 'value' => $items['qty'], 'maxlength' => '3', 'size' => '5','class' => 'num_only')); ?></td>
<td>
<?php echo $items['name']; ?>
<?php if ($this->cart->has_options($items['rowid']) == TRUE): ?>
<p>
<?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; ?>
</p>
<?php endif; ?>
</td>
<td><?php echo $this->cart->format_number($items['price']); ?></td>
<td>$<?php echo $this->cart->format_number($items['subtotal']); ?></td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>
<tr>
<td colspan="2"> </td>
<td class="right"><strong>Total</strong></td>
<td class="right">$<?php echo $this->cart->format_number($this->cart->total()); ?></td>
</tr>
</table>
<p><?php echo form_submit('', 'Destroy your Cart'); ?></p>
<p><?php echo form_submit('', 'Update your Cart'); ?></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');
}
[eluser]suku[/eluser]
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>
<?php $i = 1; ?>
<?php foreach ($this->cart->contents() as $items): ?>
<?php echo form_hidden( 'hdrow' . $i, $items['rowid']); ?>
<tr>
<td><a href="<?php echo base_url().'cart/delete/'. $items['rowid'] ;?>">Delete</a></td>
<td><?php echo form_input(array('name' => 'row'. $i, 'value' => $items['qty'], 'maxlength' => '3', 'size' => '5','class' => 'num_only')); ?></td>
<td>
<?php echo $items['name']; ?>
<?php if ($this->cart->has_options($items['rowid']) == TRUE): ?>
<p>
<?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; ?>
</p>
<?php endif; ?>
</td>
<td><?php echo $this->cart->format_number($items['price']); ?></td>
<td>$<?php echo $this->cart->format_number($items['subtotal']); ?></td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>
<tr>
<td colspan="2"> </td>
<td class="right"><strong>Total</strong></td>
<td class="right">$<?php echo $this->cart->format_number($this->cart->total()); ?></td>
</tr>
</table>
<p><?php echo form_submit('', 'Destroy your Cart'); ?></p>
<p><?php echo form_submit('', 'Update your Cart'); ?></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');
}
[eluser]jmadsen[/eluser]
Either use:
Code: <?php echo form_open('cart/update/'.$items['rowid'].'/'.$items[qty]); ?>
or put it into hidden elements and use a post instead
[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
[eluser]suku[/eluser]
idid the first one
Code: <?php echo form_open('cart/update/'.$items['rowid'].'/'.$items[qty]); ?>
but got that error
[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>
<?php $i = 1; ?>
<?php foreach ($this->cart->contents() as $items): ?>
<?php echo form_hidden( 'hdrow' . $i, $items['rowid']); ?>
<tr>
<td><a href="<?php echo base_url().'cart/delete/'. $items['rowid'] ;?>">Delete</a></td>
<td><?php echo form_input(array('name' => 'row'. $i, 'value' => $items['qty'], 'maxlength' => '3', 'size' => '5','class' => 'num_only')); ?></td>
<td>
<?php echo $items['name']; ?>
<?php if ($this->cart->has_options($items['rowid']) == TRUE): ?>
<p>
<?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; ?>
</p>
<?php endif; ?>
</td>
<td><?php echo $this->cart->format_number($items['price']); ?></td>
<td>$<?php echo $this->cart->format_number($items['subtotal']); ?></td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>
<tr>
<td colspan="2"> </td>
<td class="right"><strong>Total</strong></td>
<td class="right">$<?php echo $this->cart->format_number($this->cart->total()); ?></td>
</tr>
</table>
<p><?php echo form_submit('', 'Destroy your Cart'); ?></p>
<p><?php echo form_submit('', 'Update your Cart'); ?></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
|