|
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 Eccube\Application; |
|
28
|
|
|
use Eccube\Common\Constant; |
|
29
|
|
|
use Eccube\Controller\AbstractController; |
|
30
|
|
|
use Eccube\Entity\ShipmentItem; |
|
31
|
|
|
use Eccube\Event\EccubeEvents; |
|
32
|
|
|
use Eccube\Event\EventArgs; |
|
33
|
|
|
use Symfony\Component\Form\FormError; |
|
34
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
35
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
36
|
|
|
|
|
37
|
|
|
class EditController extends AbstractController |
|
|
|
|
|
|
38
|
|
|
{ |
|
39
|
10 |
|
public function index(Application $app, Request $request, $id = null) |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
/* @var $softDeleteFilter \Eccube\Doctrine\Filter\SoftDeleteFilter */ |
|
42
|
10 |
|
$softDeleteFilter = $app['orm.em']->getFilters()->getFilter('soft_delete'); |
|
43
|
10 |
|
$softDeleteFilter->setExcludes(array( |
|
44
|
10 |
|
'Eccube\Entity\ProductClass', |
|
45
|
|
|
'Eccube\Entity\Product', |
|
46
|
|
|
)); |
|
47
|
|
|
|
|
48
|
10 |
|
$TargetOrder = null; |
|
|
|
|
|
|
49
|
10 |
|
$OriginOrder = null; |
|
|
|
|
|
|
50
|
|
|
|
|
51
|
10 |
|
if (is_null($id)) { |
|
52
|
|
|
// 空のエンティティを作成. |
|
53
|
4 |
|
$TargetOrder = $this->newOrder(); |
|
54
|
|
|
} else { |
|
55
|
6 |
|
$TargetOrder = $app['eccube.repository.order']->find($id); |
|
56
|
6 |
|
if (is_null($TargetOrder)) { |
|
57
|
|
|
throw new NotFoundHttpException(); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
// 編集前の受注情報を保持 |
|
62
|
10 |
|
$OriginOrder = clone $TargetOrder; |
|
63
|
10 |
|
$OriginalOrderDetails = new ArrayCollection(); |
|
64
|
|
|
|
|
65
|
10 |
|
foreach ($TargetOrder->getOrderDetails() as $OrderDetail) { |
|
66
|
10 |
|
$OriginalOrderDetails->add($OrderDetail); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
10 |
|
$builder = $app['form.factory'] |
|
70
|
10 |
|
->createBuilder('order', $TargetOrder); |
|
71
|
|
|
|
|
72
|
10 |
|
$event = new EventArgs( |
|
73
|
|
|
array( |
|
74
|
10 |
|
'builder' => $builder, |
|
75
|
10 |
|
'OriginOrder' => $OriginOrder, |
|
76
|
10 |
|
'TargetOrder' => $TargetOrder, |
|
77
|
10 |
|
'OriginOrderDetails' => $OriginalOrderDetails, |
|
78
|
|
|
), |
|
79
|
|
|
$request |
|
80
|
|
|
); |
|
81
|
10 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_INITIALIZE, $event); |
|
82
|
|
|
|
|
83
|
10 |
|
$form = $builder->getForm(); |
|
84
|
|
|
|
|
85
|
10 |
|
if ('POST' === $request->getMethod()) { |
|
86
|
6 |
|
$form->handleRequest($request); |
|
87
|
|
|
|
|
88
|
6 |
|
$event = new EventArgs( |
|
89
|
|
|
array( |
|
90
|
6 |
|
'builder' => $builder, |
|
91
|
6 |
|
'OriginOrder' => $OriginOrder, |
|
92
|
6 |
|
'TargetOrder' => $TargetOrder, |
|
93
|
6 |
|
'OriginOrderDetails' => $OriginalOrderDetails, |
|
94
|
|
|
), |
|
95
|
|
|
$request |
|
96
|
|
|
); |
|
97
|
6 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_PROGRESS, $event); |
|
98
|
|
|
|
|
99
|
|
|
// 入力情報にもとづいて再計算. |
|
100
|
6 |
|
$this->calculate($app, $TargetOrder); |
|
101
|
|
|
|
|
102
|
|
|
// 登録ボタン押下 |
|
103
|
6 |
|
switch ($request->get('mode')) { |
|
104
|
6 |
|
case 'register': |
|
105
|
6 |
|
if ($TargetOrder->getTotal() > $app['config']['max_total_fee']) { |
|
106
|
|
|
$form['charge']->addError(new FormError('合計金額の上限を超えております。')); |
|
107
|
6 |
|
} elseif ($form->isValid()) { |
|
|
|
|
|
|
108
|
|
|
|
|
109
|
6 |
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
|
110
|
|
|
|
|
111
|
|
|
// お支払い方法の更新 |
|
112
|
6 |
|
$TargetOrder->setPaymentMethod($TargetOrder->getPayment()->getMethod()); |
|
113
|
|
|
|
|
114
|
|
|
// 配送業者・お届け時間の更新 |
|
115
|
6 |
|
$Shippings = $TargetOrder->getShippings(); |
|
116
|
6 |
|
foreach ($Shippings as $Shipping) { |
|
117
|
6 |
|
$Shipping->setShippingDeliveryName($Shipping->getDelivery()->getName()); |
|
118
|
6 |
|
if (!is_null($Shipping->getDeliveryTime())) { |
|
119
|
6 |
|
$Shipping->setShippingDeliveryTime($Shipping->getDeliveryTime()->getDeliveryTime()); |
|
120
|
|
|
} else { |
|
121
|
6 |
|
$Shipping->setShippingDeliveryTime(null); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
// 受注日/発送日/入金日の更新. |
|
127
|
6 |
|
$this->updateDate($app, $TargetOrder, $OriginOrder); |
|
128
|
|
|
|
|
129
|
|
|
// 受注明細で削除されているものをremove |
|
130
|
6 |
|
foreach ($OriginalOrderDetails as $OrderDetail) { |
|
131
|
4 |
|
if (false === $TargetOrder->getOrderDetails()->contains($OrderDetail)) { |
|
132
|
6 |
|
$app['orm.em']->remove($OrderDetail); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
|
|
137
|
6 |
|
if ($BaseInfo->getOptionMultipleShipping() == Constant::ENABLED) { |
|
138
|
|
|
foreach ($TargetOrder->getOrderDetails() as $OrderDetail) { |
|
139
|
|
|
/** @var $OrderDetail \Eccube\Entity\OrderDetail */ |
|
140
|
|
|
$OrderDetail->setOrder($TargetOrder); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** @var \Eccube\Entity\Shipping $Shipping */ |
|
144
|
|
View Code Duplication |
foreach ($Shippings as $Shipping) { |
|
|
|
|
|
|
145
|
|
|
$shipmentItems = $Shipping->getShipmentItems(); |
|
146
|
|
|
/** @var \Eccube\Entity\ShipmentItem $ShipmentItem */ |
|
147
|
|
|
foreach ($shipmentItems as $ShipmentItem) { |
|
148
|
|
|
$ShipmentItem->setOrder($TargetOrder); |
|
149
|
|
|
$ShipmentItem->setShipping($Shipping); |
|
150
|
|
|
$app['orm.em']->persist($ShipmentItem); |
|
151
|
|
|
} |
|
152
|
|
|
$Shipping->setOrder($TargetOrder); |
|
153
|
|
|
$app['orm.em']->persist($Shipping); |
|
154
|
|
|
} |
|
155
|
|
|
} else { |
|
|
|
|
|
|
156
|
|
|
|
|
157
|
6 |
|
$NewShipmentItems = new ArrayCollection(); |
|
158
|
|
|
|
|
159
|
6 |
|
foreach ($TargetOrder->getOrderDetails() as $OrderDetail) { |
|
160
|
|
|
/** @var $OrderDetail \Eccube\Entity\OrderDetail */ |
|
161
|
6 |
|
$OrderDetail->setOrder($TargetOrder); |
|
162
|
|
|
|
|
163
|
6 |
|
$NewShipmentItem = new ShipmentItem(); |
|
164
|
|
|
$NewShipmentItem |
|
165
|
6 |
|
->setProduct($OrderDetail->getProduct()) |
|
166
|
6 |
|
->setProductClass($OrderDetail->getProductClass()) |
|
167
|
6 |
|
->setProductName($OrderDetail->getProduct()->getName()) |
|
168
|
6 |
|
->setProductCode($OrderDetail->getProductClass()->getCode()) |
|
169
|
6 |
|
->setClassCategoryName1($OrderDetail->getClassCategoryName1()) |
|
170
|
6 |
|
->setClassCategoryName2($OrderDetail->getClassCategoryName2()) |
|
171
|
6 |
|
->setClassName1($OrderDetail->getClassName1()) |
|
172
|
6 |
|
->setClassName2($OrderDetail->getClassName2()) |
|
173
|
6 |
|
->setPrice($OrderDetail->getPrice()) |
|
174
|
6 |
|
->setQuantity($OrderDetail->getQuantity()) |
|
175
|
6 |
|
->setOrder($TargetOrder); |
|
176
|
6 |
|
$NewShipmentItems[] = $NewShipmentItem; |
|
177
|
|
|
|
|
|
|
|
|
|
178
|
|
|
} |
|
179
|
|
|
// 配送商品の更新. delete/insert. |
|
180
|
6 |
|
$Shippings = $TargetOrder->getShippings(); |
|
181
|
6 |
View Code Duplication |
foreach ($Shippings as $Shipping) { |
|
|
|
|
|
|
182
|
6 |
|
$ShipmentItems = $Shipping->getShipmentItems(); |
|
183
|
6 |
|
foreach ($ShipmentItems as $ShipmentItem) { |
|
184
|
6 |
|
$app['orm.em']->remove($ShipmentItem); |
|
185
|
|
|
} |
|
186
|
6 |
|
$ShipmentItems->clear(); |
|
187
|
6 |
|
foreach ($NewShipmentItems as $NewShipmentItem) { |
|
188
|
6 |
|
$NewShipmentItem->setShipping($Shipping); |
|
189
|
6 |
|
$ShipmentItems->add($NewShipmentItem); |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
6 |
|
$app['orm.em']->persist($TargetOrder); |
|
195
|
6 |
|
$app['orm.em']->flush(); |
|
196
|
|
|
|
|
197
|
6 |
|
$Customer = $TargetOrder->getCustomer(); |
|
198
|
6 |
|
if ($Customer) { |
|
199
|
|
|
// 会員の場合、購入回数、購入金額などを更新 |
|
200
|
6 |
|
$app['eccube.repository.customer']->updateBuyData($app, $Customer, $TargetOrder->getOrderStatus()->getId()); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
|
|
204
|
6 |
|
$event = new EventArgs( |
|
205
|
|
|
array( |
|
206
|
6 |
|
'form' => $form, |
|
207
|
6 |
|
'OriginOrder' => $OriginOrder, |
|
208
|
6 |
|
'TargetOrder' => $TargetOrder, |
|
209
|
6 |
|
'OriginOrderDetails' => $OriginalOrderDetails, |
|
210
|
6 |
|
'Customer' => $Customer, |
|
211
|
|
|
), |
|
212
|
|
|
$request |
|
213
|
|
|
); |
|
214
|
6 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_COMPLETE, $event); |
|
215
|
|
|
|
|
216
|
6 |
|
$app->addSuccess('admin.order.save.complete', 'admin'); |
|
217
|
|
|
|
|
218
|
6 |
|
return $app->redirect($app->url('admin_order_edit', array('id' => $TargetOrder->getId()))); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
1 |
|
break; |
|
222
|
|
|
|
|
223
|
|
|
case 'add_delivery': |
|
224
|
|
|
// お届け先情報の新規追加 |
|
225
|
|
|
|
|
226
|
|
|
$form = $builder->getForm(); |
|
227
|
|
|
|
|
228
|
|
|
$Shipping = new \Eccube\Entity\Shipping(); |
|
229
|
|
|
$Shipping->setDelFlg(Constant::DISABLED); |
|
230
|
|
|
|
|
231
|
|
|
$TargetOrder->addShipping($Shipping); |
|
232
|
|
|
|
|
233
|
|
|
$Shipping->setOrder($TargetOrder); |
|
234
|
|
|
|
|
235
|
|
|
$form->setData($TargetOrder); |
|
236
|
|
|
|
|
237
|
|
|
break; |
|
238
|
|
|
|
|
239
|
|
|
default: |
|
240
|
1 |
|
break; |
|
241
|
|
|
} |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
// 会員検索フォーム |
|
245
|
5 |
|
$builder = $app['form.factory'] |
|
246
|
5 |
|
->createBuilder('admin_search_customer'); |
|
247
|
|
|
|
|
248
|
5 |
|
$event = new EventArgs( |
|
249
|
|
|
array( |
|
250
|
5 |
|
'builder' => $builder, |
|
251
|
5 |
|
'OriginOrder' => $OriginOrder, |
|
252
|
5 |
|
'TargetOrder' => $TargetOrder, |
|
253
|
5 |
|
'OriginOrderDetails' => $OriginalOrderDetails, |
|
254
|
|
|
), |
|
255
|
|
|
$request |
|
256
|
|
|
); |
|
257
|
5 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_INITIALIZE, $event); |
|
258
|
|
|
|
|
259
|
5 |
|
$searchCustomerModalForm = $builder->getForm(); |
|
260
|
|
|
|
|
261
|
|
|
// 商品検索フォーム |
|
262
|
5 |
|
$builder = $app['form.factory'] |
|
263
|
5 |
|
->createBuilder('admin_search_product'); |
|
264
|
|
|
|
|
265
|
5 |
|
$event = new EventArgs( |
|
266
|
|
|
array( |
|
267
|
5 |
|
'builder' => $builder, |
|
268
|
5 |
|
'OriginOrder' => $OriginOrder, |
|
269
|
5 |
|
'TargetOrder' => $TargetOrder, |
|
270
|
5 |
|
'OriginOrderDetails' => $OriginalOrderDetails, |
|
271
|
|
|
), |
|
272
|
|
|
$request |
|
273
|
|
|
); |
|
274
|
5 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_INITIALIZE, $event); |
|
275
|
|
|
|
|
276
|
5 |
|
$searchProductModalForm = $builder->getForm(); |
|
277
|
|
|
|
|
278
|
|
|
// 配送業者のお届け時間 |
|
279
|
5 |
|
$times = array(); |
|
280
|
5 |
|
$deliveries = $app['eccube.repository.delivery']->findAll(); |
|
281
|
5 |
|
foreach ($deliveries as $Delivery) { |
|
282
|
5 |
|
$deliveryTiems = $Delivery->getDeliveryTimes(); |
|
283
|
5 |
|
foreach ($deliveryTiems as $DeliveryTime) { |
|
284
|
5 |
|
$times[$Delivery->getId()][$DeliveryTime->getId()] = $DeliveryTime->getDeliveryTime(); |
|
285
|
|
|
} |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
5 |
|
return $app->render('Order/edit.twig', array( |
|
289
|
5 |
|
'form' => $form->createView(), |
|
290
|
5 |
|
'searchCustomerModalForm' => $searchCustomerModalForm->createView(), |
|
291
|
5 |
|
'searchProductModalForm' => $searchProductModalForm->createView(), |
|
292
|
5 |
|
'Order' => $TargetOrder, |
|
293
|
5 |
|
'id' => $id, |
|
294
|
5 |
|
'shippingDeliveryTimes' => $app['serializer']->serialize($times, 'json'), |
|
295
|
|
|
)); |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* 顧客情報を検索する. |
|
300
|
|
|
* |
|
301
|
|
|
* @param Application $app |
|
302
|
|
|
* @param Request $request |
|
|
|
|
|
|
303
|
|
|
* @return \Symfony\Component\HttpFoundation\JsonResponse |
|
304
|
|
|
*/ |
|
305
|
2 |
|
public function searchCustomer(Application $app, Request $request) |
|
306
|
|
|
{ |
|
307
|
2 |
|
if ($request->isXmlHttpRequest()) { |
|
308
|
2 |
|
$app['monolog']->addDebug('search customer start.'); |
|
309
|
|
|
|
|
310
|
|
|
$searchData = array( |
|
311
|
2 |
|
'multi' => $request->get('search_word'), |
|
312
|
|
|
); |
|
313
|
|
|
|
|
314
|
2 |
|
$qb = $app['eccube.repository.customer']->getQueryBuilderBySearchData($searchData); |
|
315
|
|
|
|
|
316
|
2 |
|
$event = new EventArgs( |
|
317
|
|
|
array( |
|
318
|
2 |
|
'qb' => $qb, |
|
319
|
2 |
|
'data' => $searchData, |
|
320
|
|
|
), |
|
321
|
|
|
$request |
|
322
|
|
|
); |
|
323
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_SEARCH, $event); |
|
324
|
|
|
|
|
325
|
2 |
|
$Customers = $qb->getQuery()->getResult(); |
|
326
|
|
|
|
|
327
|
|
|
|
|
328
|
2 |
|
if (empty($Customers)) { |
|
329
|
|
|
$app['monolog']->addDebug('search customer not found.'); |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
2 |
|
$data = array(); |
|
333
|
|
|
|
|
334
|
2 |
|
$formatTel = '%s-%s-%s'; |
|
335
|
2 |
|
$formatName = '%s%s(%s%s)'; |
|
336
|
2 |
|
foreach ($Customers as $Customer) { |
|
337
|
2 |
|
$data[] = array( |
|
338
|
2 |
|
'id' => $Customer->getId(), |
|
339
|
2 |
|
'name' => sprintf($formatName, $Customer->getName01(), $Customer->getName02(), $Customer->getKana01(), |
|
340
|
2 |
|
$Customer->getKana02()), |
|
341
|
2 |
|
'tel' => sprintf($formatTel, $Customer->getTel01(), $Customer->getTel02(), $Customer->getTel03()), |
|
342
|
|
|
); |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
2 |
|
$event = new EventArgs( |
|
346
|
|
|
array( |
|
347
|
2 |
|
'data' => $data, |
|
348
|
2 |
|
'Customers' => $Customers, |
|
349
|
|
|
), |
|
350
|
|
|
$request |
|
351
|
|
|
); |
|
352
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_COMPLETE, $event); |
|
353
|
2 |
|
$data = $event->getArgument('data'); |
|
354
|
|
|
|
|
355
|
2 |
|
return $app->json($data); |
|
356
|
|
|
} |
|
357
|
|
|
} |
|
358
|
|
|
|
|
359
|
|
|
/** |
|
360
|
|
|
* 顧客情報を検索する. |
|
361
|
|
|
* |
|
362
|
|
|
* @param Application $app |
|
363
|
|
|
* @param Request $request |
|
|
|
|
|
|
364
|
|
|
* @return \Symfony\Component\HttpFoundation\JsonResponse |
|
365
|
|
|
*/ |
|
366
|
2 |
|
public function searchCustomerById(Application $app, Request $request) |
|
367
|
|
|
{ |
|
368
|
2 |
|
if ($request->isXmlHttpRequest()) { |
|
369
|
2 |
|
$app['monolog']->addDebug('search customer by id start.'); |
|
370
|
|
|
|
|
371
|
|
|
/** @var $Customer \Eccube\Entity\Customer */ |
|
372
|
2 |
|
$Customer = $app['eccube.repository.customer'] |
|
373
|
2 |
|
->find($request->get('id')); |
|
374
|
|
|
|
|
375
|
2 |
|
$event = new EventArgs( |
|
376
|
|
|
array( |
|
377
|
2 |
|
'Customer' => $Customer, |
|
378
|
|
|
), |
|
379
|
|
|
$request |
|
380
|
|
|
); |
|
381
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_INITIALIZE, $event); |
|
382
|
|
|
|
|
383
|
2 |
|
if (is_null($Customer)) { |
|
384
|
|
|
$app['monolog']->addDebug('search customer by id not found.'); |
|
385
|
|
|
|
|
386
|
|
|
return $app->json(array(), 404); |
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
2 |
|
$app['monolog']->addDebug('search customer by id found.'); |
|
390
|
|
|
|
|
391
|
|
|
$data = array( |
|
392
|
2 |
|
'id' => $Customer->getId(), |
|
393
|
2 |
|
'name01' => $Customer->getName01(), |
|
394
|
2 |
|
'name02' => $Customer->getName02(), |
|
395
|
2 |
|
'kana01' => $Customer->getKana01(), |
|
396
|
2 |
|
'kana02' => $Customer->getKana02(), |
|
397
|
2 |
|
'zip01' => $Customer->getZip01(), |
|
398
|
2 |
|
'zip02' => $Customer->getZip02(), |
|
399
|
2 |
|
'pref' => is_null($Customer->getPref()) ? null : $Customer->getPref()->getId(), |
|
400
|
2 |
|
'addr01' => $Customer->getAddr01(), |
|
401
|
2 |
|
'addr02' => $Customer->getAddr02(), |
|
402
|
2 |
|
'email' => $Customer->getEmail(), |
|
403
|
2 |
|
'tel01' => $Customer->getTel01(), |
|
404
|
2 |
|
'tel02' => $Customer->getTel02(), |
|
405
|
2 |
|
'tel03' => $Customer->getTel03(), |
|
406
|
2 |
|
'fax01' => $Customer->getFax01(), |
|
407
|
2 |
|
'fax02' => $Customer->getFax02(), |
|
408
|
2 |
|
'fax03' => $Customer->getFax03(), |
|
409
|
2 |
|
'company_name' => $Customer->getCompanyName(), |
|
410
|
|
|
); |
|
411
|
|
|
|
|
412
|
2 |
|
$event = new EventArgs( |
|
413
|
|
|
array( |
|
414
|
2 |
|
'data' => $data, |
|
415
|
2 |
|
'Customer' => $Customer, |
|
416
|
|
|
), |
|
417
|
|
|
$request |
|
418
|
|
|
); |
|
419
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_COMPLETE, $event); |
|
420
|
2 |
|
$data = $event->getArgument('data'); |
|
421
|
|
|
|
|
422
|
2 |
|
return $app->json($data); |
|
423
|
|
|
} |
|
424
|
|
|
} |
|
425
|
|
|
|
|
426
|
2 |
|
public function searchProduct(Application $app, Request $request) |
|
|
|
|
|
|
427
|
|
|
{ |
|
428
|
2 |
|
if ($request->isXmlHttpRequest()) { |
|
429
|
2 |
|
$app['monolog']->addDebug('search product start.'); |
|
430
|
|
|
|
|
431
|
|
|
$searchData = array( |
|
432
|
2 |
|
'name' => $request->get('id'), |
|
433
|
|
|
); |
|
434
|
|
|
|
|
435
|
2 |
|
if ($categoryId = $request->get('category_id')) { |
|
436
|
|
|
$Category = $app['eccube.repository.category']->find($categoryId); |
|
437
|
|
|
$searchData['category_id'] = $Category; |
|
438
|
|
|
} |
|
439
|
|
|
|
|
440
|
|
|
/** @var $Products \Eccube\Entity\Product[] */ |
|
441
|
2 |
|
$qb = $app['eccube.repository.product'] |
|
442
|
2 |
|
->getQueryBuilderBySearchData($searchData); |
|
443
|
|
|
|
|
444
|
2 |
|
$event = new EventArgs( |
|
445
|
|
|
array( |
|
446
|
2 |
|
'qb' => $qb, |
|
447
|
2 |
|
'searchData' => $searchData, |
|
448
|
|
|
), |
|
449
|
|
|
$request |
|
450
|
|
|
); |
|
451
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_SEARCH, $event); |
|
452
|
|
|
|
|
453
|
|
|
/** @var $Products \Eccube\Entity\Product[] */ |
|
454
|
2 |
|
$Products = $qb->getQuery()->getResult(); |
|
455
|
|
|
|
|
456
|
2 |
|
if (empty($Products)) { |
|
457
|
2 |
|
$app['monolog']->addDebug('search product not found.'); |
|
458
|
|
|
} |
|
459
|
|
|
|
|
460
|
2 |
|
$forms = array(); |
|
461
|
2 |
|
foreach ($Products as $Product) { |
|
462
|
|
|
/* @var $builder \Symfony\Component\Form\FormBuilderInterface */ |
|
463
|
|
|
$builder = $app['form.factory']->createNamedBuilder('', 'add_cart', null, array( |
|
464
|
|
|
'product' => $Product, |
|
465
|
|
|
)); |
|
466
|
|
|
$addCartForm = $builder->getForm(); |
|
467
|
2 |
|
$forms[$Product->getId()] = $addCartForm->createView(); |
|
468
|
|
|
} |
|
469
|
|
|
|
|
470
|
2 |
|
$event = new EventArgs( |
|
471
|
|
|
array( |
|
472
|
2 |
|
'forms' => $forms, |
|
473
|
2 |
|
'Products' => $Products, |
|
474
|
|
|
), |
|
475
|
|
|
$request |
|
476
|
|
|
); |
|
477
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_COMPLETE, $event); |
|
478
|
|
|
|
|
479
|
2 |
|
return $app->render('Order/search_product.twig', array( |
|
480
|
2 |
|
'forms' => $forms, |
|
481
|
2 |
|
'Products' => $Products, |
|
482
|
|
|
)); |
|
483
|
|
|
} |
|
484
|
|
|
} |
|
485
|
|
|
|
|
486
|
4 |
|
protected function newOrder() |
|
487
|
|
|
{ |
|
488
|
4 |
|
$Order = new \Eccube\Entity\Order(); |
|
489
|
4 |
|
$Shipping = new \Eccube\Entity\Shipping(); |
|
490
|
4 |
|
$Shipping->setDelFlg(0); |
|
491
|
4 |
|
$Order->addShipping($Shipping); |
|
492
|
4 |
|
$Shipping->setOrder($Order); |
|
493
|
|
|
|
|
494
|
4 |
|
return $Order; |
|
495
|
|
|
} |
|
496
|
|
|
|
|
497
|
|
|
/** |
|
498
|
|
|
* フォームからの入直内容に基づいて、受注情報の再計算を行う |
|
499
|
|
|
* |
|
500
|
|
|
* @param $app |
|
501
|
|
|
* @param $Order |
|
502
|
|
|
*/ |
|
503
|
6 |
|
protected function calculate($app, \Eccube\Entity\Order $Order) |
|
504
|
|
|
{ |
|
505
|
6 |
|
$taxtotal = 0; |
|
506
|
6 |
|
$subtotal = 0; |
|
507
|
|
|
|
|
508
|
|
|
// 受注明細データの税・小計を再計算 |
|
509
|
|
|
/** @var $OrderDetails \Eccube\Entity\OrderDetail[] */ |
|
510
|
6 |
|
$OrderDetails = $Order->getOrderDetails(); |
|
511
|
6 |
|
foreach ($OrderDetails as $OrderDetail) { |
|
512
|
|
|
// 新規登録の場合は, 入力されたproduct_id/produc_class_idから明細にセットする. |
|
513
|
6 |
|
if (!$OrderDetail->getId()) { |
|
514
|
2 |
|
$TaxRule = $app['eccube.repository.tax_rule']->getByRule($OrderDetail->getProduct(), |
|
515
|
2 |
|
$OrderDetail->getProductClass()); |
|
516
|
2 |
|
$OrderDetail->setTaxRule($TaxRule->getCalcRule()->getId()); |
|
517
|
2 |
|
$OrderDetail->setProductName($OrderDetail->getProduct()->getName()); |
|
518
|
2 |
|
$OrderDetail->setProductCode($OrderDetail->getProductClass()->getCode()); |
|
519
|
2 |
|
$OrderDetail->setClassName1($OrderDetail->getProductClass()->hasClassCategory1() |
|
520
|
|
|
? $OrderDetail->getProductClass()->getClassCategory1()->getClassName()->getName() |
|
521
|
2 |
|
: null); |
|
|
|
|
|
|
522
|
2 |
|
$OrderDetail->setClassName2($OrderDetail->getProductClass()->hasClassCategory2() |
|
523
|
|
|
? $OrderDetail->getProductClass()->getClassCategory2()->getClassName()->getName() |
|
524
|
2 |
|
: null); |
|
|
|
|
|
|
525
|
2 |
|
$OrderDetail->setClassCategoryName1($OrderDetail->getProductClass()->hasClassCategory1() |
|
526
|
|
|
? $OrderDetail->getProductClass()->getClassCategory1()->getName() |
|
527
|
2 |
|
: null); |
|
|
|
|
|
|
528
|
2 |
|
$OrderDetail->setClassCategoryName2($OrderDetail->getProductClass()->hasClassCategory2() |
|
529
|
|
|
? $OrderDetail->getProductClass()->getClassCategory2()->getName() |
|
530
|
2 |
|
: null); |
|
|
|
|
|
|
531
|
|
|
} |
|
532
|
|
|
|
|
533
|
|
|
// 税 |
|
534
|
6 |
|
$tax = $app['eccube.service.tax_rule'] |
|
535
|
6 |
|
->calcTax($OrderDetail->getPrice(), $OrderDetail->getTaxRate(), $OrderDetail->getTaxRule()); |
|
536
|
6 |
|
$OrderDetail->setPriceIncTax($OrderDetail->getPrice() + $tax); |
|
537
|
|
|
|
|
538
|
6 |
|
$taxtotal += $tax * $OrderDetail->getQuantity(); |
|
539
|
|
|
|
|
540
|
|
|
// 小計 |
|
541
|
6 |
|
$subtotal += $OrderDetail->getTotalPrice(); |
|
542
|
|
|
} |
|
543
|
|
|
|
|
544
|
6 |
|
$shippings = $Order->getShippings(); |
|
545
|
|
|
/** @var \Eccube\Entity\Shipping $Shipping */ |
|
546
|
6 |
|
foreach ($shippings as $Shipping) { |
|
547
|
6 |
|
$shipmentItems = $Shipping->getShipmentItems(); |
|
548
|
6 |
|
$Shipping->setDelFlg(Constant::DISABLED); |
|
549
|
|
|
/** @var \Eccube\Entity\ShipmentItem $ShipmentItem */ |
|
550
|
6 |
|
foreach ($shipmentItems as $ShipmentItem) { |
|
551
|
4 |
|
$ShipmentItem->setProductName($ShipmentItem->getProduct()->getName()); |
|
552
|
4 |
|
$ShipmentItem->setProductCode($ShipmentItem->getProductClass()->getCode()); |
|
553
|
4 |
|
$ShipmentItem->setClassName1($ShipmentItem->getProductClass()->hasClassCategory1() |
|
554
|
|
|
? $ShipmentItem->getProductClass()->getClassCategory1()->getClassName()->getName() |
|
555
|
4 |
|
: null); |
|
|
|
|
|
|
556
|
4 |
|
$ShipmentItem->setClassName2($ShipmentItem->getProductClass()->hasClassCategory2() |
|
557
|
|
|
? $ShipmentItem->getProductClass()->getClassCategory2()->getClassName()->getName() |
|
558
|
4 |
|
: null); |
|
|
|
|
|
|
559
|
4 |
|
$ShipmentItem->setClassCategoryName1($ShipmentItem->getProductClass()->hasClassCategory1() |
|
560
|
|
|
? $ShipmentItem->getProductClass()->getClassCategory1()->getName() |
|
561
|
4 |
|
: null); |
|
|
|
|
|
|
562
|
4 |
|
$ShipmentItem->setClassCategoryName2($ShipmentItem->getProductClass()->hasClassCategory2() |
|
563
|
|
|
? $ShipmentItem->getProductClass()->getClassCategory2()->getName() |
|
564
|
6 |
|
: null); |
|
|
|
|
|
|
565
|
|
|
} |
|
566
|
|
|
} |
|
567
|
|
|
|
|
568
|
|
|
// 受注データの税・小計・合計を再計算 |
|
569
|
6 |
|
$Order->setTax($taxtotal); |
|
570
|
6 |
|
$Order->setSubtotal($subtotal); |
|
571
|
6 |
|
$Order->setTotal($subtotal + $Order->getCharge() + $Order->getDeliveryFeeTotal() - $Order->getDiscount()); |
|
572
|
|
|
// お支払い合計は、totalと同一金額(2系ではtotal - point) |
|
573
|
6 |
|
$Order->setPaymentTotal($Order->getTotal()); |
|
574
|
|
|
} |
|
575
|
|
|
|
|
576
|
|
|
/** |
|
577
|
|
|
* 受注ステータスに応じて, 受注日/入金日/発送日を更新する, |
|
578
|
|
|
* 発送済ステータスが設定された場合は, お届け先情報の発送日も更新を行う. |
|
579
|
|
|
* |
|
580
|
|
|
* 編集の場合 |
|
581
|
|
|
* - 受注ステータスが他のステータスから発送済へ変更された場合に発送日を更新 |
|
582
|
|
|
* - 受注ステータスが他のステータスから入金済へ変更された場合に入金日を更新 |
|
583
|
|
|
* |
|
584
|
|
|
* 新規登録の場合 |
|
585
|
|
|
* - 受注日を更新 |
|
586
|
|
|
* - 受注ステータスが発送済に設定された場合に発送日を更新 |
|
587
|
|
|
* - 受注ステータスが入金済に設定された場合に入金日を更新 |
|
588
|
|
|
* |
|
589
|
|
|
* |
|
590
|
|
|
* @param $app |
|
591
|
|
|
* @param $TargetOrder |
|
592
|
|
|
* @param $OriginOrder |
|
593
|
|
|
*/ |
|
594
|
6 |
|
protected function updateDate($app, $TargetOrder, $OriginOrder) |
|
595
|
|
|
{ |
|
596
|
6 |
|
$dateTime = new \DateTime(); |
|
597
|
|
|
|
|
598
|
|
|
// 編集 |
|
599
|
6 |
|
if ($TargetOrder->getId()) { |
|
600
|
|
|
// 発送済 |
|
601
|
4 |
|
if ($TargetOrder->getOrderStatus()->getId() == $app['config']['order_deliv']) { |
|
602
|
|
|
// 編集前と異なる場合のみ更新 |
|
603
|
|
|
if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) { |
|
604
|
|
|
$TargetOrder->setCommitDate($dateTime); |
|
605
|
|
|
// お届け先情報の発送日も更新する. |
|
606
|
|
|
$Shippings = $TargetOrder->getShippings(); |
|
607
|
|
|
foreach ($Shippings as $Shipping) { |
|
608
|
|
|
$Shipping->setShippingCommitDate($dateTime); |
|
609
|
|
|
} |
|
610
|
|
|
} |
|
611
|
|
|
// 入金済 |
|
612
|
4 |
|
} elseif ($TargetOrder->getOrderStatus()->getId() == $app['config']['order_pre_end']) { |
|
613
|
|
|
// 編集前と異なる場合のみ更新 |
|
614
|
|
|
if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) { |
|
615
|
4 |
|
$TargetOrder->setPaymentDate($dateTime); |
|
616
|
|
|
} |
|
617
|
|
|
} |
|
618
|
|
|
// 新規 |
|
619
|
|
|
} else { |
|
620
|
|
|
// 発送済 |
|
621
|
2 |
|
if ($TargetOrder->getOrderStatus()->getId() == $app['config']['order_deliv']) { |
|
622
|
|
|
$TargetOrder->setCommitDate($dateTime); |
|
623
|
|
|
// お届け先情報の発送日も更新する. |
|
624
|
|
|
$Shippings = $TargetOrder->getShippings(); |
|
625
|
|
|
foreach ($Shippings as $Shipping) { |
|
626
|
|
|
$Shipping->setShippingCommitDate($dateTime); |
|
627
|
|
|
} |
|
628
|
|
|
// 入金済 |
|
629
|
2 |
|
} elseif ($TargetOrder->getOrderStatus()->getId() == $app['config']['order_pre_end']) { |
|
630
|
|
|
$TargetOrder->setPaymentDate($dateTime); |
|
631
|
|
|
} |
|
632
|
|
|
// 受注日時 |
|
633
|
2 |
|
$TargetOrder->setOrderDate($dateTime); |
|
634
|
|
|
} |
|
635
|
|
|
} |
|
636
|
|
|
} |
|
637
|
|
|
|