Skip to content

Instantly share code, notes, and snippets.

@iann0036
Created Mar 23, 2015
Embed
What would you like to do?
CodeIgniter Cart Extend for insert to add
class MY_Cart extends CI_Cart {
private function _is_identical($a, $b) {
sort($a);
sort($b);
return $a == $b;
}
public function insert($data) {
foreach ($this->contents() as $item) {
if ($item['id']==$data['id'] && $this->_is_identical($item['options'],$data['options'])) {
$update_data = array(
'rowid' => $item['rowid'],
'qty' => ($item['qty']+1)
);
$this->update($update_data);
return $item['rowid'];
}
}
return parent::insert($data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment