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\Admin\Setting\Shop; |
26
|
|
|
|
27
|
|
|
use Eccube\Application; |
28
|
|
|
use Eccube\Common\Constant; |
29
|
|
|
use Eccube\Controller\AbstractController; |
30
|
|
|
use Eccube\Event\EccubeEvents; |
31
|
|
|
use Eccube\Event\EventArgs; |
32
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
33
|
|
|
use Symfony\Component\HttpFoundation\Request; |
34
|
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
35
|
|
|
use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException; |
36
|
|
|
|
37
|
|
|
class PaymentController extends AbstractController |
|
|
|
|
38
|
|
|
{ |
39
|
|
View Code Duplication |
public function index(Application $app, Request $request) |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
$Payments = $app['eccube.repository.payment'] |
42
|
|
|
->findBy( |
43
|
|
|
array('del_flg' => 0), |
44
|
|
|
array('rank' => 'DESC') |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
$event = new EventArgs( |
48
|
|
|
array( |
49
|
|
|
'Payments' => $Payments, |
50
|
|
|
), |
51
|
|
|
$request |
52
|
|
|
); |
53
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SHOP_PAYMENT_INDEX_COMPLETE, $event); |
54
|
|
|
|
55
|
|
|
return $app->render('Setting/Shop/payment.twig', array( |
56
|
|
|
'Payments' => $Payments, |
57
|
|
|
)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function edit(Application $app, Request $request, $id = null) |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
$Payment = $app['eccube.repository.payment'] |
63
|
|
|
->findOrCreate($id); |
64
|
|
|
|
65
|
|
|
$builder = $app['form.factory'] |
66
|
|
|
->createBuilder('payment_register'); |
67
|
|
|
|
68
|
|
|
$event = new EventArgs( |
69
|
|
|
array( |
70
|
|
|
'builder' => $builder, |
71
|
|
|
'Payment' => $Payment, |
72
|
|
|
), |
73
|
|
|
$request |
74
|
|
|
); |
75
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SHOP_PAYMENT_EDIT_INITIALIZE, $event); |
76
|
|
|
|
77
|
|
|
$form = $builder->getForm(); |
78
|
|
|
|
79
|
|
|
$form->setData($Payment); |
80
|
|
|
|
81
|
|
|
// 登録ボタン押下 |
82
|
|
|
if ('POST' === $app['request']->getMethod()) { |
83
|
|
|
$form->handleRequest($app['request']); |
84
|
|
|
|
85
|
|
|
if ($form->isValid()) { |
86
|
|
|
$PaymentData = $form->getData(); |
87
|
|
|
|
88
|
|
|
// 手数料を設定できない場合には、手数料を0にする |
89
|
|
|
if ($PaymentData->getChargeFlg() == 2) { |
90
|
|
|
$PaymentData->setCharge(0); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
// ファイルアップロード |
94
|
|
|
$file = $form['payment_image']->getData(); |
95
|
|
|
$fs = new Filesystem(); |
96
|
|
|
if ($file && $fs->exists($app['config']['image_temp_realdir'] . '/' . $file)) { |
|
|
|
|
97
|
|
|
$fs->rename( |
98
|
|
|
$app['config']['image_temp_realdir'] . '/' . $file, |
|
|
|
|
99
|
|
|
$app['config']['image_save_realdir'] . '/' . $file |
|
|
|
|
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$app['orm.em']->persist($PaymentData); |
104
|
|
|
|
105
|
|
|
$app['orm.em']->flush(); |
106
|
|
|
|
107
|
|
|
$event = new EventArgs( |
108
|
|
|
array( |
109
|
|
|
'form' => $form, |
110
|
|
|
'Payment' => $Payment, |
111
|
|
|
), |
112
|
|
|
$request |
113
|
|
|
); |
114
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SHOP_PAYMENT_EDIT_COMPLETE, $event); |
115
|
|
|
|
116
|
|
|
$app->addSuccess('admin.register.complete', 'admin'); |
117
|
|
|
|
118
|
|
|
return $app->redirect($app->url('admin_setting_shop_payment')); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
return $app->render('Setting/Shop/payment_edit.twig', array( |
123
|
|
|
'form' => $form->createView(), |
124
|
|
|
'payment_id' => $id, |
125
|
|
|
'Payment' => $Payment, |
126
|
|
|
)); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function imageAdd(Application $app, Request $request) |
|
|
|
|
130
|
|
|
{ |
131
|
|
|
if (!$request->isXmlHttpRequest()) { |
132
|
|
|
throw new BadRequestHttpException(); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
$images = $request->files->get('payment_register'); |
136
|
|
|
$filename = null; |
137
|
|
|
if (isset($images['payment_image_file'])) { |
138
|
|
|
$image = $images['payment_image_file']; |
139
|
|
|
|
140
|
|
|
//ファイルフォーマット検証 |
141
|
|
|
$mimeType = $image->getMimeType(); |
142
|
|
|
if (0 !== strpos($mimeType, 'image')) { |
143
|
|
|
throw new UnsupportedMediaTypeHttpException(); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
$extension = $image->guessExtension(); |
147
|
|
|
$filename = date('mdHis') . uniqid('_') . '.' . $extension; |
|
|
|
|
148
|
|
|
$image->move($app['config']['image_temp_realdir'], $filename); |
149
|
|
|
} |
150
|
|
|
$event = new EventArgs( |
151
|
|
|
array( |
152
|
|
|
'images' => $images, |
153
|
|
|
'filename' => $filename, |
154
|
|
|
), |
155
|
|
|
$request |
156
|
|
|
); |
157
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SHOP_PAYMENT_IMAGE_ADD_COMPLETE, $event); |
158
|
|
|
$filename = $event->getArgument('filename'); |
159
|
|
|
|
160
|
|
|
return $app->json(array('filename' => $filename), 200); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function delete(Application $app, Request $request, $id) |
|
|
|
|
164
|
|
|
{ |
165
|
|
|
$this->isTokenValid($app); |
166
|
|
|
|
167
|
|
|
$Payment = $app['eccube.repository.payment']->find($id); |
168
|
|
|
if (!$Payment) { |
169
|
|
|
$app->deleteMessage(); |
170
|
|
|
return $app->redirect($app->url('admin_setting_shop_payment')); |
|
|
|
|
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
$Payment |
174
|
|
|
->setDelFlg(Constant::ENABLED) |
175
|
|
|
->setRank(0); |
176
|
|
|
$app['orm.em']->persist($Payment); |
177
|
|
|
|
178
|
|
|
$rank = 1; |
179
|
|
|
$Payments = $app['eccube.repository.payment']->findBy(array('del_flg' => Constant::DISABLED), array('rank' => 'ASC')); |
180
|
|
|
foreach ($Payments as $Payment) { |
181
|
|
|
if ($Payment->getId() != $id) { |
182
|
|
|
$Payment->setRank($rank); |
183
|
|
|
$rank ++; |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
$app['orm.em']->flush(); |
188
|
|
|
|
189
|
|
|
$event = new EventArgs( |
190
|
|
|
array( |
191
|
|
|
'Payment' => $Payment, |
192
|
|
|
), |
193
|
|
|
$request |
194
|
|
|
); |
195
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SHOP_PAYMENT_DELETE_COMPLETE, $event); |
196
|
|
|
|
197
|
|
|
$app->addSuccess('admin.delete.complete', 'admin') ; |
198
|
|
|
|
199
|
|
|
return $app->redirect($app->url('admin_setting_shop_payment')); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
View Code Duplication |
public function up(Application $app, $id) |
|
|
|
|
203
|
|
|
{ |
204
|
|
|
$this->isTokenValid($app); |
205
|
|
|
|
206
|
|
|
$repo = $app['orm.em']->getRepository('Eccube\Entity\Payment'); |
207
|
|
|
|
208
|
|
|
$current = $repo->find($id); |
209
|
|
|
$currentRank = $current->getRank(); |
210
|
|
|
|
211
|
|
|
$targetRank = $currentRank + 1; |
212
|
|
|
$target = $repo->findOneBy(array('rank' => $targetRank)); |
213
|
|
|
|
214
|
|
|
$app['orm.em']->persist($target->setRank($currentRank)); |
215
|
|
|
$app['orm.em']->persist($current->setRank($targetRank)); |
216
|
|
|
$app['orm.em']->flush(); |
217
|
|
|
|
218
|
|
|
$app->addSuccess('admin.rank.move.complete', 'admin'); |
219
|
|
|
|
220
|
|
|
return $app->redirect($app->url('admin_setting_shop_payment')); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
View Code Duplication |
public function down(Application $app, $id) |
|
|
|
|
224
|
|
|
{ |
225
|
|
|
$this->isTokenValid($app); |
226
|
|
|
|
227
|
|
|
$repo = $app['orm.em']->getRepository('Eccube\Entity\Payment'); |
228
|
|
|
|
229
|
|
|
$current = $repo->find($id); |
230
|
|
|
$currentRank = $current->getRank(); |
231
|
|
|
|
232
|
|
|
$targetRank = $currentRank - 1; |
233
|
|
|
$target = $repo->findOneBy(array('rank' => $targetRank)); |
234
|
|
|
|
235
|
|
|
$app['orm.em']->persist($target->setRank($currentRank)); |
236
|
|
|
$app['orm.em']->persist($current->setRank($targetRank)); |
237
|
|
|
$app['orm.em']->flush(); |
238
|
|
|
|
239
|
|
|
$app->addSuccess('admin.rank.move.complete', 'admin'); |
240
|
|
|
|
241
|
|
|
return $app->redirect($app->url('admin_setting_shop_payment')); |
242
|
|
|
} |
243
|
|
|
} |
244
|
|
|
|