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