Showing
2 changed files
with
102 additions
and
99 deletions
@@ -9,100 +9,101 @@ use Plugin\Helpers; | @@ -9,100 +9,101 @@ use Plugin\Helpers; | ||
9 | */ | 9 | */ |
10 | class ShoppingCartController extends AbstractAction | 10 | class ShoppingCartController extends AbstractAction |
11 | { | 11 | { |
12 | - protected $_uid; | ||
13 | - | ||
14 | - /** | ||
15 | - * 初始化 | ||
16 | - */ | ||
17 | - public function init() | ||
18 | - { | ||
19 | - // 检查用户是否登录, 未登录则跳转到登录页 | ||
20 | - $this->_uid = $this->getUid(); | ||
21 | - if (!$this->_uid) { | ||
22 | - $this->go(Helpers::url('/signin.html')); | ||
23 | - } | ||
24 | - | ||
25 | - parent::init(); | ||
26 | - } | ||
27 | - | ||
28 | - /* | ||
29 | - * 首页 | ||
30 | - */ | 12 | + |
13 | + protected $_uid; | ||
14 | + | ||
15 | + /** | ||
16 | + * 通过当前用户审判是否跳到登录 | ||
17 | + * | ||
18 | + * @param int $useSession (true:从服务端session中检查, false:从客户端cookie中检查) | ||
19 | + * @return void | ||
20 | + */ | ||
21 | + protected function auditJumpLogin($useSession = true) | ||
22 | + { | ||
23 | + $uid = $this->getUid($useSession); | ||
24 | + if (!$uid) { | ||
25 | + $this->go(Helpers::url('/signin.html', array('refer' => $this->server('HTTP_REFERER', SITE_MAIN)))); | ||
26 | + } | ||
27 | + } | ||
28 | + | ||
29 | + /* | ||
30 | + * 首页 | ||
31 | + */ | ||
31 | public function indexAction() | 32 | public function indexAction() |
32 | { | 33 | { |
33 | - $this->setTitle('购物车'); | ||
34 | - $this->setNavHeader('购物车'); | 34 | + $this->setTitle('购物车'); |
35 | + $this->setNavHeader('购物车'); | ||
35 | 36 | ||
36 | $data = array( | 37 | $data = array( |
37 | - 'shoppingCartPage' => true, | ||
38 | - 'shoppingCart' => CartModel::getCartData($this->_uid) | 38 | + 'shoppingCartPage' => true, |
39 | + 'shoppingCart' => CartModel::getCartData($this->_uid) | ||
39 | ); | 40 | ); |
40 | 41 | ||
41 | // 渲染模板 | 42 | // 渲染模板 |
42 | $this->_view->display('index', $data); | 43 | $this->_view->display('index', $data); |
43 | } | 44 | } |
44 | 45 | ||
45 | - /** | ||
46 | - * 移出购物车 | ||
47 | - */ | ||
48 | - public function delAction() | ||
49 | - { | ||
50 | - $result = array(); | ||
51 | - | ||
52 | - if ($this->isAjax()) { | ||
53 | - $productId = $this->post('id', 0); | ||
54 | - $result = CartModel::removeFromCart($this->_uid, $productId); | ||
55 | - } | ||
56 | - | ||
57 | - if (empty($result)) { | ||
58 | - echo ' '; | ||
59 | - } else { | ||
60 | - $this->echoJson($result); | ||
61 | - } | ||
62 | - } | ||
63 | - | ||
64 | - /** | ||
65 | - * 移入收藏夹 | ||
66 | - */ | ||
67 | - public function colAction() | ||
68 | - { | ||
69 | - $result = array(); | ||
70 | - | ||
71 | - if ($this->isAjax()) { | ||
72 | - $productId = $this->post('id', 0); | ||
73 | - $result = CartModel::addToFav($this->_uid, $productId); | ||
74 | - } | ||
75 | - | ||
76 | - if (empty($result)) { | ||
77 | - echo ' '; | ||
78 | - } else { | ||
79 | - $this->echoJson($result); | ||
80 | - } | ||
81 | - } | ||
82 | - | ||
83 | - /** | ||
84 | - * 修改购物车商品数据 | ||
85 | - */ | ||
86 | - public function modifyAction() | ||
87 | - { | ||
88 | - $result = array(); | ||
89 | - | ||
90 | - if ($this->isAjax()) { | ||
91 | - | ||
92 | - $params = array(); | ||
93 | - $params['old_product_sku']= $this->post('old_product_sku', 0); | ||
94 | - $params['new_product_sku']= $this->post('new_product_sku', 0); | ||
95 | - $params['buy_number']= $this->post('buy_number', 0); | ||
96 | - $params['selected']= $this->post('selected', null); | ||
97 | - $result = CartModel::modifyCartProduct($this->_uid, $params); | ||
98 | - } | ||
99 | - | ||
100 | - if (empty($result)) { | ||
101 | - echo ' '; | ||
102 | - } else { | ||
103 | - $this->echoJson($result); | ||
104 | - } | ||
105 | - } | 46 | + /** |
47 | + * 移出购物车 | ||
48 | + */ | ||
49 | + public function delAction() | ||
50 | + { | ||
51 | + $result = array(); | ||
52 | + | ||
53 | + if ($this->isAjax()) { | ||
54 | + $productId = $this->post('id', 0); | ||
55 | + $result = CartModel::removeFromCart($this->_uid, $productId); | ||
56 | + } | ||
57 | + | ||
58 | + if (empty($result)) { | ||
59 | + echo ' '; | ||
60 | + } else { | ||
61 | + $this->echoJson($result); | ||
62 | + } | ||
63 | + } | ||
64 | + | ||
65 | + /** | ||
66 | + * 移入收藏夹 | ||
67 | + */ | ||
68 | + public function colAction() | ||
69 | + { | ||
70 | + $result = array(); | ||
71 | + | ||
72 | + if ($this->isAjax()) { | ||
73 | + $productId = $this->post('id', 0); | ||
74 | + $result = CartModel::addToFav($this->_uid, $productId); | ||
75 | + } | ||
76 | + | ||
77 | + if (empty($result)) { | ||
78 | + echo ' '; | ||
79 | + } else { | ||
80 | + $this->echoJson($result); | ||
81 | + } | ||
82 | + } | ||
83 | + | ||
84 | + /** | ||
85 | + * 修改购物车商品数据 | ||
86 | + */ | ||
87 | + public function modifyAction() | ||
88 | + { | ||
89 | + $result = array(); | ||
90 | + | ||
91 | + if ($this->isAjax()) { | ||
92 | + | ||
93 | + $params = array(); | ||
94 | + $params['old_product_sku'] = $this->post('old_product_sku', 0); | ||
95 | + $params['new_product_sku'] = $this->post('new_product_sku', 0); | ||
96 | + $params['buy_number'] = $this->post('buy_number', 0); | ||
97 | + $params['selected'] = $this->post('selected', null); | ||
98 | + $result = CartModel::modifyCartProduct($this->_uid, $params); | ||
99 | + } | ||
100 | + | ||
101 | + if (empty($result)) { | ||
102 | + echo ' '; | ||
103 | + } else { | ||
104 | + $this->echoJson($result); | ||
105 | + } | ||
106 | + } | ||
106 | 107 | ||
107 | public function giftAdvanceAction() | 108 | public function giftAdvanceAction() |
108 | { | 109 | { |
@@ -146,10 +147,11 @@ class ShoppingCartController extends AbstractAction | @@ -146,10 +147,11 @@ class ShoppingCartController extends AbstractAction | ||
146 | ); | 147 | ); |
147 | 148 | ||
148 | $this->_view->display('gift-advance', array('giftAdvancePage' => true, 'pageHeader' => array( | 149 | $this->_view->display('gift-advance', array('giftAdvancePage' => true, 'pageHeader' => array( |
149 | - 'navBack' => true, 'navTitle' => '加价购'), 'shoppingCart' => $data)); | 150 | + 'navBack' => true, 'navTitle' => '加价购'), 'shoppingCart' => $data)); |
150 | } | 151 | } |
151 | 152 | ||
152 | - public function orderEnsureAction() { | 153 | + public function orderEnsureAction() |
154 | + { | ||
153 | $data = array( | 155 | $data = array( |
154 | 'orderEnsurePage' => true, | 156 | 'orderEnsurePage' => true, |
155 | 'orderEnsure' => array( | 157 | 'orderEnsure' => array( |
@@ -216,13 +218,13 @@ class ShoppingCartController extends AbstractAction | @@ -216,13 +218,13 @@ class ShoppingCartController extends AbstractAction | ||
216 | 218 | ||
217 | $this->_view->display('order-ensure', $data); | 219 | $this->_view->display('order-ensure', $data); |
218 | } | 220 | } |
219 | - | 221 | + |
220 | /** | 222 | /** |
221 | * 读取chose-panel内容 | 223 | * 读取chose-panel内容 |
222 | */ | 224 | */ |
223 | public function tplAction() | 225 | public function tplAction() |
224 | { | 226 | { |
225 | - if($this->isAjax()) { | 227 | + if ($this->isAjax()) { |
226 | $data = file_get_contents('../../../template/m.yohobuy.com/partials/shopping-cart/chose-panel.phtml'); | 228 | $data = file_get_contents('../../../template/m.yohobuy.com/partials/shopping-cart/chose-panel.phtml'); |
227 | 229 | ||
228 | echo($data); | 230 | echo($data); |
@@ -231,19 +233,20 @@ class ShoppingCartController extends AbstractAction | @@ -231,19 +233,20 @@ class ShoppingCartController extends AbstractAction | ||
231 | 233 | ||
232 | public function goodinfoAction() | 234 | public function goodinfoAction() |
233 | { | 235 | { |
234 | - $result = array(); | 236 | + $result = array(); |
235 | 237 | ||
236 | if ($this->isAjax()) { | 238 | if ($this->isAjax()) { |
237 | - $num = $this->get('buy_num', 1); | ||
238 | - $skn = $this->get('id', 1); | ||
239 | - $result = CartModel::cartProductData($this->_uid, $skn, $num); // 测试skn的ID为51172055 | ||
240 | - $result['num'] = $num; | 239 | + $num = $this->get('buy_num', 1); |
240 | + $skn = $this->get('id', 1); | ||
241 | + $result = CartModel::cartProductData($this->_uid, $skn, $num); // 测试skn的ID为51172055 | ||
242 | + $result['num'] = $num; | ||
241 | } | 243 | } |
242 | 244 | ||
243 | - if (empty($result)) { | ||
244 | - echo ' '; | ||
245 | - } else { | ||
246 | - $this->echoJson($result); | ||
247 | - } | 245 | + if (empty($result)) { |
246 | + echo ' '; | ||
247 | + } else { | ||
248 | + $this->echoJson($result); | ||
249 | + } | ||
248 | } | 250 | } |
251 | + | ||
249 | } | 252 | } |
-
Please register or login to post a comment