Failed Conditions
Push — master ( ee6ce9...9ed6ac )
by Yangsin
485:10 queued 475:23
created

EditController::updateDate()   D

Complexity

Conditions 10
Paths 9

Size

Total Lines 42
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 36.5723

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 42
ccs 10
cts 28
cp 0.357
rs 4.8196
cc 10
eloc 21
nc 9
nop 3
crap 36.5723

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
38
{
39 17
    public function index(Application $app, Request $request, $id = null)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
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 17
            'Eccube\Entity\Product',
46 17
        ));
47
48 17
        $TargetOrder = null;
0 ignored issues
show
Unused Code introduced by
$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
Unused Code introduced by
$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 7
        } else {
55 10
            $TargetOrder = $app['eccube.repository.order']->find($id);
56 10
            if (is_null($TargetOrder)) {
57 11
                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 10
            $OriginalOrderDetails->add($OrderDetail);
67 17
        }
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 17
            ),
79 7
            $request
80 17
        );
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 11
                ),
95
                $request
96 11
            );
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 11
                    if ($TargetOrder->getTotal() > $app['config']['max_total_fee']) {
106
                        $form['charge']->addError(new FormError('合計金額の上限を超えております。'));
107 11
                    } elseif ($form->isValid()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
108
109 11
                        $BaseInfo = $app['eccube.repository.base_info']->get();
110
111
                        // お支払い方法の更新
112 11
                        $TargetOrder->setPaymentMethod($TargetOrder->getPayment()->getMethod());
113
114
                        // 配送業者・お届け時間の更新
115 11
                        $Shippings = $TargetOrder->getShippings();
116 11
                        foreach ($Shippings as $Shipping) {
117 11
                            $Shipping->setShippingDeliveryName($Shipping->getDelivery()->getName());
118 11
                            if (!is_null($Shipping->getDeliveryTime())) {
119 11
                                $Shipping->setShippingDeliveryTime($Shipping->getDeliveryTime()->getDeliveryTime());
120 11
                            } else {
121
                                $Shipping->setShippingDeliveryTime(null);
122
                            }
123 11
                        }
124
125
126
                        // 受注日/発送日/入金日の更新.
127 11
                        $this->updateDate($app, $TargetOrder, $OriginOrder);
128
129
                        // 受注明細で削除されているものをremove
130 11
                        foreach ($OriginalOrderDetails as $OrderDetail) {
131 7
                            if (false === $TargetOrder->getOrderDetails()->contains($OrderDetail)) {
132
                                $app['orm.em']->remove($OrderDetail);
133
                            }
134 11
                        }
135
136
137 11
                        if ($BaseInfo->getOptionMultipleShipping() == Constant::ENABLED) {
138 4
                            foreach ($TargetOrder->getOrderDetails() as $OrderDetail) {
139
                                /** @var $OrderDetail \Eccube\Entity\OrderDetail */
140 4
                                $OrderDetail->setOrder($TargetOrder);
141 4
                            }
142
143
                            /** @var \Eccube\Entity\Shipping $Shipping */
144 4 View Code Duplication
                            foreach ($Shippings as $Shipping) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
145 4
                                $shipmentItems = $Shipping->getShipmentItems();
146
                                /** @var \Eccube\Entity\ShipmentItem $ShipmentItem */
147 4
                                foreach ($shipmentItems as $ShipmentItem) {
148 4
                                    $ShipmentItem->setOrder($TargetOrder);
149 4
                                    $ShipmentItem->setShipping($Shipping);
150 4
                                    $app['orm.em']->persist($ShipmentItem);
151 4
                                }
152 4
                                $Shipping->setOrder($TargetOrder);
153 4
                                $app['orm.em']->persist($Shipping);
154 4
                            }
155 4
                        } else {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
156
157 7
                            $NewShipmentItems = new ArrayCollection();
158
159 7
                            foreach ($TargetOrder->getOrderDetails() as $OrderDetail) {
160
                                /** @var $OrderDetail \Eccube\Entity\OrderDetail */
161 7
                                $OrderDetail->setOrder($TargetOrder);
162
163 7
                                $NewShipmentItem = new ShipmentItem();
164
                                $NewShipmentItem
165 7
                                    ->setProduct($OrderDetail->getProduct())
166 7
                                    ->setProductClass($OrderDetail->getProductClass())
167 7
                                    ->setProductName($OrderDetail->getProduct()->getName())
168 7
                                    ->setProductCode($OrderDetail->getProductClass()->getCode())
169 7
                                    ->setClassCategoryName1($OrderDetail->getClassCategoryName1())
170 7
                                    ->setClassCategoryName2($OrderDetail->getClassCategoryName2())
171 7
                                    ->setClassName1($OrderDetail->getClassName1())
172 7
                                    ->setClassName2($OrderDetail->getClassName2())
173 7
                                    ->setPrice($OrderDetail->getPrice())
174 7
                                    ->setQuantity($OrderDetail->getQuantity())
175 7
                                    ->setOrder($TargetOrder);
176 7
                                $NewShipmentItems[] = $NewShipmentItem;
177
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
178 7
                            }
179
                            // 配送商品の更新. delete/insert.
180 7
                            $Shippings = $TargetOrder->getShippings();
181 7 View Code Duplication
                            foreach ($Shippings as $Shipping) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
182 7
                                $ShipmentItems = $Shipping->getShipmentItems();
183 7
                                foreach ($ShipmentItems as $ShipmentItem) {
184 4
                                    $app['orm.em']->remove($ShipmentItem);
185 7
                                }
186 7
                                $ShipmentItems->clear();
187 7
                                foreach ($NewShipmentItems as $NewShipmentItem) {
188 7
                                    $NewShipmentItem->setShipping($Shipping);
189 7
                                    $ShipmentItems->add($NewShipmentItem);
190 7
                                }
191 7
                            }
