|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of EC-CUBE |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved. |
|
7
|
|
|
* |
|
8
|
|
|
* http://www.lockon.co.jp/ |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Eccube\Controller\Admin\Shipping; |
|
15
|
|
|
|
|
16
|
|
|
use Eccube\Common\Constant; |
|
17
|
|
|
use Eccube\Controller\AbstractController; |
|
18
|
|
|
use Eccube\Entity\Shipping; |
|
19
|
|
|
use Eccube\Entity\OrderItem; |
|
20
|
|
|
use Eccube\Event\EccubeEvents; |
|
21
|
|
|
use Eccube\Event\EventArgs; |
|
22
|
|
|
use Eccube\Form\Type\Admin\SearchShippingType; |
|
23
|
|
|
use Eccube\Repository\Master\PageMaxRepository; |
|
24
|
|
|
use Eccube\Repository\ShippingRepository; |
|
25
|
|
|
use Eccube\Service\MailService; |
|
26
|
|
|
use Eccube\Service\OrderStateMachine; |
|
27
|
|
|
use Eccube\Util\FormUtil; |
|
28
|
|
|
use Knp\Component\Pager\PaginatorInterface; |
|
29
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
30
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
31
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
|
32
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
33
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
34
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
35
|
|
|
|
|
36
|
|
|
class ShippingController extends AbstractController |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* @var ShippingRepository |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $shippingRepository; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var PageMaxRepository |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $pageMaxRepository; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var MailService |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $mailService; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var OrderStateMachine |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $orderStateMachine; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
|
|
|
|
|
59
|
|
|
* ShippingController constructor. |
|
60
|
|
|
* |
|
61
|
|
|
* @param ShippingRepository $shippingRepository |
|
62
|
|
|
* @param PageMaxRepository $pageMaxRepository |
|
|
|
|
|
|
63
|
|
|
* @param MailService $mailService |
|
|
|
|
|
|
64
|
|
|
* @param OrderStateMachine $orderStateMachine; |
|
|
|
|
|
|
65
|
|
|
*/ |
|
66
|
3 |
|
public function __construct( |
|
67
|
|
|
ShippingRepository $shippingRepository, |
|
68
|
|
|
PageMaxRepository $pageMaxRepository, |
|
69
|
|
|
MailService $mailService, |
|
70
|
|
|
OrderStateMachine $orderStateMachine |
|
71
|
|
|
) { |
|
72
|
3 |
|
$this->shippingRepository = $shippingRepository; |
|
73
|
3 |
|
$this->pageMaxRepository = $pageMaxRepository; |
|
74
|
3 |
|
$this->mailService = $mailService; |
|
75
|
3 |
|
$this->orderStateMachine = $orderStateMachine; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
|
|
|
|
|
79
|
|
|
* @Route("/%eccube_admin_route%/shipping", name="admin_shipping") |
|
80
|
|
|
* @Route("/%eccube_admin_route%/shipping/page/{page_no}", name="admin_shipping_page") |
|
81
|
|
|
* @Template("@admin/Shipping/index.twig") |
|
82
|
|
|
*/ |
|
|
|
|
|
|
83
|
|
|
public function index(Request $request, $page_no = null, PaginatorInterface $paginator) |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
$builder = $this->formFactory |
|
86
|
|
|
->createBuilder(SearchShippingType::class); |
|
87
|
|
|
|
|
88
|
|
|
$event = new EventArgs( |
|
89
|
|
|
[ |
|
90
|
|
|
'builder' => $builder, |
|
91
|
|
|
], |
|
92
|
|
|
$request |
|
93
|
|
|
); |
|
94
|
|
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_SHIPPING_INDEX_INITIALIZE, $event); |
|
95
|
|
|
|
|
96
|
|
|
$searchForm = $builder->getForm(); |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* ページの表示件数は, 以下の順に優先される. |
|
100
|
|
|
* - リクエストパラメータ |
|
101
|
|
|
* - セッション |
|
102
|
|
|
* - デフォルト値 |
|
103
|
|
|
* また, セッションに保存する際は mtb_page_maxと照合し, 一致した場合のみ保存する. |
|
104
|
|
|
**/ |
|
105
|
|
|
$page_count = $this->session->get('eccube.admin.shipping.search.page_count', |
|
106
|
|
|
$this->eccubeConfig->get('eccube_default_page_count')); |
|
107
|
|
|
|
|
108
|
|
|
$page_count_param = (int) $request->get('page_count'); |
|
109
|
|
|
$pageMaxis = $this->pageMaxRepository->findAll(); |
|
110
|
|
|
|
|
111
|
|
|
if ($page_count_param) { |
|
112
|
|
|
foreach ($pageMaxis as $pageMax) { |
|
113
|
|
|
if ($page_count_param == $pageMax->getName()) { |
|
114
|
|
|
$page_count = $pageMax->getName(); |
|
115
|
|
|
$this->session->set('eccube.admin.shipping.search.page_count', $page_count); |
|
116
|
|
|
break; |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
if ('POST' === $request->getMethod()) { |
|
122
|
|
|
$searchForm->handleRequest($request); |
|
123
|
|
|
|
|
124
|
|
|
if ($searchForm->isValid()) { |
|
125
|
|
|
/** |
|
126
|
|
|
* 検索が実行された場合は, セッションに検索条件を保存する. |
|
127
|
|
|
* ページ番号は最初のページ番号に初期化する. |
|
128
|
|
|
*/ |
|
129
|
|
|
$page_no = 1; |
|
130
|
|
|
$searchData = $searchForm->getData(); |
|
131
|
|
|
|
|
132
|
|
|
// 検索条件, ページ番号をセッションに保持. |
|
133
|
|
|
$this->session->set('eccube.admin.shipping.search', FormUtil::getViewData($searchForm)); |
|
134
|
|
|
$this->session->set('eccube.admin.shipping.search.page_no', $page_no); |
|
135
|
|
|
} else { |
|
136
|
|
|
return [ |
|
137
|
|
|
'searchForm' => $searchForm->createView(), |
|
138
|
|
|
'pagination' => [], |
|
139
|
|
|
'pageMaxis' => $pageMaxis, |
|
140
|
|
|
'page_no' => $page_no, |
|
141
|
|
|
'page_count' => $page_count, |
|
142
|
|
|
'has_errors' => true, |
|
143
|
|
|
]; |
|
144
|
|
|
} |
|
145
|
|
|
} else { |
|
146
|
|
|
if (null !== $page_no || $request->get('resume')) { |
|
147
|
|
|
/* |
|
148
|
|
|
* ページ送りの場合または、他画面から戻ってきた場合は, セッションから検索条件を復旧する. |
|
149
|
|
|
*/ |
|
150
|
|
|
if ($page_no) { |
|
151
|
|
|
// ページ送りで遷移した場合. |
|
152
|
|
|
$this->session->set('eccube.admin.shipping.search.page_no', (int) $page_no); |
|
153
|
|
|
} else { |
|
154
|
|
|
// 他画面から遷移した場合. |
|
155
|
|
|
$page_no = $this->session->get('eccube.admin.shipping.search.page_no', 1); |
|
156
|
|
|
} |
|
157
|
|
|
$viewData = $this->session->get('eccube.admin.shipping.search', []); |
|
158
|
|
|
$searchData = FormUtil::submitAndGetData($searchForm, $viewData); |
|
159
|
|
|
} else { |
|
160
|
|
|
/** |
|
161
|
|
|
* 初期表示の場合. |
|
162
|
|
|
*/ |
|
163
|
|
|
$page_no = 1; |
|
164
|
|
|
$searchData = []; |
|
165
|
|
|
|
|
166
|
|
|
// セッション中の検索条件, ページ番号を初期化. |
|
167
|
|
|
$this->session->set('eccube.admin.shipping.search', $searchData); |
|
168
|
|
|
$this->session->set('eccube.admin.shipping.search.page_no', $page_no); |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
$qb = $this->shippingRepository->getQueryBuilderBySearchDataForAdmin($searchData); |
|
173
|
|
|
|
|
174
|
|
|
$event = new EventArgs( |
|
175
|
|
|
[ |
|
176
|
|
|
'qb' => $qb, |
|
177
|
|
|
'searchData' => $searchData, |
|
178
|
|
|
], |
|
179
|
|
|
$request |
|
180
|
|
|
); |
|
181
|
|
|
|
|
182
|
|
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_SHIPPING_INDEX_SEARCH, $event); |
|
183
|
|
|
|
|
184
|
|
|
$pagination = $paginator->paginate( |
|
185
|
|
|
$qb, |
|
186
|
|
|
$page_no, |
|
187
|
|
|
$page_count |
|
188
|
|
|
); |
|
189
|
|
|
|
|
190
|
|
|
return [ |
|
191
|
|
|
'searchForm' => $searchForm->createView(), |
|
192
|
|
|
'pagination' => $pagination, |
|
193
|
|
|
'pageMaxis' => $pageMaxis, |
|
194
|
|
|
'page_no' => $page_no, |
|
195
|
|
|
'page_count' => $page_count, |
|
196
|
|
|
'has_errors' => false, |
|
197
|
|
|
]; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @Route("/%eccube_admin_route%/shipping/preview_notify_mail/{id}", requirements={"id" = "\d+"}, name="admin_shipping_preview_notify_mail") |
|
202
|
|
|
* |
|
203
|
|
|
* @param Shipping $Shipping |
|
204
|
|
|
* |
|
205
|
|
|
* @return Response |
|
206
|
|
|
* |
|
207
|
|
|
* @throws \Twig_Error |
|
208
|
|
|
*/ |
|
209
|
|
|
public function previewShippingNotifyMail(Shipping $Shipping) |
|
210
|
|
|
{ |
|
211
|
|
|
return new Response($this->mailService->getShippingNotifyMailBody($Shipping, $Shipping->getOrder())); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* @Method("PUT") |
|
216
|
|
|
* @Route("/%eccube_admin_route%/shipping/notify_mail/{id}", requirements={"id" = "\d+"}, name="admin_shipping_notify_mail") |
|
217
|
|
|
* |
|
218
|
|
|
* @param Shipping $Shipping |
|
219
|
|
|
* |
|
220
|
|
|
* @return JsonResponse |
|
221
|
|
|
* |
|
222
|
|
|
* @throws \Twig_Error |
|
223
|
|
|
*/ |
|
224
|
2 |
|
public function notifyMail(Shipping $Shipping) |
|
225
|
|
|
{ |
|
226
|
2 |
|
$this->isTokenValid(); |
|
227
|
|
|
|
|
228
|
2 |
|
$this->mailService->sendShippingNotifyMail($Shipping); |
|
229
|
|
|
|
|
230
|
2 |
|
$Shipping->setMailSendDate(new \DateTime()); |
|
231
|
2 |
|
$this->shippingRepository->save($Shipping); |
|
232
|
2 |
|
$this->entityManager->flush(); |
|
233
|
|
|
|
|
234
|
2 |
|
return $this->json([ |
|
235
|
2 |
|
'mail' => true, |
|
236
|
|
|
'shipped' => false, |
|
237
|
|
|
]); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
|
|
|
|
|
241
|
|
|
* @Method("POST") |
|
242
|
|
|
* @Route("/%eccube_admin_route%/shipping/bulk_delete", name="admin_shipping_bulk_delete") |
|
243
|
|
|
*/ |
|
|
|
|
|
|
244
|
1 |
|
public function bulkDelete(Request $request) |
|
245
|
|
|
{ |
|
246
|
1 |
|
$this->isTokenValid(); |
|
247
|
1 |
|
$ids = $request->get('ids'); |
|
248
|
|
|
|
|
249
|
1 |
|
foreach ($ids as $shipping_id) { |
|
250
|
|
|
/** @var Shipping $Shipping */ |
|
251
|
1 |
|
$Shipping = $this->shippingRepository->find($shipping_id); |
|
|
|
|
|
|
252
|
1 |
|
if ($Shipping) { |
|
253
|
1 |
|
$OrderItems = $Shipping->getOrderItems(); |
|
254
|
|
|
/** @var OrderItem $OrderItem */ |
|
255
|
1 |
|
foreach ($OrderItems as $OrderItem) { |
|
256
|
1 |
|
$OrderItem->setShipping(null); |
|
257
|
|
|
} |
|
258
|
1 |
|
$this->entityManager->remove($Shipping); |
|
259
|
1 |
|
log_info('出荷削除', [$Shipping->getId()]); |
|
260
|
|
|
} |
|
261
|
|
|
} |
|
262
|
1 |
|
$this->entityManager->flush(); |
|
263
|
|
|
|
|
264
|
1 |
|
$this->addSuccess('admin.shipping.delete.complete', 'admin'); |
|
265
|
|
|
|
|
266
|
1 |
|
return $this->redirect($this->generateUrl('admin_shipping', ['resume' => Constant::ENABLED])); |
|
267
|
|
|
} |
|
268
|
|
|
} |
|
269
|
|
|
|