Skip to content

Instantly share code, notes, and snippets.

@iann0036
Created March 23, 2015 14:27
Show Gist options
  • Save iann0036/04b1abb988ccd8adf7c2 to your computer and use it in GitHub Desktop.
Save iann0036/04b1abb988ccd8adf7c2 to your computer and use it in GitHub Desktop.
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