192
                        }
193
194 11
                        $Customer = $TargetOrder->getCustomer();
195 11
                        if ($Customer) {
196
                            // 受注情報の会員情報を更新
197 11
                            $TargetOrder->setSex($Customer->getSex());
198 11
                            $TargetOrder->setJob($Customer->getJob());
199 11
                            $TargetOrder->setBirth($Customer->getBirth());
200 11
                        }
201
202 11
                        $app['orm.em']->persist($TargetOrder);
203 11
                        $app['orm.em']->flush();
204
205 11
                        if ($Customer) {
206
                            // 会員の場合、購入回数、購入金額などを更新
207 11
                            $app['eccube.repository.customer']->updateBuyData($app, $Customer, $TargetOrder->getOrderStatus()->getId());
208 11
                        }
209
210 11
                        $event = new EventArgs(
211
                            array(
212 11
                                'form' => $form,
213 11
                                'OriginOrder' => $OriginOrder,
214 11
                                'TargetOrder' => $TargetOrder,
215 11
                                'OriginOrderDetails' => $OriginalOrderDetails,
216 11
                                'Customer' => $Customer,
217 11
                            ),
218
                            $request
219 11
                        );
220 11
                        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_COMPLETE, $event);
221
222 11
                        $app->addSuccess('admin.order.save.complete', 'admin');
223
224 11
                        return $app->redirect($app->url('admin_order_edit', array('id' => $TargetOrder->getId())));
225 11
                    }
226
227 2
                    break;
228
229
                case 'add_delivery':
230
                    // お届け先情報の新規追加
231
232
                    $form = $builder->getForm();
233
234
                    $Shipping = new \Eccube\Entity\Shipping();
235
                    $Shipping->setDelFlg(Constant::DISABLED);
236
237
                    $TargetOrder->addShipping($Shipping);
238
239 11
                    $Shipping->setOrder($TargetOrder);
240
241 11
                    $form->setData($TargetOrder);
242
243
                    break;
244
245
                default:
246
                    break;
247 2
            }
248 2
        }
249
250
        // 会員検索フォーム
251 8
        $builder = $app['form.factory']
252 8
            ->createBuilder('admin_search_customer');
253
254 8
        $event = new EventArgs(
255
            array(
256 8
                'builder' => $builder,
257 8
                'OriginOrder' => $OriginOrder,
258 8
                'TargetOrder' => $TargetOrder,
259 8
                'OriginOrderDetails' => $OriginalOrderDetails,
260 8
            ),
261
            $request
262 8
        );
263 8
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_INITIALIZE, $event);
264
265 8
        $searchCustomerModalForm = $builder->getForm();
266
267
        // 商品検索フォーム
268 8
        $builder = $app['form.factory']
269 8
            ->createBuilder('admin_search_product');
