|
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\Mypage; |
|
26
|
|
|
|
|
27
|
|
|
use Doctrine\ORM\EntityManager; |
|
28
|
|
|
use Eccube\Annotation\Component; |
|
29
|
|
|
use Eccube\Annotation\Inject; |
|
30
|
|
|
use Eccube\Application; |
|
31
|
|
|
use Eccube\Controller\AbstractController; |
|
32
|
|
|
use Eccube\Entity\BaseInfo; |
|
33
|
|
|
use Eccube\Entity\CustomerAddress; |
|
34
|
|
|
use Eccube\Event\EccubeEvents; |
|
35
|
|
|
use Eccube\Event\EventArgs; |
|
36
|
|
|
use Eccube\Form\Type\Front\CustomerAddressType; |
|
37
|
|
|
use Eccube\Repository\CustomerAddressRepository; |
|
38
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
39
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
40
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
|
41
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
|
42
|
|
|
use Symfony\Component\Form\FormFactory; |
|
43
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
44
|
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
|
45
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @Component |
|
49
|
|
|
* @Route(service=DeliveryController::class) |
|
50
|
|
|
*/ |
|
51
|
|
|
class DeliveryController extends AbstractController |
|
52
|
|
|
{ |
|
53
|
|
|
/** |
|
54
|
|
|
* @Inject(BaseInfo::class) |
|
55
|
|
|
* @var BaseInfo |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $BaseInfo; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @Inject("orm.em") |
|
61
|
|
|
* @var EntityManager |
|
62
|
|
|
*/ |
|
63
|
|
|
protected $entityManager; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @Inject("eccube.event.dispatcher") |
|
67
|
|
|
* @var EventDispatcher |
|
68
|
|
|
*/ |
|
69
|
|
|
protected $eventDispatcher; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @Inject("form.factory") |
|
73
|
|
|
* @var FormFactory |
|
74
|
|
|
*/ |
|
75
|
|
|
protected $formFactory; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @Inject(CustomerAddressRepository::class) |
|
79
|
|
|
* @var CustomerAddressRepository |
|
80
|
|
|
*/ |
|
81
|
|
|
protected $customerAddressRepository; |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @Inject("config") |
|
85
|
|
|
* @var array |
|
86
|
|
|
*/ |
|
87
|
|
|
protected $appConfig; |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
|
|
|
|
|
90
|
|
|
* お届け先一覧画面. |
|
91
|
|
|
* |
|
92
|
|
|
* @Route("/mypage/delivery", name="mypage_delivery") |
|
93
|
|
|
* @Template("Mypage/delivery.twig") |
|
94
|
|
|
*/ |
|
|
|
|
|
|
95
|
1 |
|
public function index(Application $app, Request $request) |
|
|
|
|
|
|
96
|
|
|
{ |
|
97
|
1 |
|
$Customer = $app['user']; |
|
98
|
|
|
|
|
99
|
|
|
return [ |
|
100
|
1 |
|
'Customer' => $Customer, |
|
101
|
|
|
]; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
|
|
|
|
|
105
|
|
|
* お届け先編集画面. |
|
106
|
|
|
* |
|
107
|
|
|
* @Route("/mypage/delivery/new", name="mypage_delivery_new") |
|
108
|
|
|
* @Route("/mypage/delivery/{id}/edit", name="mypage_delivery_edit", requirements={"id" = "\d+"}) |
|
109
|
|
|
* @Template("Mypage/delivery_edit.twig") |
|
110
|
|
|
*/ |
|
|
|
|
|
|
111
|
4 |
|
public function edit(Application $app, Request $request, $id = null) |
|
112
|
|
|
{ |
|
113
|
4 |
|
$Customer = $app['user']; |
|
114
|
|
|
|
|
115
|
|
|
// 配送先住所最大値判定 |
|
116
|
|
|
// $idが存在する際は、追加処理ではなく、編集の処理ため本ロジックスキップ |
|
117
|
4 |
View Code Duplication |
if (is_null($id)) { |
|
118
|
2 |
|
$addressCurrNum = count($Customer->getCustomerAddresses()); |
|
119
|
2 |
|
$addressMax = $this->appConfig['deliv_addr_max']; |
|
120
|
2 |
|
if ($addressCurrNum >= $addressMax) { |
|
121
|
|
|
throw new NotFoundHttpException('お届け先の登録数の上限を超えています'); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
4 |
|
$CustomerAddress = $this->customerAddressRepository->findOrCreateByCustomerAndId($Customer, $id); |
|
|
|
|
|
|
126
|
|
|
|
|
127
|
4 |
|
$parentPage = $request->get('parent_page', null); |
|
128
|
|
|
|
|
129
|
|
|
// 正しい遷移かをチェック |
|
130
|
|
|
$allowdParents = array( |
|
131
|
4 |
|
$app->url('mypage_delivery'), |
|
132
|
4 |
|
$app->url('shopping_redirect_to'), |
|
133
|
|
|
); |
|
134
|
|
|
|
|
135
|
|
|
// 遷移が正しくない場合、デフォルトであるマイページの配送先追加の画面を設定する |
|
136
|
4 |
|
if (!in_array($parentPage, $allowdParents)) { |
|
137
|
|
|
// @deprecated 使用されていないコード |
|
138
|
4 |
|
$parentPage = $app->url('mypage_delivery'); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
4 |
|
$builder = $this->formFactory |
|
142
|
4 |
|
->createBuilder(CustomerAddressType::class, $CustomerAddress); |
|
143
|
|
|
|
|
144
|
4 |
|
$event = new EventArgs( |
|
145
|
|
|
array( |
|
146
|
4 |
|
'builder' => $builder, |
|
147
|
4 |
|
'Customer' => $Customer, |
|
148
|
4 |
|
'CustomerAddress' => $CustomerAddress, |
|
149
|
|
|
), |
|
150
|
4 |
|
$request |
|
151
|
|
|
); |
|
152
|
4 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_MYPAGE_DELIVERY_EDIT_INITIALIZE, $event); |
|
153
|
|
|
|
|
154
|
4 |
|
$form = $builder->getForm(); |
|
155
|
4 |
|
$form->handleRequest($request); |
|
156
|
|
|
|
|
157
|
4 |
View Code Duplication |
if ($form->isSubmitted() && $form->isValid()) { |
|
158
|
2 |
|
log_info('お届け先登録開始', array($id)); |
|
159
|
|
|
|
|
160
|
2 |
|
$this->entityManager->persist($CustomerAddress); |
|
161
|
2 |
|
$this->entityManager->flush(); |
|
162
|
|
|
|
|
163
|
2 |
|
log_info('お届け先登録完了', array($id)); |
|
164
|
|
|
|
|
165
|
2 |
|
$event = new EventArgs( |
|
166
|
|
|
array( |
|
167
|
2 |
|
'form' => $form, |
|
168
|
2 |
|
'Customer' => $Customer, |
|
169
|
2 |
|
'CustomerAddress' => $CustomerAddress, |
|
170
|
|
|
), |
|
171
|
2 |
|
$request |
|
172
|
|
|
); |
|
173
|
2 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_MYPAGE_DELIVERY_EDIT_COMPLETE, $event); |
|
174
|
|
|
|
|
175
|
2 |
|
$app->addSuccess('mypage.delivery.add.complete'); |
|
176
|
|
|
|
|
177
|
2 |
|
return $app->redirect($app->url('mypage_delivery')); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
return [ |
|
181
|
2 |
|
'form' => $form->createView(), |
|
182
|
2 |
|
'parentPage' => $parentPage, |
|
183
|
2 |
|
'BaseInfo' => $this->BaseInfo, |
|
184
|
|
|
]; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
|
|
|
|
|
188
|
|
|
* お届け先を削除する. |
|
189
|
|
|
* |
|
190
|
|
|
* @Method("DELETE") |
|
191
|
|
|
* @Route("/mypage/delivery/{id}/delete", name="mypage_delivery_delete") |
|
192
|
|
|
*/ |
|
|
|
|
|
|
193
|
1 |
|
public function delete(Application $app, Request $request, CustomerAddress $CustomerAddress) |
|
194
|
|
|
{ |
|
195
|
1 |
|
$this->isTokenValid($app); |
|
196
|
|
|
|
|
197
|
1 |
|
log_info('お届け先削除開始', array($CustomerAddress->getId())); |
|
198
|
|
|
|
|
199
|
1 |
|
$Customer = $app['user']; |
|
200
|
|
|
|
|
201
|
1 |
|
if ($Customer->getId() != $CustomerAddress->getCustomer()->getId()) { |
|
202
|
|
|
throw new BadRequestHttpException(); |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
1 |
|
$this->customerAddressRepository->delete($CustomerAddress); |
|
206
|
|
|
|
|
207
|
1 |
|
$event = new EventArgs( |
|
208
|
|
|
array( |
|
|
|
|
|
|
209
|
1 |
|
'Customer' => $Customer, |
|
210
|
1 |
|
'CustomerAddress' => $CustomerAddress |
|
211
|
1 |
|
), $request |
|
212
|
|
|
); |
|
213
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_MYPAGE_DELIVERY_DELETE_COMPLETE, $event); |
|
214
|
|
|
|
|
215
|
1 |
|
$app->addSuccess('mypage.address.delete.complete'); |
|
216
|
|
|
|
|
217
|
1 |
|
log_info('お届け先削除完了', array($CustomerAddress->getId())); |
|
218
|
|
|
|
|
219
|
1 |
|
return $app->redirect($app->url('mypage_delivery')); |
|
220
|
|
|
} |
|
221
|
|
|
} |
|
222
|
|
|
|