Qua*_*nt6 3 shopping-cart codeigniter
使用CI 2.1.1和本机Cart库
如果我不止一次插入一个项目(具有相同的产品ID,相同的选项),它将替换而不是增加数量.
这可能是一个错误,我错过了什么,或者自己添加此功能的最佳方法是什么?
所以这是我的解决方案,更改为系统/库/ Cart.php在线号.233至244
可能有更好的方法来做到这一点,但它可以做到这一点.我不明白为什么功能不存在
// EDIT: added check if idential rowid/item already in cart, then just increase qty
// without this addition, it would not increase qty but simply replace the item
if (array_key_exists($rowid, $this->_cart_contents))
{
$this->_cart_contents[$rowid]['qty'] += $items['qty'];
}
else
{
// let's unset this first, just to make sure our index contains only the data from this submission
unset($this->_cart_contents[$rowid]);
// Create a new index with our new row ID
$this->_cart_contents[$rowid]['rowid'] = $rowid;
// And add the new items to the cart array
foreach ($items as $key => $val)
{
$this->_cart_contents[$rowid][$key] = $val;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2620 次 |
| 最近记录: |