I am using codeigniter cart class
, when I insert new product to it, overrides existing products below I my code and output please guide me what's wrong with my code.
live test URL is
http://outlets.pk/outlets/items_controller/add_to_cart/12/2
http://outlets.pk/outlets/items_controller/add_to_cart/11/2
http://outlets.pk/outlets/items_controller/add_to_cart/id/qty
What I am doing: if we change id then items must be increase in cart.
its properly working on localhost but when I move it on Live hosting it behave unexpectedly.
Problem:
items_controller/add_to_cart URL is used to add item into cart but when I insert new item into cart and then try to access on other action it returns empty array.
SESSIONS are Not working on shared hosting server.
This is my functions:
public function add_to_cart($product_id,$qty){
$result=$this->items_model->get_items_id($product_id);
$cart_item=$this->items_model->is_exist($this->cart->contents(),$product_id);
if($cart_item!=NULL){
$this->cart->update(array(
'rowid'=> $cart_item['rowid'],
'qty'=> $cart_item['qty']+$qty,
));
}
else{
$this->cart->insert(array(
'id'=> $result[0]['product_id'],
'name'=> $result[0]['product_name'],
'qty'=> $qty,
'price'=>$result[0]['product_price'],
'product_sku'=>$result[0]['product_sku']
));
}
$this->randerCart();
}
Is_exist
function code:
public function is_exist($cart_content,$id){
foreach($cart_content as $c_i){
if($c_i['id']===$id){
return $c_i;
}
}
return NULL;
}
Thank you