Completed
Pull Request — master (#1779)
by Kentaro
214:45 queued 207:18
created

EditController::index()   F

Complexity

Conditions 24
Paths 637

Size

Total Lines 258
Code Lines 157

Duplication

Lines 22
Ratio 8.53 %

Code Coverage

Tests 161
CRAP Score 24.2948

Importance

Changes 0
Metric Value
dl 22
loc 258
ccs 161
cts 175
cp 0.92
rs 2.248
c 0
b 0
f 0
cc 24
eloc 157
nc 637
nop 3
crap 24.2948

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