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\Product; |
26
|
|
|
|
27
|
|
|
use Doctrine\ORM\EntityManager; |
28
|
|
|
use Eccube\Annotation\Inject; |
29
|
|
|
use Eccube\Annotation\Component; |
30
|
|
|
use Eccube\Application; |
31
|
|
|
use Eccube\Controller\AbstractController; |
32
|
|
|
use Eccube\Event\EccubeEvents; |
33
|
|
|
use Eccube\Event\EventArgs; |
34
|
|
|
use Eccube\Form\Type\Admin\ClassCategoryType; |
35
|
|
|
use Eccube\Repository\ClassCategoryRepository; |
36
|
|
|
use Eccube\Repository\ClassNameRepository; |
37
|
|
|
use Eccube\Repository\ProductClassRepository; |
38
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
39
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
40
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
41
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
42
|
|
|
use Symfony\Component\Form\FormFactory; |
43
|
|
|
use Symfony\Component\HttpFoundation\Request; |
44
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @Component |
48
|
|
|
* @Route(service=ClassCategoryController::class) |
49
|
|
|
*/ |
50
|
|
|
class ClassCategoryController extends AbstractController |
51
|
|
|
{ |
52
|
|
|
/** |
53
|
|
|
* @Inject("orm.em") |
54
|
|
|
* @var EntityManager |
55
|
|
|
*/ |
56
|
|
|
protected $entityManager; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @Inject(ProductClassRepository::class) |
60
|
|
|
* @var ProductClassRepository |
61
|
|
|
*/ |
62
|
|
|
protected $productClassRepository; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @Inject("eccube.event.dispatcher") |
66
|
|
|
* @var EventDispatcher |
67
|
|
|
*/ |
68
|
|
|
protected $eventDispatcher; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @Inject("form.factory") |
72
|
|
|
* @var FormFactory |
73
|
|
|
*/ |
74
|
|
|
protected $formFactory; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @Inject(ClassCategoryRepository::class) |
78
|
|
|
* @var ClassCategoryRepository |
79
|
|
|
*/ |
80
|
|
|
protected $classCategoryRepository; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @Inject(ClassNameRepository::class) |
84
|
|
|
* @var ClassNameRepository |
85
|
|
|
*/ |
86
|
|
|
protected $classNameRepository; |
87
|
|
|
|
88
|
|
|
/** |
|
|
|
|
89
|
|
|
* @Route("/{_admin}/product/class_category/{class_name_id}", requirements={"class_name_id" = "\d+"}, name="admin_product_class_category") |
90
|
|
|
* @Route("/{_admin}/product/class_category/{class_name_id}/{id}/edit", requirements={"class_name_id" = "\d+", "id" = "\d+"}, name="admin_product_class_category_edit") |
91
|
|
|
* @Template("Product/class_category.twig") |
92
|
|
|
*/ |
|
|
|
|
93
|
2 |
|
public function index(Application $app, Request $request, $class_name_id, $id = null) |
94
|
|
|
{ |
95
|
|
|
// |
96
|
2 |
|
$ClassName = $this->classNameRepository->find($class_name_id); |
97
|
2 |
|
if (!$ClassName) { |
98
|
|
|
throw new NotFoundHttpException('商品規格が存在しません'); |
99
|
|
|
} |
100
|
2 |
|
if ($id) { |
101
|
1 |
|
$TargetClassCategory = $this->classCategoryRepository->find($id); |
102
|
1 |
|
if (!$TargetClassCategory || $TargetClassCategory->getClassName() != $ClassName) { |
103
|
1 |
|
throw new NotFoundHttpException('商品規格が存在しません'); |
104
|
|
|
} |
105
|
|
|
} else { |
106
|
1 |
|
$TargetClassCategory = new \Eccube\Entity\ClassCategory(); |
107
|
1 |
|
$TargetClassCategory->setClassName($ClassName); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
// |
111
|
2 |
|
$builder = $this->formFactory |
112
|
2 |
|
->createBuilder(ClassCategoryType::class, $TargetClassCategory); |
113
|
|
|
|
114
|
2 |
|
$event = new EventArgs( |
115
|
|
|
array( |
116
|
2 |
|
'builder' => $builder, |
117
|
2 |
|
'ClassName' => $ClassName, |
118
|
2 |
|
'TargetClassCategory' => $TargetClassCategory, |
119
|
|
|
), |
120
|
2 |
|
$request |
121
|
|
|
); |
122
|
2 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_PRODUCT_CLASS_CATEGORY_INDEX_INITIALIZE, $event); |
123
|
|
|
|
124
|
2 |
|
$form = $builder->getForm(); |
125
|
|
|
|
126
|
2 |
|
if ($request->getMethod() === 'POST') { |
127
|
|
|
$form->handleRequest($request); |
128
|
|
|
if ($form->isValid()) { |
129
|
|
|
log_info('規格分類登録開始', array($id)); |
130
|
|
|
|
131
|
|
|
$this->classCategoryRepository->save($TargetClassCategory); |
132
|
|
|
|
133
|
|
|
log_info('規格分類登録完了', array($id)); |
134
|
|
|
|
135
|
|
|
$event = new EventArgs( |
136
|
|
|
array( |
137
|
|
|
'form' => $form, |
138
|
|
|
'ClassName' => $ClassName, |
139
|
|
|
'TargetClassCategory' => $TargetClassCategory, |
140
|
|
|
), |
141
|
|
|
$request |
142
|
|
|
); |
143
|
|
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_PRODUCT_CLASS_CATEGORY_INDEX_COMPLETE, $event); |
144
|
|
|
|
145
|
|
|
$app->addSuccess('admin.class_category.save.complete', 'admin'); |
146
|
|
|
|
147
|
|
|
return $app->redirect($app->url('admin_product_class_category', array('class_name_id' => $ClassName->getId()))); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
151
|
2 |
|
$ClassCategories = $this->classCategoryRepository->getList($ClassName); |
152
|
|
|
|
153
|
|
|
return [ |
154
|
2 |
|
'form' => $form->createView(), |
155
|
2 |
|
'ClassName' => $ClassName, |
156
|
2 |
|
'ClassCategories' => $ClassCategories, |
157
|
2 |
|
'TargetClassCategory' => $TargetClassCategory, |
158
|
|
|
]; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
|
|
|
|
162
|
|
|
* @Method("DELETE") |
163
|
|
|
* @Route("/{_admin}/product/class_category/{class_name_id}/{id}/delete", requirements={"class_name_id" = "\d+", "id" = "\d+"}, name="admin_product_class_category_delete") |
164
|
|
|
*/ |
|
|
|
|
165
|
1 |
|
public function delete(Application $app, Request $request, $class_name_id, $id) |
166
|
|
|
{ |
167
|
1 |
|
$this->isTokenValid($app); |
168
|
|
|
|
169
|
1 |
|
$ClassName = $this->classNameRepository->find($class_name_id); |
170
|
1 |
|
if (!$ClassName) { |
171
|
|
|
throw new NotFoundHttpException('商品規格が存在しません'); |
172
|
|
|
} |
173
|
|
|
|
174
|
1 |
|
log_info('規格分類削除開始', array($id)); |
175
|
|
|
|
176
|
1 |
|
$TargetClassCategory = $this->classCategoryRepository->find($id); |
177
|
1 |
View Code Duplication |
if (!$TargetClassCategory || $TargetClassCategory->getClassName() != $ClassName) { |
178
|
|
|
$app->deleteMessage(); |
179
|
|
|
return $app->redirect($app->url('admin_product_class_category', array('class_name_id' => $ClassName->getId()))); |
|
|
|
|
180
|
|
|
} |
181
|
|
|
|
182
|
1 |
|
$num = $this->productClassRepository->createQueryBuilder('pc') |
183
|
1 |
|
->select('count(pc.id)') |
184
|
1 |
|
->where('pc.ClassCategory1 = :id OR pc.ClassCategory2 = :id') |
185
|
1 |
|
->setParameter('id',$id) |
|
|
|
|
186
|
1 |
|
->getQuery() |
187
|
1 |
|
->getSingleScalarResult(); |
188
|
1 |
|
if ($num > 0) { |
189
|
|
|
$app->addError('admin.class_category.delete.hasproduct', 'admin'); |
190
|
|
|
} else { |
191
|
|
|
try { |
192
|
1 |
|
$this->classCategoryRepository->delete($TargetClassCategory); |
193
|
|
|
|
194
|
1 |
|
$event = new EventArgs( |
195
|
|
|
array( |
196
|
1 |
|
'ClassName' => $ClassName, |
197
|
1 |
|
'TargetClassCategory' => $TargetClassCategory, |
198
|
|
|
), |
199
|
1 |
|
$request |
200
|
|
|
); |
201
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_PRODUCT_CLASS_CATEGORY_DELETE_COMPLETE, $event); |
202
|
|
|
|
203
|
1 |
|
$app->addSuccess('admin.class_category.delete.complete', 'admin'); |
204
|
|
|
|
205
|
1 |
|
log_info('規格分類削除完了', array($id)); |
206
|
|
|
|
|
|
|
|
207
|
|
|
} catch (\Exception $e) { |
208
|
|
|
log_error('規格分類削除エラー', array($id, $e)); |
209
|
|
|
|
210
|
|
|
$message = $app->trans('admin.delete.failed.foreign_key', ['%name%' => '規格分類']); |
211
|
|
|
$app->addError($message, 'admin'); } |
212
|
|
|
} |
213
|
|
|
|
214
|
1 |
|
return $app->redirect($app->url('admin_product_class_category', array('class_name_id' => $ClassName->getId()))); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
|
|
|
|
218
|
|
|
* @Method("PUT") |
219
|
|
|
* @Route("/{_admin}/product/class_category/{class_name_id}/{id}/visibility", requirements={"class_name_id" = "\d+", "id" = "\d+"}, name="admin_product_class_category_visibility") |
220
|
|
|
*/ |
|
|
|
|
221
|
1 |
|
public function visibility(Application $app, Request $request, $class_name_id, $id) |
222
|
|
|
{ |
223
|
1 |
|
$this->isTokenValid($app); |
224
|
|
|
|
225
|
1 |
|
$ClassName = $this->classNameRepository->find($class_name_id); |
226
|
1 |
|
if (!$ClassName) { |
227
|
|
|
throw new NotFoundHttpException('商品規格が存在しません'); |
228
|
|
|
} |
229
|
|
|
|
230
|
1 |
|
log_info('規格分類表示変更開始', array($id)); |
231
|
|
|
|
232
|
1 |
|
$TargetClassCategory = $this->classCategoryRepository->find($id); |
233
|
1 |
View Code Duplication |
if (!$TargetClassCategory || $TargetClassCategory->getClassName() != $ClassName) { |
234
|
|
|
$app->deleteMessage(); |
235
|
|
|
return $app->redirect($app->url('admin_product_class_category', array('class_name_id' => $ClassName->getId()))); |
|
|
|
|
236
|
|
|
} |
237
|
|
|
|
238
|
1 |
|
$this->classCategoryRepository->toggleVisibility($TargetClassCategory); |
239
|
|
|
|
240
|
1 |
|
log_info('規格分類表示変更完了', array($id)); |
241
|
|
|
|
242
|
1 |
|
$event = new EventArgs( |
243
|
|
|
array( |
244
|
1 |
|
'ClassName' => $ClassName, |
245
|
1 |
|
'TargetClassCategory' => $TargetClassCategory, |
246
|
|
|
), |
247
|
1 |
|
$request |
248
|
|
|
); |
249
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_PRODUCT_CLASS_CATEGORY_DELETE_COMPLETE, $event); |
250
|
|
|
|
251
|
1 |
|
$app->addSuccess('admin.class_category.delete.complete', 'admin'); |
252
|
|
|
|
253
|
1 |
|
return $app->redirect($app->url('admin_product_class_category', array('class_name_id' => $ClassName->getId()))); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
|
|
|
|
257
|
|
|
* @Method("POST") |
258
|
|
|
* @Route("/product/class_category/rank/move", name="admin_product_class_category_rank_move") |
259
|
|
|
*/ |
|
|
|
|
260
|
|
View Code Duplication |
public function moveRank(Application $app, Request $request) |
|
|
|
|
261
|
|
|
{ |
262
|
|
|
if ($request->isXmlHttpRequest()) { |
263
|
|
|
$ranks = $request->request->all(); |
264
|
|
|
foreach ($ranks as $categoryId => $rank) { |
265
|
|
|
$ClassCategory = $this->classCategoryRepository |
266
|
|
|
->find($categoryId); |
267
|
|
|
$ClassCategory->setRank($rank); |
268
|
|
|
$this->entityManager->persist($ClassCategory); |
|
|
|
|
269
|
|
|
} |
270
|
|
|
$this->entityManager->flush(); |
271
|
|
|
} |
272
|
|
|
return true; |
|
|
|
|
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
|