|
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\Entity\ClassName; |
|
32
|
|
|
use Eccube\Event\EccubeEvents; |
|
33
|
|
|
use Eccube\Event\EventArgs; |
|
34
|
|
|
use Eccube\Form\Type\Admin\ClassNameType; |
|
35
|
|
|
use Eccube\Repository\ClassNameRepository; |
|
36
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
37
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
38
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
|
39
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
|
40
|
|
|
use Symfony\Component\Form\FormFactory; |
|
41
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
42
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @Route(service=ClassNameController::class) |
|
46
|
|
|
*/ |
|
47
|
|
|
class ClassNameController extends AbstractController |
|
48
|
|
|
{ |
|
49
|
|
|
/** |
|
50
|
|
|
* @Inject("orm.em") |
|
51
|
|
|
* @var EntityManager |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $entityManager; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @Inject("eccube.event.dispatcher") |
|
57
|
|
|
* @var EventDispatcher |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $eventDispatcher; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @Inject("form.factory") |
|
63
|
|
|
* @var FormFactory |
|
64
|
|
|
*/ |
|
65
|
|
|
protected $formFactory; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @Inject(ClassNameRepository::class) |
|
69
|
|
|
* @var ClassNameRepository |
|
70
|
|
|
*/ |
|
71
|
|
|
protected $classNameRepository; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
|
|
|
|
|
74
|
|
|
* @Route("/{_admin}/product/class_name", name="admin_product_class_name") |
|
75
|
|
|
* @Route("/{_admin}/product/class_name/{id}/edit", requirements={"id" = "\d+"}, name="admin_product_class_name_edit") |
|
76
|
|
|
* @Template("Product/class_name.twig") |
|
77
|
|
|
*/ |
|
|
|
|
|
|
78
|
3 |
|
public function index(Application $app, Request $request, $id = null) |
|
79
|
|
|
{ |
|
80
|
3 |
|
if ($id) { |
|
81
|
1 |
|
$TargetClassName = $this->classNameRepository->find($id); |
|
82
|
1 |
|
if (!$TargetClassName) { |
|
83
|
1 |
|
throw new NotFoundHttpException('商品規格が存在しません'); |
|
84
|
|
|
} |
|
85
|
|
|
} else { |
|
86
|
2 |
|
$TargetClassName = new \Eccube\Entity\ClassName(); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
3 |
|
$builder = $this->formFactory |
|
90
|
3 |
|
->createBuilder(ClassNameType::class, $TargetClassName); |
|
91
|
|
|
|
|
92
|
3 |
|
$event = new EventArgs( |
|
93
|
|
|
array( |
|
94
|
3 |
|
'builder' => $builder, |
|
95
|
3 |
|
'TargetClassName' => $TargetClassName, |
|
96
|
|
|
), |
|
97
|
3 |
|
$request |
|
98
|
|
|
); |
|
99
|
3 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_PRODUCT_CLASS_NAME_INDEX_INITIALIZE, $event); |
|
100
|
|
|
|
|
101
|
3 |
|
$form = $builder->getForm(); |
|
102
|
|
|
|
|
103
|
3 |
View Code Duplication |
if ($request->getMethod() === 'POST') { |
|
104
|
1 |
|
$form->handleRequest($request); |
|
105
|
1 |
|
if ($form->isValid()) { |
|
106
|
1 |
|
log_info('商品規格登録開始', array($id)); |
|
107
|
|
|
|
|
108
|
1 |
|
$this->classNameRepository->save($TargetClassName); |
|
109
|
|
|
|
|
110
|
1 |
|
log_info('商品規格登録完了', array($id)); |
|
111
|
|
|
|
|
112
|
1 |
|
$event = new EventArgs( |
|
113
|
|
|
array( |
|
114
|
1 |
|
'form' => $form, |
|
115
|
1 |
|
'TargetClassName' => $TargetClassName, |
|
116
|
|
|
), |
|
117
|
1 |
|
$request |
|
118
|
|
|
); |
|
119
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_PRODUCT_CLASS_NAME_INDEX_COMPLETE, $event); |
|
120
|
|
|
|
|
121
|
1 |
|
$app->addSuccess('admin.class_name.save.complete', 'admin'); |
|
122
|
|
|
|
|
123
|
1 |
|
return $app->redirect($app->url('admin_product_class_name')); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
2 |
|
$ClassNames = $this->classNameRepository->getList(); |
|
128
|
|
|
|
|
129
|
|
|
return [ |
|
130
|
2 |
|
'form' => $form->createView(), |
|
131
|
2 |
|
'ClassNames' => $ClassNames, |
|
132
|
2 |
|
'TargetClassName' => $TargetClassName, |
|
133
|
|
|
]; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
|
|
|
|
|
137
|
|
|
* @Method("DELETE") |
|
138
|
|
|
* @Route("/{_admin}/product/class_name/{id}/delete", requirements={"id" = "\d+"}, name="admin_product_class_name_delete") |
|
139
|
|
|
*/ |
|
|
|
|
|
|
140
|
1 |
View Code Duplication |
public function delete(Application $app, Request $request, ClassName $ClassName) |
|
|
|
|
|
|
141
|
|
|
{ |
|
142
|
1 |
|
$this->isTokenValid($app); |
|
143
|
|
|
|
|
144
|
1 |
|
log_info('商品規格削除開始', array($ClassName->getId())); |
|
145
|
|
|
|
|
146
|
|
|
try { |
|
147
|
1 |
|
$this->classNameRepository->delete($ClassName); |
|
148
|
|
|
|
|
149
|
1 |
|
$event = new EventArgs(['ClassName' => $ClassName,], $request); |
|
|
|
|
|
|
150
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_PRODUCT_CLASS_NAME_DELETE_COMPLETE, $event); |
|
151
|
|
|
|
|
152
|
1 |
|
$app->addSuccess('admin.class_name.delete.complete', 'admin'); |
|
153
|
|
|
|
|
154
|
1 |
|
log_info('商品規格削除完了', array($ClassName->getId())); |
|
155
|
|
|
|
|
|
|
|
|
|
156
|
|
|
} catch (\Exception $e) { |
|
157
|
|
|
$message = $app->trans('admin.delete.failed.foreign_key', ['%name%' => '商品規格']); |
|
158
|
|
|
$app->addError($message, 'admin'); |
|
159
|
|
|
|
|
160
|
|
|
log_error('商品企画削除エラー', [$ClassName->getId(), $e]); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
1 |
|
return $app->redirect($app->url('admin_product_class_name')); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
|
|
|
|
|
167
|
|
|
* @Method("POST") |
|
168
|
|
|
* @Route("/{_admin}/product/class_name/sort_no/move", name="admin_product_class_name_sort_no_move") |
|
169
|
|
|
*/ |
|
|
|
|
|
|
170
|
1 |
View Code Duplication |
public function moveSortNo(Application $app, Request $request) |
|
|
|
|
|
|
171
|
|
|
{ |
|
172
|
1 |
|
if ($request->isXmlHttpRequest()) { |
|
173
|
1 |
|
$sortNos = $request->request->all(); |
|
174
|
1 |
|
foreach ($sortNos as $classNameId => $sortNo) { |
|
175
|
1 |
|
$ClassName = $this->classNameRepository |
|
176
|
1 |
|
->find($classNameId); |
|
177
|
1 |
|
$ClassName->setSortNo($sortNo); |
|
178
|
1 |
|
$this->entityManager->persist($ClassName); |
|
|
|
|
|
|
179
|
|
|
} |
|
180
|
1 |
|
$this->entityManager->flush(); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
1 |
|
return true; |
|
184
|
|
|
} |
|
185
|
|
|
} |
|
186
|
|
|
|