Authored by hf

code review by hf: do modify cart list add cartType parameter

... ... @@ -191,7 +191,7 @@ class SaeTOAuthV2 {
$params['username'] = $keys['username'];
$params['password'] = $keys['password'];
} else {
throw new OAuthException("wrong auth type");
throw new \OAuthException("wrong auth type");
}
$response = $this->oAuthRequest($this->accessTokenURL(), 'POST', $params);
... ... @@ -200,7 +200,7 @@ class SaeTOAuthV2 {
$this->access_token = $token['access_token'];
//$this->refresh_token = $token['refresh_token'];
} else {
throw new OAuthException("get access token failed." . $token['error']);
throw new \OAuthException("get access token failed." . $token['error']);
}
return $token;
}
... ...
... ... @@ -52,7 +52,7 @@ class CartModel
*/
public static function getCartData($uid, $shoppingKey, $cartType = 'all', $onlyGift = false, $onlyAdvanceBuy = false)
{
$result = array('cartNav' => true, 'commonGoodsCount' => '0', 'presellGoodsCount' => '0');
$result = array('cartNav' => false, 'commonGoodsCount' => '0', 'presellGoodsCount' => '0');
// 用户是否登录
if (empty($uid)) {
... ... @@ -65,15 +65,13 @@ class CartModel
// 处理普通购物车和预售购物车的数据
do {
if (!isset($cartData['data']) || empty($cartData['data'])) {
// $result['isEmptyCart'] = true;
if (empty($cartData['data'])) {
$result['isEmptyCart'] = true;
break;
}
$cart = $cartData['data'];
$result['cartNav'] = true;
if ($cartType !== 'all') { // 加价购或者赠品数据
$result = self::procCartData($cart['ordinary_cart_data'], $onlyGift, $onlyAdvanceBuy);
break;
... ... @@ -86,15 +84,32 @@ class CartModel
$result['isEmptyCart'] = true;
break;
}
if ($ordinaryCount === '0' || $advanceCount === '0') {
// 普通购物车空,则显示预售购物车
if ($ordinaryCount === '0') {
$result['cartNav'] = false;
$result['cartType'] = 'advance';
}
// 预售购物车空,则显示普通购物车
elseif ($advanceCount === '0') {
$result['cartNav'] = false;
$result['cartType'] = 'ordinary';
}
// 以上两个购物车中都有数据, 默认显示普通购物车
else {
$result['cartNav'] = true;
$result['cartType'] = 'ordinary';
}
/* 普通购物车 */
$result['commonGoodsCount'] = $ordinaryCount;
$result['commonCart'] = self::procCartData($cart['ordinary_cart_data'], $onlyGift, $onlyAdvanceBuy);
/* 预售购物车 */
$result['presellGoodsCount'] = $advanceCount;
$result['preSellCart'] = self::procCartData($cart['advance_cart_data'], $onlyGift, $onlyAdvanceBuy);
} while(false);
return $result;
... ...