270
271 8
        $event = new EventArgs(
272
            array(
273 8
                'builder' => $builder,
274 8
                'OriginOrder' => $OriginOrder,
275 8
                'TargetOrder' => $TargetOrder,
276 8
                'OriginOrderDetails' => $OriginalOrderDetails,
277 8
            ),
278
            $request
279 8
        );
280 8
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_INITIALIZE, $event);
281
282 8
        $searchProductModalForm = $builder->getForm();
283
284
        // 配送業者のお届け時間
285 8
        $times = array();
286 8
        $deliveries = $app['eccube.repository.delivery']->findAll();
287 8
        foreach ($deliveries as $Delivery) {
288 8
            $deliveryTiems = $Delivery->getDeliveryTimes();
289 8
            foreach ($deliveryTiems as $DeliveryTime) {
290 8
                $times[$Delivery->getId()][$DeliveryTime->getId()] = $DeliveryTime->getDeliveryTime();
291 8
            }
292 8
        }
293
294 8
        return $app->render('Order/edit.twig', array(
295 8
            'form' => $form->createView(),
296 8
            'searchCustomerModalForm' => $searchCustomerModalForm->createView(),
297 8
            'searchProductModalForm' => $searchProductModalForm->createView(),
298 8
            'Order' => $TargetOrder,
299 8
            'id' => $id,
300 17
            'shippingDeliveryTimes' => $app['serializer']->serialize($times, 'json'),
301 8
        ));
302
    }
303
304
    /**
305
     * 顧客情報を検索する.
306
     *
307
     * @param Application $app
308
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
309
     * @return \Symfony\Component\HttpFoundation\JsonResponse
310
     */
311 3
    public function searchCustomer(Application $app, Request $request)
312
    {
313 3
        if ($request->isXmlHttpRequest()) {
314 3
            $app['monolog']->addDebug('search customer start.');
315
316
            $searchData = array(
317 3
                'multi' => $request->get('search_word'),
318 3
            );
319
320 3
            $qb = $app['eccube.repository.customer']->getQueryBuilderBySearchData($searchData);
321
322 3
            $event = new EventArgs(
323
                array(
324 3
                    'qb' => $qb,
325 3
                    'data' => $searchData,
326 3
                ),
327
                $request
328 3
            );
329 3
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_SEARCH, $event);
330
331 3
            $Customers = $qb->getQuery()->getResult();
332
333
334 3
            if (empty($Customers)) {
335
                $app['monolog']->addDebug('search customer not found.');
336
            }
337
338 3
            $data = array();
339
340 3
            $formatTel = '%s-%s-%s';
341 3
            $formatName = '%s%s(%s%s)';
342 3
            foreach ($Customers as $Customer) {
343 3
                $data[] = array(
344 3
                    'id' => $Customer->getId(),
345 3
                    'name' => sprintf($formatName, $Customer->getName01(), $Customer->getName02(), $Customer->getKana01(),
346 3
                        $Customer->getKana02()),
347 3
                    'tel' => sprintf($formatTel, $Customer->getTel01(), $Customer->getTel02(), $Customer->getTel03()),
348 3
                    'email' => $Customer->getEmail(),
349
                );
350 3
            }
351
352 3
            $event = new EventArgs(
353
                array(
354 3
                    'data' => $data,
355 3
                    'Customers' => $Customers,
356 3
                ),
357
                $request
358 3
            );
359 3
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_COMPLETE, $event);
360 3
            $data = $event->getArgument('data');
361
362 3
            return $app->json($data);
363
        }
364
    }
365
366
    /**
367
     * 顧客情報を検索する.
368
     *
369
     * @param Application $app
370
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
371
     * @return \Symfony\Component\HttpFoundation\JsonResponse
372
     */
373 3
    public function searchCustomerById(Application $app, Request $request)
