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