Welcome Guest, Not a member yet? Register   Sign In
A question about CI cart
#5

[eluser]jdutoit[/eluser]
Hi I am having a serious problem that I'm sure has a simple solution.

I'm trying to add to the qty value in my cart not replace the qty value when I choose the same item, I am guessing it is overriding the item with the same unique rowid, here is my code (taken from a tutorial)


Controller

function add() {

$this->load->model('Products_model');

$product = $this->Products_model->get($this->input->post('id'));

$insert = array(
'id' => $this->input->post('id'),
'qty' => $this->input->post('qty'),
'price' => $product->price,
'name' => $product->name
);
if ($product->option_name) {
$insert['options'] = array(
$product->option_name => $product->option_values[$this->input->post($product->option_name)]
);
}

$this->cart->insert($insert);

redirect('shop');

}

Model

class Products_model extends Model {

function get_all() {

$results = $this->db->get('products')->result();

foreach ($results as &$result) {

if ($result->option_values) {
$result->option_values = explode(',',$result->option_values);
}

}

return $results;

}

function get($id) {

$results = $this->db->get_where('products', array('id' => $id))->result();
$result = $results[0];

if ($result->option_values) {
$result->option_values = explode(',',$result->option_values);
}

return $result;
}

}

Any suggestion would be greatly appreciated.

Thx,

Jean


Messages In This Thread
A question about CI cart - by El Forum - 09-28-2010, 08:35 AM
A question about CI cart - by El Forum - 09-28-2010, 08:56 AM
A question about CI cart - by El Forum - 09-28-2010, 09:04 AM
A question about CI cart - by El Forum - 09-28-2010, 11:15 AM
A question about CI cart - by El Forum - 09-29-2010, 01:40 AM
A question about CI cart - by El Forum - 09-29-2010, 02:18 AM
A question about CI cart - by El Forum - 09-29-2010, 09:04 AM
A question about CI cart - by El Forum - 09-29-2010, 10:12 PM



Theme © iAndrew 2016 - Forum software by © MyBB