374
    {
375 3
        if ($request->isXmlHttpRequest()) {
376 3
            $app['monolog']->addDebug('search customer by id start.');
377
378
            /** @var $Customer \Eccube\Entity\Customer */
379 3
            $Customer = $app['eccube.repository.customer']
380 3
                ->find($request->get('id'));
381
382 3
            $event = new EventArgs(
383
                array(
384 3
                    'Customer' => $Customer,
385 3
                ),
386
                $request
387 3
            );
388 3
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_INITIALIZE, $event);
389
390 3
            if (is_null($Customer)) {
391
                $app['monolog']->addDebug('search customer by id not found.');
392
393
                return $app->json(array(), 404);
394
            }
395
396 3
            $app['monolog']->addDebug('search customer by id found.');
397
398
            $data = array(
399 3
                'id' => $Customer->getId(),
400 3
                'name01' => $Customer->getName01(),
401 3
                'name02' => $Customer->getName02(),
402 3
                'kana01' => $Customer->getKana01(),
403 3
                'kana02' => $Customer->getKana02(),
404 3
                'zip01' => $Customer->getZip01(),
405 3
                'zip02' => $Customer->getZip02(),
406 3
                'pref' => is_null($Customer->getPref()) ? null : $Customer->getPref()->getId(),
407 3
                'addr01' => $Customer->getAddr01(),
408 3
                'addr02' => $Customer->getAddr02(),
409 3
                'email' => $Customer->getEmail(),
410 3
                'tel01' => $Customer->getTel01(),
411 3
                'tel02' => $Customer->getTel02(),
412 3
                'tel03' => $Customer->getTel03(),
413 3
                'fax01' => $Customer->getFax01(),
414 3
                'fax02' => $Customer->getFax02(),
415 3
                'fax03' => $Customer->getFax03(),
416 3
                'company_name' => $Customer->getCompanyName(),
417 3
            );
418
419 3
            $event = new EventArgs(
420
                array(
421 3
                    'data' => $data,
422 3
                    'Customer' => $Customer,
423 3
                ),
424
                $request
425 3
            );
426 3
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_BY_ID_COMPLETE, $event);
427 3
            $data = $event->getArgument('data');
428
429 3
            return $app->json($data);
430
        }
431
    }
432
433 14
    public function searchProduct(Application $app, Request $request, $page_no = null)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
434
    {
435 14
        if ($request->isXmlHttpRequest()) {
436 14
            $app['monolog']->addDebug('search product start.');
437 14
            $page_count = $app['config']['default_page_count'];
438 14
            $session = $app['session'];
439
440 3
            if ('POST' === $request->getMethod()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
441
442 14
                $page_no = 1;
443
444
                $searchData = array(
445 3
                    'name' => $request->get('id'),
446 3
                );
447
448 3
                if ($categoryId = $request->get('category_id')) {
449
                    $Category = $app['eccube.repository.category']->find($categoryId);
450
                    $searchData['category_id'] = $Category;
451
                }
452
453 3
                $session->set('eccube.admin.order.product.search', $searchData);
454 12
                $session->set('eccube.admin.order.product.search.page_no', $page_no);
455 12
            } else {
456 9
                $searchData = (array)$session->get('eccube.admin.order.product.search');
0 ignored issues
show
Coding Style introduced by
As per coding-style, a cast statement should be followed by a single space.
Loading history...
457
                if (is_null($page_no)) {
458
                    $page_no = intval($session->get('eccube.admin.order.product.search.page_no'));
459
                } else {
460
                    $session->set('eccube.admin.order.product.search.page_no', $page_no);
461
                }
462
            }
463
464 3
            $qb = $app['eccube.repository.product']
465 3
                ->getQueryBuilderBySearchData($searchData);
466
467 3
            $event = new EventArgs(
468
                array(
469 3
                    'qb' => $qb,
470 3
                    'searchData' => $searchData,
471 3
                ),
472
                $request
473 14
            );
474 14
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_SEARCH, $event);
475
476
            /** @var \Knp\Component\Pager\Pagination\SlidingPagination $pagination */
477 3
            $pagination = $app['paginator']()->paginate(
478 3
                $qb,
479 3
                $page_no,
480 3
                $page_count,
481 3
                array('wrap-queries' => true)
482 3
            );
483
484
            /** @var $Products \Eccube\Entity\Product[] */
485 3
            $Products = $pagination->getItems();
486
487 3
            if (empty($Products)) {
488 3
                $app['monolog']->addDebug('search product not found.');
489 3
            }
490
491 3
            $forms = array();
492 3
            foreach ($Products as $Product) {
493
                /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
494
                $builder = $app['form.factory']->createNamedBuilder('', 'add_cart', null, array(
495
                    'product' => $Product,
496
                ));
497
                $addCartForm = $builder->getForm();
498
                $forms[$Product->getId()] = $addCartForm->createView();
499 3
            }
500
501 3
            $event = new EventArgs(
502
                array(
503 3
                    'forms' => $forms,
504 3
                    'Products' => $Products,
505 4
                    'pagination' => $pagination,
506 3
                ),
507
                $request
508 3
            );
509 3
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_PRODUCT_COMPLETE, $event);
510
511 3
            return $app->render('Order/search_product.twig', array(
512 3
                'forms' => $forms,
513 3
                'Products' => $Products,
514 3
                'pagination' => $pagination,
515 3
            ));
