Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like EditController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use EditController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
49 | class EditController extends AbstractController |
||
50 | { |
||
51 | /** |
||
52 | * 受注登録/編集画面. |
||
53 | * |
||
54 | * @Route("/edit", name="admin_order_new") |
||
55 | * @Route("/{id}/edit", requirements={"id" = "\d+"}, name="admin_order_edit") |
||
56 | * @Template("Order/edit.twig") |
||
57 | * |
||
58 | * TODO templateアノテーションを利用するかどうか検討.http://symfony.com/doc/current/best_practices/controllers.html |
||
59 | 17 | */ |
|
60 | public function index(Application $app, Request $request, $id = null) |
||
61 | { |
||
62 | 17 | /* @var $softDeleteFilter \Eccube\Doctrine\Filter\SoftDeleteFilter */ |
|
63 | 17 | $softDeleteFilter = $app['orm.em']->getFilters()->getFilter('soft_delete'); |
|
64 | 17 | $softDeleteFilter->setExcludes(array( |
|
65 | 'Eccube\Entity\ProductClass', |
||
66 | 'Eccube\Entity\Product', |
||
67 | )); |
||
68 | 17 | ||
69 | 17 | $TargetOrder = null; |
|
70 | $OriginOrder = null; |
||
71 | 17 | ||
72 | if (is_null($id)) { |
||
73 | 7 | // 空のエンティティを作成. |
|
74 | $TargetOrder = $this->newOrder($app); |
||
75 | 10 | } else { |
|
76 | 10 | $TargetOrder = $app['eccube.repository.order']->find($id); |
|
77 | if (is_null($TargetOrder)) { |
||
78 | throw new NotFoundHttpException(); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | 17 | // 編集前の受注情報を保持 |
|
83 | 17 | $OriginOrder = clone $TargetOrder; |
|
84 | $OriginalOrderDetails = new ArrayCollection(); |
||
85 | 17 | // 編集前のお届け先情報を保持 |
|
86 | 17 | $OriginalShippings = new ArrayCollection(); |
|
87 | // 編集前のお届け先のアイテム情報を保持 |
||
88 | $OriginalShipmentItems = new ArrayCollection(); |
||
89 | 17 | ||
90 | 17 | foreach ($TargetOrder->getOrderDetails() as $OrderDetail) { |
|
91 | $OriginalOrderDetails->add($OrderDetail); |
||
92 | 17 | } |
|
93 | |||
94 | 17 | // 編集前の情報を保持 |
|
95 | 17 | foreach ($TargetOrder->getShippings() as $tmpOriginalShippings) { |
|
96 | 17 | foreach ($tmpOriginalShippings->getShipmentItems() as $tmpOriginalShipmentItem) { |
|
97 | 17 | // アイテム情報 |
|
98 | $OriginalShipmentItems->add($tmpOriginalShipmentItem); |
||
99 | } |
||
100 | // お届け先情報 |
||
101 | 17 | $OriginalShippings->add($tmpOriginalShippings); |
|
102 | } |
||
103 | 17 | ||
104 | 17 | $builder = $app['form.factory'] |
|
105 | ->createBuilder(OrderType::class, $TargetOrder); |
||
106 | 17 | ||
107 | 11 | $event = new EventArgs( |
|
108 | array( |
||
109 | 11 | 'builder' => $builder, |
|
110 | 11 | 'OriginOrder' => $OriginOrder, |
|
111 | 11 | 'TargetOrder' => $TargetOrder, |
|
112 | 11 | 'OriginOrderDetails' => $OriginalOrderDetails, |
|
113 | ), |
||
114 | $request |
||
115 | ); |
||
116 | 11 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_INITIALIZE, $event); |
|
117 | |||
118 | $form = $builder->getForm(); |
||
119 | $form->handleRequest($request); |
||
120 | |||
121 | if ($form->isSubmitted()) { |
||
122 | $event = new EventArgs( |
||
123 | 11 | array( |
|
124 | 'builder' => $builder, |
||
125 | 'OriginOrder' => $OriginOrder, |
||
126 | 11 | 'TargetOrder' => $TargetOrder, |
|
127 | 11 | 'OriginOrderDetails' => $OriginalOrderDetails, |
|
128 | ), |
||
129 | 11 | $request |
|
130 | ); |
||
131 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_PROGRESS, $event); |
||
132 | 11 | ||
133 | // 入力情報にもとづいて再計算. |
||
134 | // TODO 購入フローのように、明細の自動生成をどこまで行うか検討する. 単純集計でよいような気がする |
||
135 | 11 | // 集計は,この1行でいけるはず |
|
136 | // プラグインで Strategy をセットしたりする |
||
137 | 11 | // TODO 編集前のOrder情報が必要かもしれない |
|
138 | $app['eccube.service.calculate']($TargetOrder, $TargetOrder->getCustomer())->calculate(); |
||
139 | |||
140 | // 登録ボタン押下 |
||
141 | 11 | switch ($request->get('mode')) { |
|
142 | case 'register': |
||
143 | |||
144 | 11 | log_info('受注登録開始', array($TargetOrder->getId())); |
|
145 | 7 | ||
146 | 11 | // TODO 在庫の有無や販売制限数のチェックなども行う必要があるため、完了処理もcaluclatorのように抽象化できないか検討する. |
|
147 | if ($TargetOrder->getTotal() > $app['config']['max_total_fee']) { |
||
148 | log_info('受注登録入力チェックエラー', array($TargetOrder->getId())); |
||
149 | $form['charge']->addError(new FormError('合計金額の上限を超えております。')); |
||
150 | } elseif ($form->isValid()) { |
||
151 | 11 | ||
152 | 4 | $BaseInfo = $app['eccube.repository.base_info']->get(); |
|
153 | 4 | ||
154 | // TODO 後続にある会員情報の更新のように、完了処理もcaluclatorのように抽象化できないか検討する. |
||
155 | 4 | // 受注日/発送日/入金日の更新. |
|
156 | 4 | $this->updateDate($app, $TargetOrder, $OriginOrder); |
|
157 | 4 | ||
158 | 4 | // 画面上で削除された明細は、受注明細で削除されているものをremove |
|
159 | 4 | foreach ($OriginalOrderDetails as $OrderDetail) { |
|
160 | 4 | if (false === $TargetOrder->getOrderDetails()->contains($OrderDetail)) { |
|
161 | 4 | $app['orm.em']->remove($OrderDetail); |
|
162 | } |
||
163 | 4 | } |
|
164 | 4 | ||
165 | // 複数配送の場合, |
||
166 | if ($BaseInfo->getOptionMultipleShipping() == Constant::ENABLED) { |
||
167 | foreach ($TargetOrder->getOrderDetails() as $OrderDetail) { |
||
168 | $OrderDetail->setOrder($TargetOrder); |
||
169 | 7 | } |
|
170 | 7 | $Shippings = $TargetOrder->getShippings(); |
|
171 | 4 | foreach ($Shippings as $Shipping) { |
|
172 | 7 | $shipmentItems = $Shipping->getShipmentItems(); |
|
173 | foreach ($shipmentItems as $ShipmentItem) { |
||
174 | 7 | // 削除予定から商品アイテムを外す |
|
175 | 7 | $OriginalShipmentItems->removeElement($ShipmentItem); |
|
176 | 7 | $ShipmentItem->setOrder($TargetOrder); |
|
177 | 7 | $ShipmentItem->setShipping($Shipping); |
|
178 | 7 | $app['orm.em']->persist($ShipmentItem); |
|
179 | 7 | } |
|
180 | 7 | // 削除予定からお届け先情報を外す |
|
181 | $OriginalShippings->removeElement($Shipping); |
||
182 | $Shipping->setOrder($TargetOrder); |
||
183 | $app['orm.em']->persist($Shipping); |
||
184 | } |
||
185 | 11 | // 商品アイテムを削除する |
|
186 | 11 | foreach ($OriginalShipmentItems as $OriginalShipmentItem) { |
|
187 | $app['orm.em']->remove($OriginalShipmentItem); |
||
188 | } |
||
189 | // お届け先情報削除する |
||
190 | foreach ($OriginalShippings as $OriginalShipping) { |
||
191 | $app['orm.em']->remove($OriginalShipping); |
||
192 | } |
||
193 | } else { |
||
194 | 11 | // 単一配送の場合, ShippimentItemsはOrderDetailの内容をコピーし、delete/insertで作り直す. |
|
195 | // TODO あまり本質的な処理ではないので簡略化したい. |
||
196 | 11 | $Shipping = $TargetOrder->getShippings()->first(); |
|
197 | 11 | foreach ($Shipping->getShipmentItems() as $ShipmentItem) { |
|
198 | 11 | $Shipping->removeShipmentItem($ShipmentItem); |
|
199 | 11 | $app['orm.em']->remove($ShipmentItem); |
|
200 | } |
||
201 | foreach ($TargetOrder->getOrderDetails() as $OrderDetail) { |
||
202 | $OrderDetail->setOrder($TargetOrder); |
||
203 | if ($OrderDetail->getProduct()) { |
||
204 | 11 | $ShipmentItem = new ShipmentItem(); |
|
205 | $ShipmentItem->copyProperties($OrderDetail); |
||
206 | 11 | $ShipmentItem->setShipping($Shipping); |
|
207 | $Shipping->addShipmentItem($ShipmentItem); |
||
208 | 11 | } |
|
209 | } |
||
210 | 11 | } |
|
211 | |||
212 | $app['orm.em']->persist($TargetOrder); |
||
213 | $app['orm.em']->flush(); |
||
214 | |||
215 | // TODO 集計系に移動 |
||
216 | // if ($Customer) { |
||
217 | // // 会員の場合、購入回数、購入金額などを更新 |
||
218 | // $app['eccube.repository.customer']->updateBuyData($app, $Customer, $TargetOrder->getOrderStatus()->getId()); |
||
219 | // } |
||
220 | |||
221 | $event = new EventArgs( |
||
222 | array( |
||
223 | 'form' => $form, |
||
224 | 'OriginOrder' => $OriginOrder, |
||
225 | 'TargetOrder' => $TargetOrder, |
||
226 | 'OriginOrderDetails' => $OriginalOrderDetails, |
||
227 | //'Customer' => $Customer, |
||
228 | ), |
||
229 | $request |
||
230 | ); |
||
231 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_COMPLETE, $event); |
||
232 | |||
233 | $app->addSuccess('admin.order.save.complete', 'admin'); |
||
234 | |||
235 | 6 | log_info('受注登録完了', array($TargetOrder->getId())); |
|
236 | 6 | ||
237 | return $app->redirect($app->url('admin_order_edit', array('id' => $TargetOrder->getId()))); |
||
238 | 6 | } |
|
239 | |||
240 | 6 | break; |
|
241 | 6 | ||
242 | 6 | case 'add_delivery': |
|
243 | 6 | // お届け先情報の新規追加 |
|
244 | |||
245 | $form = $builder->getForm(); |
||
246 | |||
247 | 6 | $Shipping = new \Eccube\Entity\Shipping(); |
|
248 | $TargetOrder->addShipping($Shipping); |
||
249 | 6 | ||
250 | $Shipping->setOrder($TargetOrder); |
||
251 | |||
252 | 6 | $form->setData($TargetOrder); |
|
253 | 6 | ||
254 | break; |
||
255 | 6 | ||
256 | default: |
||
257 | 6 | break; |
|
258 | 6 | } |
|
259 | 6 | } |
|
260 | 6 | ||
261 | // 会員検索フォーム |
||
262 | $builder = $app['form.factory'] |
||
263 | ->createBuilder(SearchCustomerType::class); |
||
264 | 6 | ||
265 | $event = new EventArgs( |
||
266 | 6 | array( |
|
267 | 'builder' => $builder, |
||
268 | 'OriginOrder' => $OriginOrder, |
||
269 | 6 | 'TargetOrder' => $TargetOrder, |
|
270 | 6 | 'OriginOrderDetails' => $OriginalOrderDetails, |
|
271 | 6 | ), |
|
272 | 6 | $request |
|
273 | 6 | ); |
|
274 | 6 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_INITIALIZE, $event); |
|
275 | |||
276 | $searchCustomerModalForm = $builder->getForm(); |
||
277 | |||
278 | // 商品検索フォーム |
||
279 | 6 | $builder = $app['form.factory'] |
|
280 | 6 | ->createBuilder(SearchProductType::class); |
|
281 | 6 | ||
282 | 6 | $event = new EventArgs( |
|
283 | 6 | array( |
|
284 | 6 | 'builder' => $builder, |
|
285 | 'OriginOrder' => $OriginOrder, |
||
286 | 'TargetOrder' => $TargetOrder, |
||
287 | 'OriginOrderDetails' => $OriginalOrderDetails, |
||
288 | ), |
||
289 | $request |
||
290 | ); |
||
291 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_INITIALIZE, $event); |
||
292 | |||
293 | $searchProductModalForm = $builder->getForm(); |
||
294 | |||
295 | 5 | // 配送業者のお届け時間 |
|
296 | $times = array(); |
||
297 | 5 | $deliveries = $app['eccube.repository.delivery']->findAll(); |
|
298 | 5 | foreach ($deliveries as $Delivery) { |
|
299 | $deliveryTiems = $Delivery->getDeliveryTimes(); |
||
300 | foreach ($deliveryTiems as $DeliveryTime) { |
||
301 | 5 | $times[$Delivery->getId()][$DeliveryTime->getId()] = $DeliveryTime->getDeliveryTime(); |
|
302 | } |
||
303 | } |
||
304 | 5 | ||
305 | return [ |
||
306 | 5 | 'form' => $form->createView(), |
|
307 | 'searchCustomerModalForm' => $searchCustomerModalForm->createView(), |
||
308 | 5 | 'searchProductModalForm' => $searchProductModalForm->createView(), |
|
309 | 5 | 'Order' => $TargetOrder, |
|
310 | 'id' => $id, |
||
311 | 'shippingDeliveryTimes' => $app['serializer']->serialize($times, 'json'), |
||
312 | ]; |
||
313 | 5 | } |
|
314 | |||
315 | 5 | /** |
|
316 | * 顧客情報を検索する. |
||
317 | * |
||
318 | 5 | * @param Application $app |
|
319 | * @param Request $request |
||
320 | * @return \Symfony\Component\HttpFoundation\JsonResponse |
||
321 | */ |
||
322 | 5 | public function searchCustomer(Application $app, Request $request) |
|
323 | { |
||
324 | 5 | if ($request->isXmlHttpRequest()) { |
|
325 | 5 | $app['monolog']->addDebug('search customer start.'); |
|
326 | 5 | ||
327 | 5 | $searchData = array( |
|
328 | 5 | 'multi' => $request->get('search_word'), |
|
329 | 5 | ); |
|
330 | 5 | ||
331 | 5 | $qb = $app['eccube.repository.customer']->getQueryBuilderBySearchData($searchData); |
|
332 | 5 | ||
333 | $event = new EventArgs( |
||
334 | array( |
||
335 | 'qb' => $qb, |
||
336 | 5 | 'data' => $searchData, |
|
337 | ), |
||
338 | 5 | $request |
|
339 | 5 | ); |
|
340 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_SEARCH, $event); |
||
341 | |||
342 | $Customers = $qb->getQuery()->getResult(); |
||
343 | 5 | ||
344 | 5 | ||
345 | if (empty($Customers)) { |
||
346 | 5 | $app['monolog']->addDebug('search customer not found.'); |
|
347 | } |
||
348 | |||
349 | $data = array(); |
||
350 | |||
351 | $formatTel = '%s-%s-%s'; |
||
352 | $formatName = '%s%s(%s%s)'; |
||
353 | View Code Duplication | foreach ($Customers as $Customer) { |
|
354 | $data[] = array( |
||
355 | 'id' => $Customer->getId(), |
||
356 | 'name' => sprintf($formatName, $Customer->getName01(), $Customer->getName02(), $Customer->getKana01(), |
||
357 | $Customer->getKana02()), |
||
358 | 1 | 'tel' => sprintf($formatTel, $Customer->getTel01(), $Customer->getTel02(), $Customer->getTel03()), |
|
359 | 'email' => $Customer->getEmail(), |
||
360 | 1 | ); |
|
361 | 1 | } |
|
362 | 1 | ||
363 | 1 | $event = new EventArgs( |
|
364 | array( |
||
365 | 1 | 'data' => $data, |
|
366 | 'Customers' => $Customers, |
||
367 | 1 | ), |
|
368 | $request |
||
369 | ); |
||
370 | 1 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_COMPLETE, $event); |
|
371 | $data = $event->getArgument('data'); |
||
372 | |||
373 | 1 | return $app->json($data); |
|
374 | 1 | } |
|
375 | } |
||
376 | |||
377 | /** |
||
378 | * 顧客情報を検索する. |
||
379 | * |
||
380 | * @param Application $app |
||
381 | * @param Request $request |
||
382 | * @param integer $page_no |
||
383 | * @return \Symfony\Component\HttpFoundation\JsonResponse |
||
384 | 1 | */ |
|
385 | public function searchCustomerHtml(Application $app, Request $request, $page_no = null) |
||
386 | 1 | { |
|
387 | if ($request->isXmlHttpRequest()) { |
||
388 | 1 | $app['monolog']->addDebug('search customer start.'); |
|
389 | 1 | $page_count = $app['config']['default_page_count']; |
|
390 | $session = $app['session']; |
||
391 | |||
392 | if ('POST' === $request->getMethod()) { |
||
393 | 1 | ||
394 | $page_no = 1; |
||
395 | |||
396 | 1 | $searchData = array( |
|
397 | 'multi' => $request->get('search_word'), |
||
398 | ); |
||
399 | |||
400 | 1 | $session->set('eccube.admin.order.customer.search', $searchData); |
|
401 | $session->set('eccube.admin.order.customer.search.page_no', $page_no); |
||
402 | } else { |
||
403 | $searchData = (array)$session->get('eccube.admin.order.customer.search'); |
||
404 | 1 | if (is_null($page_no)) { |
|
405 | $page_no = intval($session->get('eccube.admin.order.customer.search.page_no')); |
||
406 | 1 | } else { |
|
407 | $session->set('eccube.admin.order.customer.search.page_no', $page_no); |
||
408 | } |
||
409 | } |
||
410 | 1 | ||
411 | $qb = $app['eccube.repository.customer']->getQueryBuilderBySearchData($searchData); |
||
412 | 1 | ||
413 | 1 | $event = new EventArgs( |
|
414 | 1 | array( |
|
415 | 1 | 'qb' => $qb, |
|
416 | 1 | 'data' => $searchData, |
|
417 | 1 | ), |
|
418 | 1 | $request |
|
419 | 1 | ); |
|
420 | 1 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_SEARCH, $event); |
|
421 | |||
422 | /** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */ |
||
423 | $pagination = $app['paginator']()->paginate( |
||
424 | 1 | $qb, |
|
425 | $page_no, |
||
426 | 1 | $page_count, |
|
427 | 1 | array('wrap-queries' => true) |
|
428 | ); |
||
429 | |||
430 | /** @var $Customers \Eccube\Entity\Customer[] */ |
||
431 | 1 | $Customers = $pagination->getItems(); |
|
432 | 1 | ||
433 | if (empty($Customers)) { |
||
434 | 1 | $app['monolog']->addDebug('search customer not found.'); |
|
435 | 1 | } |
|
436 | 1 | ||
437 | $data = array(); |
||
438 | |||
439 | $formatTel = '%s-%s-%s'; |
||
440 | $formatName = '%s%s(%s%s)'; |
||
441 | View Code Duplication | foreach ($Customers as $Customer) { |
|
442 | $data[] = array( |
||
443 | 'id' => $Customer->getId(), |
||
444 | 'name' => sprintf($formatName, $Customer->getName01(), $Customer->getName02(), $Customer->getKana01(), |
||
445 | $Customer->getKana02()), |
||
446 | 'tel' => sprintf($formatTel, $Customer->getTel01(), $Customer->getTel02(), $Customer->getTel03()), |
||
447 | 'email' => $Customer->getEmail(), |
||
448 | 3 | ); |
|
449 | } |
||
450 | 3 | ||
451 | 3 | $event = new EventArgs( |
|
452 | array( |
||
453 | 'data' => $data, |
||
454 | 3 | 'Customers' => $pagination, |
|
455 | 3 | ), |
|
456 | $request |
||
457 | 3 | ); |
|
458 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_COMPLETE, $event); |
||
459 | 3 | $data = $event->getArgument('data'); |
|
460 | |||
461 | return $app->render('Order/search_customer.twig', array( |
||
462 | 'data' => $data, |
||
463 | 3 | 'pagination' => $pagination, |
|
464 | )); |
||
465 | 3 | } |
|
466 | } |
||
467 | |||
468 | /** |
||
469 | * 顧客情報を検索する. |
||
470 | * |
||
471 | 3 | * @param Application $app |
|
472 | * @param Request $request |
||
473 | * @return \Symfony\Component\HttpFoundation\JsonResponse |
||
474 | 3 | */ |
|
475 | 3 | public function searchCustomerById(Application $app, Request $request) |
|
476 | 3 | { |
|
477 | 3 | if ($request->isXmlHttpRequest()) { |
|
478 | 3 | $app['monolog']->addDebug('search customer by id start.'); |
|
479 | 3 | ||
480 | 3 | /** @var $Customer \Eccube\Entity\Customer */ |
|
481 | 3 | $Customer = $app['eccube.repository.customer'] |
|
482 | 3 | ->find($request->get('id')); |
|
483 | 3 | ||
484 | 3 | $event = new EventArgs( |
|
485 | 3 | array( |
|
486 | 3 | 'Customer' => $Customer, |
|
487 | 3 | ), |
|
488 | 3 | $request |
|
489 | 3 | ); |
|
490 | 3 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_INITIALIZE, $event); |
|
491 | 3 | ||
492 | if (is_null($Customer)) { |
||
493 | $app['monolog']->addDebug('search customer by id not found.'); |
||
494 | 3 | ||
495 | return $app->json(array(), 404); |
||
496 | 3 | } |
|
497 | 3 | ||
498 | $app['monolog']->addDebug('search customer by id found.'); |
||
499 | |||
500 | $data = array( |
||
501 | 3 | 'id' => $Customer->getId(), |
|
502 | 3 | 'name01' => $Customer->getName01(), |
|
503 | 'name02' => $Customer->getName02(), |
||
504 | 3 | 'kana01' => $Customer->getKana01(), |
|
505 | 'kana02' => $Customer->getKana02(), |
||
506 | 'zip01' => $Customer->getZip01(), |
||
507 | 'zip02' => $Customer->getZip02(), |
||
508 | 3 | 'pref' => is_null($Customer->getPref()) ? null : $Customer->getPref()->getId(), |
|
509 | 'addr01' => $Customer->getAddr01(), |
||
510 | 3 | 'addr02' => $Customer->getAddr02(), |
|
511 | 3 | 'email' => $Customer->getEmail(), |
|
512 | 3 | 'tel01' => $Customer->getTel01(), |
|
513 | 3 | 'tel02' => $Customer->getTel02(), |
|
514 | 'tel03' => $Customer->getTel03(), |
||
515 | 3 | 'fax01' => $Customer->getFax01(), |
|
516 | 'fax02' => $Customer->getFax02(), |
||
517 | 3 | 'fax03' => $Customer->getFax03(), |
|
518 | 'company_name' => $Customer->getCompanyName(), |
||
519 | ); |
||
520 | 3 | ||
521 | $event = new EventArgs( |
||
522 | array( |
||
523 | 3 | 'data' => $data, |
|
524 | 'Customer' => $Customer, |
||
525 | ), |
||
526 | $request |
||
527 | ); |
||
528 | 3 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_COMPLETE, $event); |
|
529 | 3 | $data = $event->getArgument('data'); |
|
530 | |||
531 | return $app->json($data); |
||
532 | } |
||
533 | } |
||
534 | |||
535 | public function searchProduct(Application $app, Request $request, $page_no = null) |
||
536 | { |
||
537 | if ($request->isXmlHttpRequest()) { |
||
538 | $app['monolog']->addDebug('search product start.'); |
||
539 | 3 | $page_count = $app['config']['default_page_count']; |
|
540 | 3 | $session = $app['session']; |
|
541 | |||
542 | 3 | if ('POST' === $request->getMethod()) { |
|
543 | |||
544 | 3 | $page_no = 1; |
|
545 | 3 | ||
546 | $searchData = array( |
||
547 | 'id' => $request->get('id'), |
||
548 | ); |
||
549 | 3 | ||
550 | if ($categoryId = $request->get('category_id')) { |
||
551 | $Category = $app['eccube.repository.category']->find($categoryId); |
||
552 | 3 | $searchData['category_id'] = $Category; |
|
553 | } |
||
554 | |||
555 | $session->set('eccube.admin.order.product.search', $searchData); |
||
556 | 3 | $session->set('eccube.admin.order.product.search.page_no', $page_no); |
|
557 | } else { |
||
558 | $searchData = (array)$session->get('eccube.admin.order.product.search'); |
||
559 | if (is_null($page_no)) { |
||
560 | 3 | $page_no = intval($session->get('eccube.admin.order.product.search.page_no')); |
|
561 | } else { |
||
562 | 3 | $session->set('eccube.admin.order.product.search.page_no', $page_no); |
|
563 | } |
||
564 | } |
||
565 | |||
566 | 3 | $qb = $app['eccube.repository.product'] |
|
567 | 3 | ->getQueryBuilderBySearchDataForAdmin($searchData); |
|
568 | |||
569 | 3 | $event = new EventArgs( |
|
570 | 3 | array( |
|
571 | 'qb' => $qb, |
||
572 | 3 | 'searchData' => $searchData, |
|
573 | 3 | ), |
|
574 | $request |
||
575 | ); |
||
576 | 3 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_SEARCH, $event); |
|
577 | |||
578 | 3 | /** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */ |
|
579 | 3 | $pagination = $app['paginator']()->paginate( |
|
580 | 3 | $qb, |
|
581 | $page_no, |
||
582 | $page_count, |
||
583 | array('wrap-queries' => true) |
||
584 | 3 | ); |
|
585 | |||
586 | 3 | /** @var $Products \Eccube\Entity\Product[] */ |
|
587 | 3 | $Products = $pagination->getItems(); |
|
588 | 3 | ||
589 | 3 | if (empty($Products)) { |
|
590 | $app['monolog']->addDebug('search product not found.'); |
||
591 | } |
||
592 | |||
593 | $forms = array(); |
||
594 | 7 | foreach ($Products as $Product) { |
|
595 | /* @var $builder \Symfony\Component\Form\FormBuilderInterface */ |
||
596 | 7 | $builder = $app['form.factory']->createNamedBuilder('', AddCartType::class, null, array( |
|
597 | 7 | 'product' => $Product, |
|
598 | 7 | )); |
|
599 | 7 | $addCartForm = $builder->getForm(); |
|
600 | $forms[$Product->getId()] = $addCartForm->createView(); |
||
601 | 7 | } |
|
602 | |||
603 | $event = new EventArgs( |
||
604 | array( |
||
605 | 'forms' => $forms, |
||
606 | 'Products' => $Products, |
||
607 | 'pagination' => $pagination, |
||
608 | ), |
||
609 | $request |
||
610 | ); |
||
611 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_COMPLETE, $event); |
||
612 | |||
613 | return $app->render('Order/search_product.twig', array( |
||
614 | 'forms' => $forms, |
||
615 | 'Products' => $Products, |
||
616 | 'pagination' => $pagination, |
||
617 | )); |
||
618 | } |
||
619 | } |
||
620 | |||
621 | protected function newOrder(Application $app) |
||
634 | |||
635 | /** |
||
636 | * フォームからの入直内容に基づいて、受注情報の再計算を行う |
||
637 | * |
||
638 | * @param $app |
||
639 | * @param $Order |
||
640 | */ |
||
641 | protected function calculate($app, \Eccube\Entity\Order $Order) |
||
679 | |||
680 | /** |
||
681 | * 受注ステータスに応じて, 受注日/入金日/発送日を更新する, |
||
682 | * 発送済ステータスが設定された場合は, お届け先情報の発送日も更新を行う. |
||
683 | * |
||
684 | * 編集の場合 |
||
685 | 7 | * - 受注ステータスが他のステータスから発送済へ変更された場合に発送日を更新 |
|
686 | * - 受注ステータスが他のステータスから入金済へ変更された場合に入金日を更新 |
||
687 | * |
||
688 | 7 | * 新規登録の場合 |
|
689 | * - 受注日を更新 |
||
690 | * - 受注ステータスが発送済に設定された場合に発送日を更新 |
||
691 | * - 受注ステータスが入金済に設定された場合に入金日を更新 |
||
692 | * |
||
693 | * |
||
694 | 4 | * @param $app |
|
695 | * @param $TargetOrder |
||
696 | * @param $OriginOrder |
||
697 | */ |
||
698 | protected function updateDate($app, $TargetOrder, $OriginOrder) |
||
740 | } |
||
741 |