Authored by Rock Zhang

修复删除商品时只能删除一个的bug

... ... @@ -148,12 +148,14 @@ $('.cart-goods').on('touchstart', '.checkbox', function() {
}
}, function() {
var id = $this.closest('.shopping-cart-good').data('id');
var count = $this.data('count');
$.ajax({
method: 'post',
url: '/cart/index/del',
data: {
id: id
sku: id,
count: count
}
}).then(function(data) {
if (data.code === 200) {
... ...
... ... @@ -52,7 +52,7 @@
<span class="iconfont icon-del">&#xe621;</span>
<span class="iconfont icon-del" data-count="{{count}}">&#xe621;</span>
</p>
<p class="row">
{{#if lowStocks}}
... ...
... ... @@ -127,16 +127,17 @@ class CartModel
* 移出购物车
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @param string $sku 商品sku
* @param string $count 要删除的数目
* @param string $shoppingKey 未登录用户唯一识别码
* @return array 接口返回的数据
*/
public static function removeFromCart($uid, $sku, $shoppingKey)
public static function removeFromCart($uid, $sku, $count, $shoppingKey)
{
$result = array('code' => 400, 'message' => '出错啦~');
// 处理sku
$sku_list = json_encode(array($sku => 1));
$sku_list = json_encode(array($sku => $count));
$remove = CartData::removeFromCart($uid, $sku_list, $shoppingKey);
if ($remove && isset($remove['code'])) {
... ...
... ... @@ -80,7 +80,7 @@ class IndexController extends AbstractAction
if ($this->isAjax()) {
$productId = $this->post('id', 0);
$uid = $this->getUid(true);
$shoppingKey = $this->getSession('shoppingKey');
$shoppingKey = Helpers::getShoppingKeyByCookie();
$result = CartModel::selectGoods($uid, $productId, $shoppingKey);
}
... ... @@ -99,10 +99,11 @@ class IndexController extends AbstractAction
$result = array();
if ($this->isAjax()) {
$productId = $this->post('id', 0);
$sku = $this->post('sku', 0);
$count = $this->post('count', 0);
$uid = $this->getUid(true);
$shoppingKey = $this->getSession('shoppingKey');
$result = CartModel::removeFromCart($uid, $productId, $shoppingKey);
$shoppingKey = Helpers::getShoppingKeyByCookie();
$result = CartModel::removeFromCart($uid, $sku, $count, $shoppingKey);
}
if (empty($result)) {
... ...