[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