CodeIgniter Cart Extend for insert to add
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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