516
        }
517
    }
518
519 7
    protected function newOrder()
520
    {
521 7
        $Order = new \Eccube\Entity\Order();
522 7
        $Shipping = new \Eccube\Entity\Shipping();
523 7
        $Shipping->setDelFlg(0);
524 7
        $Order->addShipping($Shipping);
525 7
        $Shipping->setOrder($Order);
526
527 7
        return $Order;
528
    }
529
530
    /**
531
     * フォームからの入直内容に基づいて、受注情報の再計算を行う
532
     *
533
     * @param $app
534
     * @param $Order
535
     */
536 11
    protected function calculate($app, \Eccube\Entity\Order $Order)
537
    {
538 11
        $taxtotal = 0;
539 11
        $subtotal = 0;
540
541
        // 受注明細データの税・小計を再計算
542
        /** @var $OrderDetails \Eccube\Entity\OrderDetail[] */
543 11
        $OrderDetails = $Order->getOrderDetails();
544 11
        foreach ($OrderDetails as $OrderDetail) {
545
            // 新規登録の場合は, 入力されたproduct_id/produc_class_idから明細にセットする.
546 11
            if (!$OrderDetail->getId()) {
547 7
                $TaxRule = $app['eccube.repository.tax_rule']->getByRule($OrderDetail->getProduct(),
548 7
                    $OrderDetail->getProductClass());
549 7
                $OrderDetail->setTaxRule($TaxRule->getId());
550 7
                $OrderDetail->setProductName($OrderDetail->getProduct()->getName());
551 7
                $OrderDetail->setProductCode($OrderDetail->getProductClass()->getCode());
552 7
                $OrderDetail->setClassName1($OrderDetail->getProductClass()->hasClassCategory1()
553 7
                    ? $OrderDetail->getProductClass()->getClassCategory1()->getClassName()->getName()
554 7
                    : null);
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 20.
Loading history...
555 7
                $OrderDetail->setClassName2($OrderDetail->getProductClass()->hasClassCategory2()
556 7
                    ? $OrderDetail->getProductClass()->getClassCategory2()->getClassName()->getName()
557 7
                    : null);
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 20.
Loading history...
558 7
                $OrderDetail->setClassCategoryName1($OrderDetail->getProductClass()->hasClassCategory1()
559 7
                    ? $OrderDetail->getProductClass()->getClassCategory1()->getName()
560 7
                    : null);
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 20.
Loading history...
561 7
                $OrderDetail->setClassCategoryName2($OrderDetail->getProductClass()->hasClassCategory2()
562 7
                    ? $OrderDetail->getProductClass()->getClassCategory2()->getName()
563 7
                    : null);
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 20.
Loading history...
564 7
            }
565
566
            // 税
567 11
            $tax = $app['eccube.service.tax_rule']
568 11
                ->calcTax($OrderDetail->getPrice(), $OrderDetail->getTaxRate(), $OrderDetail->getTaxRule());
569 11
            $OrderDetail->setPriceIncTax($OrderDetail->getPrice() + $tax);
570
571 11
            $taxtotal += $tax * $OrderDetail->getQuantity();
572
573
            // 小計
574 11
            $subtotal += $OrderDetail->getTotalPrice();
575 11
        }
576
577 11
        $shippings = $Order->getShippings();
578
        /** @var \Eccube\Entity\Shipping $Shipping */
579 11
        foreach ($shippings as $Shipping) {
580 11
            $shipmentItems = $Shipping->getShipmentItems();
581 11
            $Shipping->setDelFlg(Constant::DISABLED);
582
            /** @var \Eccube\Entity\ShipmentItem $ShipmentItem */
583 11
            foreach ($shipmentItems as $ShipmentItem) {
584 8
                $ShipmentItem->setProductName($ShipmentItem->getProduct()->getName());
585 8
                $ShipmentItem->setProductCode($ShipmentItem->getProductClass()->getCode());
586 8
                $ShipmentItem->setClassName1($ShipmentItem->getProductClass()->hasClassCategory1()
587 8
                    ? $ShipmentItem->getProductClass()->getClassCategory1()->getClassName()->getName()
588 8
                    : null);
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 20.
Loading history...
589 8
                $ShipmentItem->setClassName2($ShipmentItem->getProductClass()->hasClassCategory2()
590 8
                    ? $ShipmentItem->getProductClass()->getClassCategory2()->getClassName()->getName()
591 8
                    : null);
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 20.
Loading history...
592 8
                $ShipmentItem->setClassCategoryName1($ShipmentItem->getProductClass()->hasClassCategory1()
593 8
                    ? $ShipmentItem->getProductClass()->getClassCategory1()->getName()
594 8
                    : null);
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 20.
Loading history...
595 8
                $ShipmentItem->setClassCategoryName2($ShipmentItem->getProductClass()->hasClassCategory2()
596 8
                    ? $ShipmentItem->getProductClass()->getClassCategory2()->getName()
597 8
                    : null);
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 20.
Loading history...
598 11
            }
599 11
        }
600
601
        // 受注データの税・小計・合計を再計算
602 11
        $Order->setTax($taxtotal);
603 11
        $Order->setSubtotal($subtotal);
604 11
        $Order->setTotal($subtotal + $Order->getCharge() + $Order->getDeliveryFeeTotal() - $Order->getDiscount());
605
        // お支払い合計は、totalと同一金額(2系ではtotal - point)
606 11
        $Order->setPaymentTotal($Order->getTotal());
607 11
    }
