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\Order; |
15
|
|
|
|
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
17
|
|
|
use Doctrine\Common\Collections\Criteria; |
18
|
|
|
use Eccube\Controller\AbstractController; |
19
|
|
|
use Eccube\Entity\Customer; |
20
|
|
|
use Eccube\Entity\Master\CustomerStatus; |
21
|
|
|
use Eccube\Entity\Master\OrderItemType; |
22
|
|
|
use Eccube\Entity\Order; |
23
|
|
|
use Eccube\Entity\Shipping; |
24
|
|
|
use Eccube\Event\EccubeEvents; |
25
|
|
|
use Eccube\Event\EventArgs; |
26
|
|
|
use Eccube\Form\Type\AddCartType; |
27
|
|
|
use Eccube\Form\Type\Admin\OrderType; |
28
|
|
|
use Eccube\Form\Type\Admin\SearchCustomerType; |
29
|
|
|
use Eccube\Form\Type\Admin\SearchProductType; |
30
|
|
|
use Eccube\Repository\CategoryRepository; |
31
|
|
|
use Eccube\Repository\CustomerRepository; |
32
|
|
|
use Eccube\Repository\DeliveryRepository; |
33
|
|
|
use Eccube\Repository\Master\DeviceTypeRepository; |
34
|
|
|
use Eccube\Repository\Master\OrderItemTypeRepository; |
35
|
|
|
use Eccube\Repository\Master\OrderStatusRepository; |
36
|
|
|
use Eccube\Repository\OrderRepository; |
37
|
|
|
use Eccube\Repository\ProductRepository; |
38
|
|
|
use Eccube\Service\OrderStateMachine; |
39
|
|
|
use Eccube\Service\PurchaseFlow\Processor\OrderNoProcessor; |
40
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseContext; |
41
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseException; |
42
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseFlow; |
43
|
|
|
use Eccube\Service\TaxRuleService; |
44
|
|
|
use Knp\Component\Pager\Paginator; |
45
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
46
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
47
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
48
|
|
|
use Symfony\Component\HttpFoundation\Request; |
49
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
50
|
|
|
use Symfony\Component\Serializer\Serializer; |
51
|
|
|
use Symfony\Component\Serializer\SerializerInterface; |
52
|
|
|
|
53
|
|
|
class EditController extends AbstractController |
54
|
|
|
{ |
55
|
|
|
/** |
56
|
|
|
* @var TaxRuleService |
57
|
|
|
*/ |
58
|
|
|
protected $taxRuleService; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var DeviceTypeRepository |
62
|
|
|
*/ |
63
|
|
|
protected $deviceTypeRepository; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var ProductRepository |
67
|
|
|
*/ |
68
|
|
|
protected $productRepository; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var CategoryRepository |
72
|
|
|
*/ |
73
|
|
|
protected $categoryRepository; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var CustomerRepository |
77
|
|
|
*/ |
78
|
|
|
protected $customerRepository; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var Serializer |
82
|
|
|
*/ |
83
|
|
|
protected $serializer; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @var DeliveryRepository |
87
|
|
|
*/ |
88
|
|
|
protected $deliveryRepository; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @var PurchaseFlow |
92
|
|
|
*/ |
93
|
|
|
protected $purchaseFlow; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @var OrderRepository |
97
|
|
|
*/ |
98
|
|
|
protected $orderRepository; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @var OrderNoProcessor |
102
|
|
|
*/ |
103
|
|
|
protected $orderNoProcessor; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @var OrderItemTypeRepository |
107
|
|
|
*/ |
108
|
|
|
protected $orderItemTypeRepository; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @var OrderStateMachine |
112
|
|
|
*/ |
113
|
|
|
protected $orderStateMachine; |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @var OrderStatusRepository |
117
|
|
|
*/ |
118
|
|
|
protected $orderStatusRepository; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* EditController constructor. |
122
|
|
|
* |
123
|
|
|
* @param TaxRuleService $taxRuleService |
124
|
|
|
* @param DeviceTypeRepository $deviceTypeRepository |
125
|
|
|
* @param ProductRepository $productRepository |
126
|
|
|
* @param CategoryRepository $categoryRepository |
127
|
|
|
* @param CustomerRepository $customerRepository |
128
|
|
|
* @param SerializerInterface $serializer |
129
|
|
|
* @param DeliveryRepository $deliveryRepository |
130
|
|
|
* @param PurchaseFlow $orderPurchaseFlow |
131
|
|
|
* @param OrderRepository $orderRepository |
132
|
|
|
* @param OrderNoProcessor $orderNoProcessor |
133
|
|
|
*/ |
134
|
10 |
|
public function __construct( |
135
|
|
|
TaxRuleService $taxRuleService, |
136
|
|
|
DeviceTypeRepository $deviceTypeRepository, |
137
|
|
|
ProductRepository $productRepository, |
138
|
|
|
CategoryRepository $categoryRepository, |
139
|
|
|
CustomerRepository $customerRepository, |
140
|
|
|
SerializerInterface $serializer, |
141
|
|
|
DeliveryRepository $deliveryRepository, |
142
|
|
|
PurchaseFlow $orderPurchaseFlow, |
143
|
|
|
OrderRepository $orderRepository, |
144
|
|
|
OrderNoProcessor $orderNoProcessor, |
145
|
|
|
OrderItemTypeRepository $orderItemTypeRepository, |
146
|
|
|
OrderStatusRepository $orderStatusRepository, |
147
|
|
|
OrderStateMachine $orderStateMachine |
148
|
|
|
) { |
149
|
10 |
|
$this->taxRuleService = $taxRuleService; |
150
|
10 |
|
$this->deviceTypeRepository = $deviceTypeRepository; |
151
|
10 |
|
$this->productRepository = $productRepository; |
152
|
10 |
|
$this->categoryRepository = $categoryRepository; |
153
|
10 |
|
$this->customerRepository = $customerRepository; |
154
|
10 |
|
$this->serializer = $serializer; |
|
|
|
|
155
|
10 |
|
$this->deliveryRepository = $deliveryRepository; |
156
|
10 |
|
$this->purchaseFlow = $orderPurchaseFlow; |
157
|
10 |
|
$this->orderRepository = $orderRepository; |
158
|
10 |
|
$this->orderNoProcessor = $orderNoProcessor; |
159
|
10 |
|
$this->orderItemTypeRepository = $orderItemTypeRepository; |
160
|
10 |
|
$this->orderStatusRepository = $orderStatusRepository; |
161
|
10 |
|
$this->orderStateMachine = $orderStateMachine; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* 受注登録/編集画面. |
166
|
|
|
* |
167
|
|
|
* @Route("/%eccube_admin_route%/order/new", name="admin_order_new") |
168
|
|
|
* @Route("/%eccube_admin_route%/order/{id}/edit", requirements={"id" = "\d+"}, name="admin_order_edit") |
169
|
|
|
* @Template("@admin/Order/edit.twig") |
170
|
|
|
*/ |
171
|
7 |
|
public function index(Request $request, $id = null) |
172
|
|
|
{ |
173
|
7 |
|
$TargetOrder = null; |
|
|
|
|
174
|
7 |
|
$OriginOrder = null; |
|
|
|
|
175
|
|
|
|
176
|
7 |
|
if (null === $id) { |
177
|
|
|
// 空のエンティティを作成. |
178
|
3 |
|
$TargetOrder = new Order(); |
179
|
3 |
|
$TargetOrder->addShipping((new Shipping())->setOrder($TargetOrder)); |
180
|
|
|
} else { |
181
|
4 |
|
$TargetOrder = $this->orderRepository->find($id); |
182
|
4 |
|
if (null === $TargetOrder) { |
183
|
|
|
throw new NotFoundHttpException(); |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
// 編集前の受注情報を保持 |
188
|
7 |
|
$OriginOrder = clone $TargetOrder; |
189
|
7 |
|
$OriginItems = new ArrayCollection(); |
190
|
7 |
|
foreach ($TargetOrder->getOrderItems() as $Item) { |
191
|
4 |
|
$OriginItems->add($Item); |
192
|
|
|
} |
193
|
|
|
|
194
|
7 |
|
$builder = $this->formFactory->createBuilder(OrderType::class, $TargetOrder); |
195
|
|
|
|
196
|
7 |
|
$event = new EventArgs( |
197
|
|
|
[ |
198
|
7 |
|
'builder' => $builder, |
199
|
7 |
|
'OriginOrder' => $OriginOrder, |
200
|
7 |
|
'TargetOrder' => $TargetOrder, |
201
|
|
|
], |
202
|
7 |
|
$request |
203
|
|
|
); |
204
|
7 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_INITIALIZE, $event); |
205
|
|
|
|
206
|
7 |
|
$form = $builder->getForm(); |
207
|
|
|
|
208
|
7 |
|
$form->handleRequest($request); |
209
|
7 |
|
$purchaseContext = new PurchaseContext($OriginOrder, $OriginOrder->getCustomer()); |
210
|
|
|
|
211
|
7 |
|
if ($form->isSubmitted() && $form['OrderItems']->isValid()) { |
212
|
5 |
|
$event = new EventArgs( |
213
|
|
|
[ |
214
|
5 |
|
'builder' => $builder, |
215
|
5 |
|
'OriginOrder' => $OriginOrder, |
216
|
5 |
|
'TargetOrder' => $TargetOrder, |
217
|
5 |
|
'PurchaseContext' => $purchaseContext, |
218
|
|
|
], |
219
|
5 |
|
$request |
220
|
|
|
); |
221
|
5 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_PROGRESS, $event); |
222
|
|
|
|
223
|
5 |
|
$flowResult = $this->purchaseFlow->validate($TargetOrder, $purchaseContext); |
224
|
|
|
|
225
|
5 |
|
if ($flowResult->hasWarning()) { |
226
|
|
|
foreach ($flowResult->getWarning() as $warning) { |
227
|
|
|
$this->addWarning($warning->getMessage(), 'admin'); |
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
|
231
|
5 |
|
if ($flowResult->hasError()) { |
232
|
|
|
foreach ($flowResult->getErrors() as $error) { |
233
|
|
|
$this->addError($error->getMessage(), 'admin'); |
234
|
|
|
} |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
// 登録ボタン押下 |
238
|
5 |
|
switch ($request->get('mode')) { |
239
|
|
|
case 'register': |
240
|
5 |
|
log_info('受注登録開始', [$TargetOrder->getId()]); |
241
|
|
|
|
242
|
5 |
|
if (!$flowResult->hasError() && $form->isValid()) { |
243
|
|
|
try { |
244
|
5 |
|
$this->purchaseFlow->prepare($TargetOrder, $purchaseContext); |
245
|
5 |
|
$this->purchaseFlow->commit($TargetOrder, $purchaseContext); |
246
|
|
|
} catch (PurchaseException $e) { |
247
|
|
|
$this->addError($e->getMessage(), 'admin'); |
248
|
|
|
break; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
// ステータスが変更されている場合はステートマシンを実行. |
252
|
5 |
|
$OldStatus = $OriginOrder->getOrderStatus(); |
253
|
5 |
|
$NewStatus = $TargetOrder->getOrderStatus(); |
254
|
|
|
|
255
|
5 |
|
if ($TargetOrder->getId() && $OldStatus->getId() != $NewStatus->getId()) { |
256
|
|
|
// ステートマシンでステータスは更新されるので, 古いステータスに戻す. |
257
|
3 |
|
$TargetOrder->setOrderStatus($OldStatus); |
258
|
|
|
// FormTypeでステータスの遷移チェックは行っているのでapplyのみ実行. |
259
|
3 |
|
$this->orderStateMachine->apply($TargetOrder, $NewStatus); |
260
|
|
|
// FIXME ステートマシンがmtb_order_statusを更新しようとするので, refreshしておく. |
261
|
3 |
|
$this->entityManager->refresh($OldStatus); |
262
|
3 |
|
$this->entityManager->refresh($NewStatus); |
263
|
|
|
} |
264
|
|
|
|
265
|
5 |
|
$this->entityManager->persist($TargetOrder); |
266
|
5 |
|
$this->entityManager->flush(); |
267
|
|
|
|
268
|
5 |
|
foreach ($OriginItems as $Item) { |
269
|
3 |
|
if ($TargetOrder->getOrderItems()->contains($Item) === false) { |
270
|
3 |
|
$this->entityManager->remove($Item); |
271
|
|
|
} |
272
|
|
|
} |
273
|
5 |
|
$this->entityManager->flush(); |
274
|
|
|
|
275
|
|
|
// 新規登録時はMySQL対応のためflushしてから採番 |
276
|
5 |
|
$this->orderNoProcessor->process($TargetOrder, $purchaseContext); |
277
|
5 |
|
$this->entityManager->flush(); |
278
|
|
|
|
279
|
|
|
// 会員の場合、購入回数、購入金額などを更新 |
280
|
5 |
|
if ($Customer = $TargetOrder->getCustomer()) { |
281
|
5 |
|
$this->orderRepository->updateOrderSummary($Customer); |
282
|
5 |
|
$this->entityManager->flush($Customer); |
|
|
|
|
283
|
|
|
} |
284
|
|
|
|
285
|
5 |
|
$event = new EventArgs( |
286
|
|
|
[ |
287
|
5 |
|
'form' => $form, |
288
|
5 |
|
'OriginOrder' => $OriginOrder, |
289
|
5 |
|
'TargetOrder' => $TargetOrder, |
290
|
5 |
|
'Customer' => $Customer, |
291
|
|
|
], |
292
|
5 |
|
$request |
293
|
|
|
); |
294
|
5 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_COMPLETE, $event); |
295
|
|
|
|
296
|
5 |
|
$this->addSuccess('admin.order.save.complete', 'admin'); |
297
|
|
|
|
298
|
5 |
|
log_info('受注登録完了', [$TargetOrder->getId()]); |
299
|
|
|
|
300
|
5 |
|
return $this->redirectToRoute('admin_order_edit', ['id' => $TargetOrder->getId()]); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
break; |
304
|
|
|
default: |
305
|
|
|
break; |
306
|
|
|
} |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
// 会員検索フォーム |
310
|
2 |
|
$builder = $this->formFactory |
311
|
2 |
|
->createBuilder(SearchCustomerType::class); |
312
|
|
|
|
313
|
2 |
|
$event = new EventArgs( |
314
|
|
|
[ |
315
|
2 |
|
'builder' => $builder, |
316
|
2 |
|
'OriginOrder' => $OriginOrder, |
317
|
2 |
|
'TargetOrder' => $TargetOrder, |
318
|
|
|
], |
319
|
2 |
|
$request |
320
|
|
|
); |
321
|
2 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_INITIALIZE, $event); |
322
|
|
|
|
323
|
2 |
|
$searchCustomerModalForm = $builder->getForm(); |
324
|
|
|
|
325
|
|
|
// 商品検索フォーム |
326
|
2 |
|
$builder = $this->formFactory |
327
|
2 |
|
->createBuilder(SearchProductType::class); |
328
|
|
|
|
329
|
2 |
|
$event = new EventArgs( |
330
|
|
|
[ |
331
|
2 |
|
'builder' => $builder, |
332
|
2 |
|
'OriginOrder' => $OriginOrder, |
333
|
2 |
|
'TargetOrder' => $TargetOrder, |
334
|
|
|
], |
335
|
2 |
|
$request |
336
|
|
|
); |
337
|
2 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_INITIALIZE, $event); |
338
|
|
|
|
339
|
2 |
|
$searchProductModalForm = $builder->getForm(); |
340
|
|
|
|
341
|
|
|
// 配送業者のお届け時間 |
342
|
2 |
|
$times = []; |
343
|
2 |
|
$deliveries = $this->deliveryRepository->findAll(); |
344
|
2 |
View Code Duplication |
foreach ($deliveries as $Delivery) { |
|
|
|
|
345
|
2 |
|
$deliveryTiems = $Delivery->getDeliveryTimes(); |
346
|
2 |
|
foreach ($deliveryTiems as $DeliveryTime) { |
347
|
2 |
|
$times[$Delivery->getId()][$DeliveryTime->getId()] = $DeliveryTime->getDeliveryTime(); |
348
|
|
|
} |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
return [ |
352
|
2 |
|
'form' => $form->createView(), |
353
|
2 |
|
'searchCustomerModalForm' => $searchCustomerModalForm->createView(), |
354
|
2 |
|
'searchProductModalForm' => $searchProductModalForm->createView(), |
355
|
2 |
|
'Order' => $TargetOrder, |
356
|
2 |
|
'id' => $id, |
357
|
2 |
|
'shippingDeliveryTimes' => $this->serializer->serialize($times, 'json'), |
358
|
|
|
]; |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
/** |
362
|
|
|
* 顧客情報を検索する. |
363
|
|
|
* |
364
|
|
|
* @Route("/%eccube_admin_route%/order/search/customer/html", name="admin_order_search_customer_html") |
365
|
|
|
* @Route("/%eccube_admin_route%/order/search/customer/html/page/{page_no}", requirements={"page_No" = "\d+"}, name="admin_order_search_customer_html_page") |
366
|
|
|
* @Template("@admin/Order/search_customer.twig") |
367
|
|
|
* |
368
|
|
|
* @param Request $request |
369
|
|
|
* @param integer $page_no |
370
|
|
|
* |
371
|
|
|
* @return \Symfony\Component\HttpFoundation\JsonResponse |
372
|
|
|
*/ |
373
|
1 |
|
public function searchCustomerHtml(Request $request, $page_no = null, Paginator $paginator) |
374
|
|
|
{ |
375
|
1 |
|
if ($request->isXmlHttpRequest() && $this->isTokenValid()) { |
376
|
1 |
|
log_debug('search customer start.'); |
377
|
1 |
|
$page_count = $this->eccubeConfig['eccube_default_page_count']; |
378
|
1 |
|
$session = $this->session; |
379
|
|
|
|
380
|
1 |
|
if ('POST' === $request->getMethod()) { |
381
|
1 |
|
$page_no = 1; |
382
|
|
|
|
383
|
|
|
$searchData = [ |
384
|
1 |
|
'multi' => $request->get('search_word'), |
385
|
|
|
'customer_status' => [ |
386
|
1 |
|
CustomerStatus::REGULAR, |
387
|
|
|
], |
388
|
|
|
]; |
389
|
|
|
|
390
|
1 |
|
$session->set('eccube.admin.order.customer.search', $searchData); |
391
|
1 |
|
$session->set('eccube.admin.order.customer.search.page_no', $page_no); |
392
|
|
|
} else { |
393
|
|
|
$searchData = (array) $session->get('eccube.admin.order.customer.search'); |
394
|
|
|
if (is_null($page_no)) { |
395
|
|
|
$page_no = intval($session->get('eccube.admin.order.customer.search.page_no')); |
396
|
|
|
} else { |
397
|
|
|
$session->set('eccube.admin.order.customer.search.page_no', $page_no); |
398
|
|
|
} |
399
|
|
|
} |
400
|
|
|
|
401
|
1 |
|
$qb = $this->customerRepository->getQueryBuilderBySearchData($searchData); |
402
|
|
|
|
403
|
1 |
|
$event = new EventArgs( |
404
|
|
|
[ |
405
|
1 |
|
'qb' => $qb, |
406
|
1 |
|
'data' => $searchData, |
407
|
|
|
], |
408
|
1 |
|
$request |
409
|
|
|
); |
410
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_SEARCH, $event); |
411
|
|
|
|
412
|
|
|
/** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */ |
413
|
1 |
|
$pagination = $paginator->paginate( |
414
|
1 |
|
$qb, |
415
|
1 |
|
$page_no, |
416
|
1 |
|
$page_count, |
417
|
1 |
|
['wrap-queries' => true] |
418
|
|
|
); |
419
|
|
|
|
420
|
|
|
/** @var $Customers \Eccube\Entity\Customer[] */ |
421
|
1 |
|
$Customers = $pagination->getItems(); |
422
|
|
|
|
423
|
1 |
|
if (empty($Customers)) { |
424
|
|
|
log_debug('search customer not found.'); |
425
|
|
|
} |
426
|
|
|
|
427
|
1 |
|
$data = []; |
428
|
1 |
|
$formatName = '%s%s(%s%s)'; |
429
|
1 |
|
foreach ($Customers as $Customer) { |
430
|
1 |
|
$data[] = [ |
431
|
1 |
|
'id' => $Customer->getId(), |
432
|
1 |
|
'name' => sprintf($formatName, $Customer->getName01(), $Customer->getName02(), |
433
|
1 |
|
$Customer->getKana01(), |
434
|
1 |
|
$Customer->getKana02()), |
435
|
1 |
|
'phone_number' => $Customer->getPhoneNumber(), |
436
|
1 |
|
'email' => $Customer->getEmail(), |
437
|
|
|
]; |
438
|
|
|
} |
439
|
|
|
|
440
|
1 |
|
$event = new EventArgs( |
441
|
|
|
[ |
442
|
1 |
|
'data' => $data, |
443
|
1 |
|
'Customers' => $pagination, |
444
|
|
|
], |
445
|
1 |
|
$request |
446
|
|
|
); |
447
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_COMPLETE, $event); |
448
|
1 |
|
$data = $event->getArgument('data'); |
449
|
|
|
|
450
|
|
|
return [ |
451
|
1 |
|
'data' => $data, |
452
|
1 |
|
'pagination' => $pagination, |
453
|
|
|
]; |
454
|
|
|
} |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
/** |
458
|
|
|
* 顧客情報を検索する. |
459
|
|
|
* |
460
|
|
|
* @Method("POST") |
461
|
|
|
* @Route("/%eccube_admin_route%/order/search/customer/id", name="admin_order_search_customer_by_id") |
462
|
|
|
* |
463
|
|
|
* @param Request $request |
464
|
|
|
* |
465
|
|
|
* @return \Symfony\Component\HttpFoundation\JsonResponse |
466
|
|
|
*/ |
467
|
1 |
|
public function searchCustomerById(Request $request) |
468
|
|
|
{ |
469
|
1 |
|
if ($request->isXmlHttpRequest() && $this->isTokenValid()) { |
470
|
1 |
|
log_debug('search customer by id start.'); |
471
|
|
|
|
472
|
|
|
/** @var $Customer \Eccube\Entity\Customer */ |
473
|
1 |
|
$Customer = $this->customerRepository |
474
|
1 |
|
->find($request->get('id')); |
475
|
|
|
|
476
|
1 |
|
$event = new EventArgs( |
477
|
|
|
[ |
478
|
1 |
|
'Customer' => $Customer, |
479
|
|
|
], |
480
|
1 |
|
$request |
481
|
|
|
); |
482
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_INITIALIZE, $event); |
483
|
|
|
|
484
|
1 |
|
if (is_null($Customer)) { |
485
|
|
|
log_debug('search customer by id not found.'); |
486
|
|
|
|
487
|
|
|
return $this->json([], 404); |
488
|
|
|
} |
489
|
|
|
|
490
|
1 |
|
log_debug('search customer by id found.'); |
491
|
|
|
|
492
|
|
|
$data = [ |
493
|
1 |
|
'id' => $Customer->getId(), |
494
|
1 |
|
'name01' => $Customer->getName01(), |
495
|
1 |
|
'name02' => $Customer->getName02(), |
496
|
1 |
|
'kana01' => $Customer->getKana01(), |
497
|
1 |
|
'kana02' => $Customer->getKana02(), |
498
|
1 |
|
'postal_code' => $Customer->getPostalCode(), |
499
|
1 |
|
'pref' => is_null($Customer->getPref()) ? null : $Customer->getPref()->getId(), |
500
|
1 |
|
'addr01' => $Customer->getAddr01(), |
501
|
1 |
|
'addr02' => $Customer->getAddr02(), |
502
|
1 |
|
'email' => $Customer->getEmail(), |
503
|
1 |
|
'phone_number' => $Customer->getPhoneNumber(), |
504
|
1 |
|
'company_name' => $Customer->getCompanyName(), |
505
|
|
|
]; |
506
|
|
|
|
507
|
1 |
|
$event = new EventArgs( |
508
|
|
|
[ |
509
|
1 |
|
'data' => $data, |
510
|
1 |
|
'Customer' => $Customer, |
511
|
|
|
], |
512
|
1 |
|
$request |
513
|
|
|
); |
514
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_COMPLETE, $event); |
515
|
1 |
|
$data = $event->getArgument('data'); |
516
|
|
|
|
517
|
1 |
|
return $this->json($data); |
518
|
|
|
} |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
/** |
522
|
|
|
* @Route("/%eccube_admin_route%/order/search/product", name="admin_order_search_product") |
523
|
|
|
* @Route("/%eccube_admin_route%/order/search/product/page/{page_no}", requirements={"page_no" = "\d+"}, name="admin_order_search_product_page") |
524
|
|
|
* @Template("@admin/Order/search_product.twig") |
525
|
|
|
*/ |
526
|
1 |
|
public function searchProduct(Request $request, $page_no = null, Paginator $paginator) |
527
|
|
|
{ |
528
|
1 |
|
if ($request->isXmlHttpRequest() && $this->isTokenValid()) { |
529
|
1 |
|
log_debug('search product start.'); |
530
|
1 |
|
$page_count = $this->eccubeConfig['eccube_default_page_count']; |
531
|
1 |
|
$session = $this->session; |
532
|
|
|
|
533
|
1 |
|
if ('POST' === $request->getMethod()) { |
534
|
1 |
|
$page_no = 1; |
535
|
|
|
|
536
|
|
|
$searchData = [ |
537
|
1 |
|
'id' => $request->get('id'), |
538
|
|
|
]; |
539
|
|
|
|
540
|
1 |
|
if ($categoryId = $request->get('category_id')) { |
541
|
|
|
$Category = $this->categoryRepository->find($categoryId); |
542
|
|
|
$searchData['category_id'] = $Category; |
543
|
|
|
} |
544
|
|
|
|
545
|
1 |
|
$session->set('eccube.admin.order.product.search', $searchData); |
546
|
1 |
|
$session->set('eccube.admin.order.product.search.page_no', $page_no); |
547
|
|
|
} else { |
548
|
|
|
$searchData = (array) $session->get('eccube.admin.order.product.search'); |
549
|
|
|
if (is_null($page_no)) { |
550
|
|
|
$page_no = intval($session->get('eccube.admin.order.product.search.page_no')); |
551
|
|
|
} else { |
552
|
|
|
$session->set('eccube.admin.order.product.search.page_no', $page_no); |
553
|
|
|
} |
554
|
|
|
} |
555
|
|
|
|
556
|
1 |
|
$qb = $this->productRepository |
557
|
1 |
|
->getQueryBuilderBySearchDataForAdmin($searchData); |
558
|
|
|
|
559
|
1 |
|
$event = new EventArgs( |
560
|
|
|
[ |
561
|
1 |
|
'qb' => $qb, |
562
|
1 |
|
'searchData' => $searchData, |
563
|
|
|
], |
564
|
1 |
|
$request |
565
|
|
|
); |
566
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_SEARCH, $event); |
567
|
|
|
|
568
|
|
|
/** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */ |
569
|
1 |
|
$pagination = $paginator->paginate( |
570
|
1 |
|
$qb, |
571
|
1 |
|
$page_no, |
572
|
1 |
|
$page_count, |
573
|
1 |
|
['wrap-queries' => true] |
574
|
|
|
); |
575
|
|
|
|
576
|
|
|
/** @var $Products \Eccube\Entity\Product[] */ |
577
|
1 |
|
$Products = $pagination->getItems(); |
578
|
|
|
|
579
|
1 |
|
if (empty($Products)) { |
580
|
|
|
log_debug('search product not found.'); |
581
|
|
|
} |
582
|
|
|
|
583
|
1 |
|
$forms = []; |
584
|
1 |
View Code Duplication |
foreach ($Products as $Product) { |
|
|
|
|
585
|
|
|
/* @var $builder \Symfony\Component\Form\FormBuilderInterface */ |
586
|
1 |
|
$builder = $this->formFactory->createNamedBuilder('', AddCartType::class, null, [ |
587
|
1 |
|
'product' => $Product, |
588
|
|
|
]); |
589
|
1 |
|
$addCartForm = $builder->getForm(); |
590
|
1 |
|
$forms[$Product->getId()] = $addCartForm->createView(); |
591
|
|
|
} |
592
|
|
|
|
593
|
1 |
|
$event = new EventArgs( |
594
|
|
|
[ |
595
|
1 |
|
'forms' => $forms, |
596
|
1 |
|
'Products' => $Products, |
597
|
1 |
|
'pagination' => $pagination, |
598
|
|
|
], |
599
|
1 |
|
$request |
600
|
|
|
); |
601
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_COMPLETE, $event); |
602
|
|
|
|
603
|
|
|
return [ |
604
|
1 |
|
'forms' => $forms, |
605
|
1 |
|
'Products' => $Products, |
606
|
1 |
|
'pagination' => $pagination, |
607
|
|
|
]; |
608
|
|
|
} |
609
|
|
|
} |
610
|
|
|
|
611
|
|
|
/** |
612
|
|
|
* その他明細情報を取得 |
613
|
|
|
* |
614
|
|
|
* @Route("/%eccube_admin_route%/order/search/order_item_type", name="admin_order_search_order_item_type") |
615
|
|
|
* @Template("@admin/Order/order_item_type.twig") |
616
|
|
|
* |
617
|
|
|
* @param Request $request |
618
|
|
|
* |
619
|
|
|
* @return array |
620
|
|
|
*/ |
621
|
|
|
public function searchOrderItemType(Request $request) |
622
|
|
|
{ |
623
|
|
|
if ($request->isXmlHttpRequest() && $this->isTokenValid()) { |
624
|
|
|
log_debug('search order item type start.'); |
625
|
|
|
|
626
|
|
|
$criteria = Criteria::create(); |
627
|
|
|
$criteria |
628
|
|
|
->where($criteria->expr()->andX( |
629
|
|
|
$criteria->expr()->neq('id', OrderItemType::PRODUCT), |
630
|
|
|
$criteria->expr()->neq('id', OrderItemType::TAX) |
631
|
|
|
)) |
632
|
|
|
->orderBy(['sort_no' => 'ASC']); |
633
|
|
|
|
634
|
|
|
$OrderItemTypes = $this->orderItemTypeRepository->matching($criteria); |
635
|
|
|
|
636
|
|
|
$forms = []; |
637
|
|
|
foreach ($OrderItemTypes as $OrderItemType) { |
638
|
|
|
/* @var $builder \Symfony\Component\Form\FormBuilderInterface */ |
639
|
|
|
$builder = $this->formFactory->createBuilder(); |
640
|
|
|
$form = $builder->getForm(); |
641
|
|
|
$forms[$OrderItemType->getId()] = $form->createView(); |
642
|
|
|
} |
643
|
|
|
|
644
|
|
|
return [ |
645
|
|
|
'forms' => $forms, |
646
|
|
|
'OrderItemTypes' => $OrderItemTypes, |
647
|
|
|
]; |
648
|
|
|
} |
649
|
|
|
} |
650
|
|
|
} |
651
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.