From c40ee82d000bf5e57de605a900641cd4cd564378 Mon Sep 17 00:00:00 2001
From: Rock Zhang <iamgtskk@gmail.com>
Date: Thu, 14 Jan 2016 15:44:40 +0800
Subject: [PATCH] 修复默认不使用有货币功能导致的改变地址后一些状态不能保存的bug;当退出结算页面再次从购物车进入结算页面 时清除order-info的cookie值

Code Review By Rock Zhang
---
 static/js/cart/cart.js                                               | 8 ++++++++
 static/js/cart/good.js                                               | 2 +-
 static/js/cart/order-ensure.js                                       | 8 +-------
 static/js/cart/order-info.js                                         | 6 +++---
 yohobuy/m.yohobuy.com/application/models/Index/Cart.php              | 2 +-
 yohobuy/m.yohobuy.com/application/modules/Cart/controllers/Index.php | 2 +-
 6 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/static/js/cart/cart.js b/static/js/cart/cart.js
index ce7ba8c..91e6cf5 100644
--- a/static/js/cart/cart.js
+++ b/static/js/cart/cart.js
@@ -111,6 +111,10 @@ function showChooseGifDialog() {
     }, function() {
         window.location.href = cartContentShow().find('.freebie > a').attr('href');
     }, function() {
+        var info = window.cookie('order-info');
+        if (info) {
+            window.setCookie('order-info', '');
+        }
         window.location.href = '/cart/index/orderEnsure?cartType=' + cartType;
     });
 }
@@ -185,6 +189,7 @@ if ($('.freebie').length > 0) {
 }
 
 $('.btn-balance').on('touchend', function() {
+    var info = window.cookie('order-info');
     if (shouldLowStocks()) {
         tip.show('所选商品中含有库存不足的商品');
         return false;
@@ -196,6 +201,9 @@ $('.btn-balance').on('touchend', function() {
     }
 
     if (hasChecked()) {
+        if (info) {
+            window.setCookie('order-info', '');
+        }
         window.location.href = '/cart/index/orderEnsure?cartType=' + cartType;
     } else {
         tip.show('请先勾选商品');
diff --git a/static/js/cart/good.js b/static/js/cart/good.js
index a4a04cb..c49c886 100644
--- a/static/js/cart/good.js
+++ b/static/js/cart/good.js
@@ -105,7 +105,7 @@ $('.icon-del').on('touchstart', function(e) {
                     autoHide: true,
                     fast: true
                 });
-                window.setCookie('order-info', '');
+                //window.setCookie('order-info', '');
                 window.setCookie('_yoho-cart-refreshByDelete', true);
                 window.location.href = '/cart/index/index?cartType=' + $('#cartType').val();
             } else {
diff --git a/static/js/cart/order-ensure.js b/static/js/cart/order-ensure.js
index a2efd75..db25320 100644
--- a/static/js/cart/order-ensure.js
+++ b/static/js/cart/order-ensure.js
@@ -82,11 +82,8 @@ $('.invoice').on('touchend', '.checkbox', function() {
     }
 });
 
-function orderCompute(firstEnter) {
+function orderCompute() {
     var yohoCoin = orderInfo('yohoCoin');
-    if (firstEnter) {
-        yohoCoin = 0;
-    }
     $.ajax({
         method: 'POST',
         url: '/cart/index/orderCompute',
@@ -124,9 +121,6 @@ function orderCompute(firstEnter) {
     });
 }
 
-// 进入页面计算一次价格
-//orderCompute(1);
-
 function submitOrder() {
     var invoiceText = $invoice.find('[name="invoice-title"]').val() || orderInfo('invoiceText'),
         msg = $('#msg').find('input').val() || orderInfo('msg');
diff --git a/static/js/cart/order-info.js b/static/js/cart/order-info.js
index 1e10b81..dec1c82 100644
--- a/static/js/cart/order-info.js
+++ b/static/js/cart/order-info.js
@@ -14,7 +14,7 @@ function init() {
         deliveryId: $('.dispatch-mode .chosed').data('id') || 1,
         deliveryTimeId: 1,
         paymentTypeId: 1,
-        yohoCoin: $('.coin').data('yoho-coin') || 0,
+        yohoCoin: 0,
         addressId: null,
         couponCode: null,
         couponName: null,
@@ -30,9 +30,9 @@ function init() {
 // info 必须是 JSON 字符串
 try {
     info = JSON.parse(info);
-    
+
     // 2015/12/31 hf: fixes bug to 购物车页面调用该JS, 会导致有YOHO币,值却没有传给服务端. 因此需要再设置一下
-    info['yohoCoin'] = $('.coin').data('yoho-coin') || 0;
+    //info['yohoCoin'] = $('.coin').data('yoho-coin') || 0;
 } catch (e) {
     init();
 }
diff --git a/yohobuy/m.yohobuy.com/application/models/Index/Cart.php b/yohobuy/m.yohobuy.com/application/models/Index/Cart.php
index 1e55f19..27ca479 100644
--- a/yohobuy/m.yohobuy.com/application/models/Index/Cart.php
+++ b/yohobuy/m.yohobuy.com/application/models/Index/Cart.php
@@ -486,7 +486,7 @@ class CartModel
 
             // 优惠券数据
             $coupons = array('couponName' => '');
-            if (!empty($orderCompute['coupon_amount'])) {
+            if (isset($orderCompute['coupon_amount']) && (!empty($orderCompute['coupon_amount']) || ($orderCompute['coupon_amount'] === 0 && $orderCompute['shipping_cost'] === 0))) {
                 $coupons['couponName'] = $orderInfo['couponName'];
             }
             $result['coupon'] = $coupons;
diff --git a/yohobuy/m.yohobuy.com/application/modules/Cart/controllers/Index.php b/yohobuy/m.yohobuy.com/application/modules/Cart/controllers/Index.php
index 6f4abf8..4e3a727 100644
--- a/yohobuy/m.yohobuy.com/application/modules/Cart/controllers/Index.php
+++ b/yohobuy/m.yohobuy.com/application/modules/Cart/controllers/Index.php
@@ -285,7 +285,7 @@ class IndexController extends AbstractAction
         $cartType = $this->get('cartType', '');
         $cookieData = $this->getCookie('order-info', null);
         $orderInfo = array();
-        if (empty($cartType) && !empty($cookieData)) {
+        if (!empty($cookieData)) {
             $orderInfo = json_decode($cookieData, true);
             $cartType = $orderInfo['cartType'];
         }
--
libgit2 0.24.0