[eluser]LeMec[/eluser]
Hello all,
I have to modify a functionality of an existing product build using Codeigniter.
The system adds items to a list of Items until the transaction is completed.
As it is now, the system looks if the item already exists and adds one to the quantity.
It does not add a new item to the list if it is already there.
I want to change that so that it adds the item to the list even if it already exists.
Here is the relevant portion of code:
function add_item($item_id,$quantity=1,$discount=0,$price=null,$tax=null)
{
//make sure item exists
if(!$this->CI->Item->exists($item_id))
{
//try to get item id given an item_number
$item_id = $this->CI->Item->get_item_id($item_id);
if(!$item_id)
return false;
}
$items = $this->get_cart();
$item = array($item_id=>
array(
'name'=>$this->CI->Item->get_info($item_id)->name,
'quantity'=>$quantity,
'discount'=>$discount,
'price'=>$price!=null ? $price: $this->CI->Item->get_info($item_id)->unit_price
)
);
//Item already exists, add to quantity
if(isset($items[$item_id]))
{
$items[$item_id]['quantity']+=$quantity;
}
else
{
//add to existing array
$items+=$item;
}
$this->set_cart($items);
return true;
}
I tried to modify the condition and simply execute the:
$items+=$item;
statement unconditionaly, but it does not work.
Here is the Get_Cart Set_Cart routines.
function get_cart()
{
if(!$this->CI->session->userdata('cart'))
$this->set_cart(array());
return $this->CI->session->userdata('cart');
}
function set_cart($cart_data)
{
$this->CI->session->set_userdata('cart',$cart_data);
}
I am a newbee. Please let me know if you need more information.
Many thanks.