Failed Conditions
Pull Request — 3.0.9-dev (#1468)
by chihiro
59:35 queued 23:18
created

EditController::searchCustomer()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 54
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 4

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 54
ccs 22
cts 22
cp 1
rs 9.0306
cc 4
eloc 33
nc 5
nop 2
crap 4

How to fix   Long Method   

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