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