问题描述:

The problem i have with class, is strange. I can not add new product with same name like

SHIRT

If i add new SHIRT to cart, class check te name and just update quantity.

The problem is what if i have same shirt but with different color??

It only update and change quanity and change color that is already in cart?

How to disable to check name and add new product with same name?

This is what i have for update

$qty=$_POST['productquantity'];

$data = array(

'id' => $proizvodid,

'qty' => $qty,

'price' => $cena,

'name' => $nazivproizvoda

);

if (count($this->cart->contents())>0)

{

foreach ($this->cart->contents() as $item)

{

if ($item['id']==$proizvodid)

{

$data = array('rowid'=>$item['rowid'],

'qty' => $item['qty']+$qty);

$this->cart->update($data);

}

else

{

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

}

}

}

else

{

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

}

redirect($page);

}

网友答案:

You can use option in your cart.

$data = array(
              'id'      => $proizvodid,
              'qty'     => $qty,
              'price'   => $cena,
              'name'    => $nazivproizvoda
              'options' => array('Color' => 'Red')
            );

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

Look here the explanation http://ellislab.com/codeigniter%20/user-guide/libraries/cart.html

网友答案:

You are checking with the id like this:

if ($item['id']==$proizvodid)
{
$data = array('rowid'=>$item['rowid'],
'qty' => $item['qty']+$qty);
$this->cart->update($data);
}

And only updating the quantity.

相关阅读:
Top