1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of EC-CUBE |
4
|
|
|
* |
5
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
6
|
|
|
* |
7
|
|
|
* http://www.lockon.co.jp/ |
8
|
|
|
* |
9
|
|
|
* This program is free software; you can redistribute it and/or |
10
|
|
|
* modify it under the terms of the GNU General Public License |
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
12
|
|
|
* of the License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU General Public License |
20
|
|
|
* along with this program; if not, write to the Free Software |
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
namespace Eccube\Controller; |
26
|
|
|
|
27
|
|
|
use Eccube\Application; |
28
|
|
|
use Eccube\Exception\CartException; |
29
|
|
|
use Symfony\Component\HttpFoundation\Request; |
30
|
|
|
|
31
|
|
|
class CartController extends AbstractController |
|
|
|
|
32
|
|
|
{ |
33
|
1 |
|
public function index(Application $app) |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
$Cart = $app['eccube.service.cart']->getCart(); |
36
|
|
|
|
37
|
|
|
/* @var $BaseInfo \Eccube\Entity\BaseInfo */ |
38
|
|
|
/* @var $Cart \Eccube\Entity\Cart */ |
39
|
|
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
40
|
|
|
|
41
|
1 |
|
$isDeliveryFree = false; |
42
|
1 |
|
$least = 0; |
43
|
1 |
|
$quantity = 0; |
44
|
|
|
if ($BaseInfo->getDeliveryFreeAmount()) { |
45
|
|
|
if ($BaseInfo->getDeliveryFreeAmount() <= $Cart->getTotalPrice()) { |
46
|
|
|
// 送料無料(金額)を超えている |
47
|
|
|
$isDeliveryFree = true; |
48
|
|
|
} else { |
49
|
|
|
$least = $BaseInfo->getDeliveryFreeAmount() - $Cart->getTotalPrice(); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if ($BaseInfo->getDeliveryFreeQuantity()) { |
54
|
|
|
if ($BaseInfo->getDeliveryFreeQuantity() <= $Cart->getTotalQuantity()) { |
55
|
|
|
// 送料無料(個数)を超えている |
56
|
|
|
$isDeliveryFree = true; |
57
|
|
|
} else { |
58
|
|
|
$quantity = $BaseInfo->getDeliveryFreeQuantity() - $Cart->getTotalQuantity(); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $app->render( |
63
|
1 |
|
'Cart/index.twig', |
64
|
|
|
array( |
65
|
|
|
'Cart' => $Cart, |
66
|
|
|
'least' => $least, |
67
|
|
|
'quantity' => $quantity, |
68
|
|
|
'is_delivery_free' => $isDeliveryFree, |
69
|
1 |
|
) |
70
|
|
|
); |
71
|
1 |
|
} |
72
|
|
|
|
73
|
21 |
|
public function add(Application $app, Request $request) |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
$productClassId = $request->get('product_class_id'); |
76
|
|
|
$quantity = $request->request->has('quantity') ? $request->get('quantity') : 1; |
77
|
|
|
try { |
78
|
|
|
$app['eccube.service.cart']->addProduct($productClassId, $quantity)->save(); |
79
|
|
|
} catch (CartException $e) { |
80
|
|
|
$app->addRequestError($e->getMessage()); |
81
|
21 |
|
} |
82
|
|
|
|
83
|
|
|
return $app->redirect($app->url('cart')); |
84
|
21 |
|
} |
85
|
|
|
|
86
|
1 |
View Code Duplication |
public function up(Application $app, $productClassId) |
|
|
|
|
87
|
|
|
{ |
88
|
|
|
$this->isTokenValid($app); |
89
|
|
|
|
90
|
|
|
try { |
91
|
|
|
$app['eccube.service.cart']->upProductQuantity($productClassId)->save(); |
92
|
|
|
} catch (CartException $e) { |
93
|
|
|
$app->addRequestError($e->getMessage()); |
94
|
1 |
|
} |
95
|
|
|
|
96
|
|
|
return $app->redirect($app->url('cart')); |
97
|
1 |
|
} |
98
|
|
|
|
99
|
1 |
View Code Duplication |
public function down(Application $app, $productClassId) |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
$this->isTokenValid($app); |
102
|
|
|
|
103
|
|
|
try { |
104
|
|
|
$app['eccube.service.cart']->downProductQuantity($productClassId)->save(); |
105
|
|
|
} catch (CartException $e) { |
106
|
|
|
$app->addRequestError($e->getMessage()); |
107
|
1 |
|
} |
108
|
|
|
|
109
|
|
|
return $app->redirect($app->url('cart')); |
110
|
1 |
|
} |
111
|
|
|
|
112
|
1 |
|
public function remove(Application $app, $productClassId) |
|
|
|
|
113
|
|
|
{ |
114
|
|
|
$this->isTokenValid($app); |
115
|
|
|
|
116
|
|
|
$app['eccube.service.cart']->removeProduct($productClassId)->save(); |
117
|
|
|
|
118
|
|
|
return $app->redirect($app->url('cart')); |
119
|
1 |
|
} |
120
|
|
|
|
121
|
1 |
|
public function setQuantity(Application $app, $productClassId, $quantity) |
|
|
|
|
122
|
|
|
{ |
123
|
|
|
$this->isTokenValid($app); |
124
|
|
|
|
125
|
|
|
$app['eccube.service.cart']->setProductQuantity($productClassId, $quantity)->save(); |
126
|
|
|
|
127
|
|
|
return $app->redirect($app->url('cart')); |
128
|
1 |
|
} |
129
|
|
|
|
130
|
|
|
public function buystep(Application $app) |
|
|
|
|
131
|
|
|
{ |
132
|
|
|
$app['eccube.service.cart']->lock(); |
133
|
|
|
$app['eccube.service.cart']->save(); |
134
|
|
|
|
135
|
|
|
return $app->redirect($app->url('shopping')); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|