Failed Conditions
Push — master ( fc54b8...947180 )
by Yangsin
124:44 queued 119:37
created

Eccube/Controller/Admin/Order/EditController.php (2 issues)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 17
    public function index(Application $app, Request $request, $id = null)
40
    {
41
        /* @var $softDeleteFilter \Eccube\Doctrine\Filter\SoftDeleteFilter */
42 17
        $softDeleteFilter = $app['orm.em']->getFilters()->getFilter('soft_delete');
43 17
        $softDeleteFilter->setExcludes(array(
44 17
            'Eccube\Entity\ProductClass',
45
            'Eccube\Entity\Product',
46
        ));
47
48 17
        $TargetOrder = null;
0 ignored issues
show
$TargetOrder is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
49 17
        $OriginOrder = null;
0 ignored issues
show
$OriginOrder is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

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