608
609
    /**
610
     * 受注ステータスに応じて, 受注日/入金日/発送日を更新する,
611
     * 発送済ステータスが設定された場合は, お届け先情報の発送日も更新を行う.
612
     *
613
     * 編集の場合
614
     * - 受注ステータスが他のステータスから発送済へ変更された場合に発送日を更新
615
     * - 受注ステータスが他のステータスから入金済へ変更された場合に入金日を更新
616
     *
617
     * 新規登録の場合
618
     * - 受注日を更新
619
     * - 受注ステータスが発送済に設定された場合に発送日を更新
620
     * - 受注ステータスが入金済に設定された場合に入金日を更新
621
     *
622
     *
623
     * @param $app
624
     * @param $TargetOrder
625
     * @param $OriginOrder
626
     */
627 11
    protected function updateDate($app, $TargetOrder, $OriginOrder)
628
    {
629 11
        $dateTime = new \DateTime();
630
631
        // 編集
632 11
        if ($TargetOrder->getId()) {
633
            // 発送済
634 7
            if ($TargetOrder->getOrderStatus()->getId() == $app['config']['order_deliv']) {
635
                // 編集前と異なる場合のみ更新
636
                if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) {
637
                    $TargetOrder->setCommitDate($dateTime);
638
                    // お届け先情報の発送日も更新する.
639
                    $Shippings = $TargetOrder->getShippings();
640
                    foreach ($Shippings as $Shipping) {
641
                        $Shipping->setShippingCommitDate($dateTime);
642
                    }
643
                }
644
                // 入金済
645 7
            } elseif ($TargetOrder->getOrderStatus()->getId() == $app['config']['order_pre_end']) {
646
                // 編集前と異なる場合のみ更新
647
                if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) {
648
                    $TargetOrder->setPaymentDate($dateTime);
649
                }
650
            }
651
            // 新規
652 7
        } else {
653
            // 発送済
654 4
            if ($TargetOrder->getOrderStatus()->getId() == $app['config']['order_deliv']) {
655
                $TargetOrder->setCommitDate($dateTime);
656
                // お届け先情報の発送日も更新する.
657
                $Shippings = $TargetOrder->getShippings();
658
                foreach ($Shippings as $Shipping) {
659
                    $Shipping->setShippingCommitDate($dateTime);
660
                }
661
                // 入金済
662 4
            } elseif ($TargetOrder->getOrderStatus()->getId() == $app['config']['order_pre_end']) {
663
                $TargetOrder->setPaymentDate($dateTime);
664
            }
665
            // 受注日時
666 4
            $TargetOrder->setOrderDate($dateTime);
667
        }
668 11
    }
669
}
670