I am currently developing an ecommerce system and I am already in the part of ordering module. I am using the shopping cart of Codeigniter and it is my first to do it.
Done in a part of add to cart but having problem in remove single item in cart session. When I clicked the Remove, everything in my cart will be remove.
Question: How can I remove a single item in my cart?
View
<?php foreach ($this->cart->contents() as $items): ?>
<tr>
<td><?= $items['name']?></td>
<td><?= $items['qty']?></td>
<td style="text-align:center"><span>₱<?= $this->cart->format_number($items['price'])?></span></td>
<td style="text-align:center"><span>₱<?= $items['subtotal']?></span></td>
<td><a href="<?= base_url().'user/remove_cart'?>"><button class="btn btn-primary btn-sm"><i class="fa fa-times" aria-hidden="true"><?= $this->cart->remove($items['rowid'])?>REMOVE</i></button></a></td>
</tr>
<?php endforeach; ?>
Controller
public function remove_cart($rowid)
{
$removed_cart = array(
'rowid' => $rowid,
'qty' => 0
);
$this->cart->update($removed_cart);
}
}