Completed
Pull Request — master (#1632)
by Kentaro
32:45
created

ShoppingController   F

Complexity

Total Complexity 123

Size/Duplication

Total Lines 1346
Duplicated Lines 12.93 %

Coupling/Cohesion

Components 1
Dependencies 17

Test Coverage

Coverage 98.06%

Importance

Changes 7
Bugs 0 Features 0
Metric Value
wmc 123
c 7
b 0
f 0
lcom 1
cbo 17
dl 174
loc 1346
ccs 101
cts 103
cp 0.9806
rs 0.6314

17 Methods

Rating   Name   Duplication   Size   Complexity  
A customerValidation() 0 68 1
B complete() 0 24 2
B shippingEditChange() 43 43 5
B shippingMultipleChange() 43 43 5
B shippingMultipleEdit() 0 52 4
C index() 0 84 10
D confirm() 0 113 10
D delivery() 0 95 9
B payment() 0 60 5
B shippingChange() 43 43 5
C shipping() 0 78 7
C shippingEdit() 7 91 11
C customer() 10 72 7
B login() 6 35 5
D nonmember() 0 121 9
F shippingMultiple() 22 207 26
A shoppingError() 0 15 2

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ShoppingController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ShoppingController, and based on these observations, apply Extract Interface, too.

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
25
namespace Eccube\Controller;
26
27
use Eccube\Application;
28
use Eccube\Common\Constant;
29
use Eccube\Entity\Customer;
30
use Eccube\Entity\CustomerAddress;
31
use Eccube\Entity\ShipmentItem;
32
use Eccube\Entity\Shipping;
33
use Eccube\Event\EccubeEvents;
34
use Eccube\Event\EventArgs;
35
use Eccube\Exception\CartException;
36
use Eccube\Exception\ShoppingException;
37
use Symfony\Component\HttpFoundation\Request;
38
use Symfony\Component\HttpFoundation\Response;
39
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
40
use Symfony\Component\Validator\Constraints as Assert;
41
42
class ShoppingController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
43
{
44
45
    /**
46
     * @var string 非会員用セッションキー
47
     */
48
    private $sessionKey = 'eccube.front.shopping.nonmember';
49
50
    /**
51
     * @var string 非会員用セッションキー
52
     */
53
    private $sessionCustomerAddressKey = 'eccube.front.shopping.nonmember.customeraddress';
54
55
    /**
56
     * @var string 複数配送警告メッセージ
57
     */
58
    private $sessionMultipleKey = 'eccube.front.shopping.multiple';
59
60
    /**
61
     * @var string 受注IDキー
62
     */
63
    private $sessionOrderKey = 'eccube.front.shopping.order.id';
64
65
    /**
66
     * 購入画面表示
67
     *
68
     * @param Application $app
69
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
70
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
71
     */
72 12
    public function index(Application $app, Request $request)
73
    {
74
        $cartService = $app['eccube.service.cart'];
75
76
        // カートチェック
77
        if (!$cartService->isLocked()) {
78
            // カートが存在しない、カートがロックされていない時はエラー
79
            return $app->redirect($app->url('cart'));
80
        }
81
82
        // カートチェック
83
        if (count($cartService->getCart()->getCartItems()) <= 0) {
84
            // カートが存在しない時はエラー
85
            return $app->redirect($app->url('cart'));
86
        }
87
88
        // 登録済みの受注情報を取得
89
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
90
91
        // 初回アクセス(受注情報がない)の場合は, 受注情報を作成
92
        if (is_null($Order)) {
93
            // 未ログインの場合, ログイン画面へリダイレクト.
94
            if (!$app->isGranted('IS_AUTHENTICATED_FULLY')) {
95
                // 非会員でも一度会員登録されていればショッピング画面へ遷移
96
                $Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey);
97
98
                if (is_null($Customer)) {
99
                    return $app->redirect($app->url('shopping_login'));
100
                }
101
            } else {
102
                $Customer = $app->user();
103 2
            }
104
105
            try {
106
                // 受注情報を作成
107
                $Order = $app['eccube.service.shopping']->createOrder($Customer);
108
            } catch (CartException $e) {
109
                $app->addRequestError($e->getMessage());
110
                return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
111 11
            }
112
113
            // セッション情報を削除
114
            $app['session']->remove($this->sessionOrderKey);
115
            $app['session']->remove($this->sessionMultipleKey);
116
        }
117
118
        // 受注関連情報を最新状態に更新
119
        $app['orm.em']->refresh($Order);
120
121
        // form作成
122
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
123
124
        $event = new EventArgs(
125
            array(
126
                'builder' => $builder,
127
                'Order' => $Order,
128 11
            ),
129
            $request
130
        );
131
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_INDEX_INITIALIZE, $event);
132
133
        $form = $builder->getForm();
134
135
        if ($Order->getTotalPrice() < 0) {
136
            // 合計金額がマイナスの場合、エラー
137
            $message = $app->trans('shopping.total.price', array('totalPrice' => number_format($Order->getTotalPrice())));
138
            $app->addError($message);
139
140
            return $app->redirect($app->url('shopping_error'));
141
        }
142
143
        // 複数配送の場合、エラーメッセージを一度だけ表示
144
        if (!$app['session']->has($this->sessionMultipleKey)) {
145
            if (count($Order->getShippings()) > 1) {
146
                $app->addRequestError('shopping.multiple.delivery');
147
            }
148
            $app['session']->set($this->sessionMultipleKey, 'multiple');
149
        }
150
151 11
        return $app->render('Shopping/index.twig', array(
152 11
            'form' => $form->createView(),
153
            'Order' => $Order,
154
        ));
155 12
    }
156
157
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
158
     * 購入処理
159
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
160 3
    public function confirm(Application $app, Request $request)
161
    {
162
        $cartService = $app['eccube.service.cart'];
163
164
        // カートチェック
165
        if (!$cartService->isLocked()) {
166
            // カートが存在しない、カートがロックされていない時はエラー
167
            return $app->redirect($app->url('cart'));
168
        }
169
170
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
171 3
        if (!$Order) {
172
            $app->addError('front.shopping.order.error');
173
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
174
        }
175
176
        if ('POST' !== $request->getMethod()) {
177
            return $app->redirect($app->url('cart'));
178
        }
179
180
        // form作成
181
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
182
183
        $event = new EventArgs(
184
            array(
185
                'builder' => $builder,
186
                'Order' => $Order,
187 3
            ),
188
            $request
189
        );
190
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CONFIRM_INITIALIZE, $event);
191
192
        $form = $builder->getForm();
193
194
        $form->handleRequest($request);
195
196
        if ($form->isSubmitted() && $form->isValid()) {
197
            $data = $form->getData();
198
199
            // トランザクション制御
200
            $em = $app['orm.em'];
201
            $em->getConnection()->beginTransaction();
202
            try {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
203
204
                // お問い合わせ、配送時間などのフォーム項目をセット
205
                $app['eccube.service.shopping']->setFormData($Order, $data);
206
                // 購入処理
207
                $app['eccube.service.shopping']->processPurchase($Order);
208
209
                $em->flush();
210
                $em->getConnection()->commit();
211
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
212
            } catch (ShoppingException $e) {
213
                $em->getConnection()->rollback();
214
215
                $app->log($e);
216
                $app->addError($e->getMessage());
217
218
                return $app->redirect($app->url('shopping_error'));
219
            } catch (\Exception $e) {
220
                $em->getConnection()->rollback();
221
222
                $app->log($e);
223
224
                $app->addError('front.shopping.system.error');
225
                return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
226 3
            }
227
228
            // カート削除
229
            $app['eccube.service.cart']->clear()->save();
230
231
            $event = new EventArgs(
232
                array(
233
                    'form' => $form,
234
                    'Order' => $Order,
235 3
                ),
236
                $request
237
            );
238
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CONFIRM_PROCESSING, $event);
239
240
            if ($event->getResponse() !== null) {
241
                return $event->getResponse();
242
            }
243
244
            // 受注IDをセッションにセット
245
            $app['session']->set($this->sessionOrderKey, $Order->getId());
246
247
            // メール送信
248
            $MailHistory = $app['eccube.service.shopping']->sendOrderMail($Order);
249
250
            $event = new EventArgs(
251
                array(
252
                    'form' => $form,
253
                    'Order' => $Order,
254
                    'MailHistory' => $MailHistory,
255 3
                ),
256
                $request
257
            );
258
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CONFIRM_COMPLETE, $event);
259
260
            if ($event->getResponse() !== null) {
261
                return $event->getResponse();
262
            }
263
264
            // 完了画面表示
265
            return $app->redirect($app->url('shopping_complete'));
266
        }
267
268
        return $app->render('Shopping/index.twig', array(
269
            'form' => $form->createView(),
270
            'Order' => $Order,
271
        ));
272 3
    }
273
274
275
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
276
     * 購入完了画面表示
277
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
278 1
    public function complete(Application $app, Request $request)
279
    {
280
        // 受注IDを取得
281
        $orderId = $app['session']->get($this->sessionOrderKey);
282
283
        $event = new EventArgs(
284
            array(
285
                'orderId' => $orderId,
286 1
            ),
287
            $request
288
        );
289
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_COMPLETE_INITIALIZE, $event);
290
291
        if ($event->getResponse() !== null) {
292
            return $event->getResponse();
293
        }
294
295
        // 受注IDセッションを削除
296
        $app['session']->remove($this->sessionOrderKey);
297
298 1
        return $app->render('Shopping/complete.twig', array(
299
            'orderId' => $orderId,
300
        ));
301 1
    }
302
303
304
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
305
     * 配送業者選択処理
306
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
307 3
    public function delivery(Application $app, Request $request)
308
    {
309
        // カートチェック
310
        if (!$app['eccube.service.cart']->isLocked()) {
311
            // カートが存在しない、カートがロックされていない時はエラー
312
            return $app->redirect($app->url('cart'));
313
        }
314
315
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
316 3
        if (!$Order) {
317
            $app->addError('front.shopping.order.error');
318
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
319
        }
320
321
        if ('POST' !== $request->getMethod()) {
322
            return $app->redirect($app->url('shopping'));
323
        }
324
325
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
326
327
        $event = new EventArgs(
328
            array(
329
                'builder' => $builder,
330
                'Order' => $Order,
331 3
            ),
332
            $request
333
        );
334
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_DELIVERY_INITIALIZE, $event);
335
336
        $form = $builder->getForm();
337
338
        $form->handleRequest($request);
339
340
        if ($form->isSubmitted() && $form->isValid()) {
341
            $data = $form->getData();
342
343 1
            $shippings = $data['shippings'];
344
345 1
            $productDeliveryFeeTotal = 0;
346
            $BaseInfo = $app['eccube.repository.base_info']->get();
347
348
            foreach ($shippings as $Shipping) {
349
                $Delivery = $Shipping->getDelivery();
350
351 1
                if ($Delivery) {
352
                    $deliveryFee = $app['eccube.repository.delivery_fee']->findOneBy(array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
353
                        'Delivery' => $Delivery,
354 1
                        'Pref' => $Shipping->getPref()
355
                    ));
356
357
                    // 商品ごとの配送料合計
358
                    if (!is_null($BaseInfo->getOptionProductDeliveryFee())) {
359
                        $productDeliveryFeeTotal += $app['eccube.service.shopping']->getProductDeliveryFee($Shipping);
360
                    }
361
362
                    $Shipping->setDeliveryFee($deliveryFee);
363
                    $Shipping->setShippingDeliveryFee($deliveryFee->getFee() + $productDeliveryFeeTotal);
364
                    $Shipping->setShippingDeliveryName($Delivery->getName());
365
                }
366
            }
367
368
            // 支払い情報をセット
369 1
            $payment = $data['payment'];
370 1
            $message = $data['message'];
371
372
            $Order->setPayment($payment);
373
            $Order->setPaymentMethod($payment->getMethod());
374
            $Order->setMessage($message);
375
            $Order->setCharge($payment->getCharge());
376
377
            $Order->setDeliveryFeeTotal($app['eccube.service.shopping']->getShippingDeliveryFeeTotal($shippings));
378
379
            // 合計金額の再計算
380
            $Order = $app['eccube.service.shopping']->getAmount($Order);
381
382
            // 受注関連情報を最新状態に更新
383
            $app['orm.em']->flush();
384
385
            $event = new EventArgs(
386
                array(
387
                    'form' => $form,
388
                    'Order' => $Order,
389 1
                ),
390
                $request
391
            );
392
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_DELIVERY_COMPLETE, $event);
393
394
            return $app->redirect($app->url('shopping'));
395
        }
396
397 2
        return $app->render('Shopping/index.twig', array(
398 2
            'form' => $form->createView(),
399
            'Order' => $Order,
400
        ));
401 3
    }
402
403
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
404
     * 支払い方法選択処理
405
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
406 2
    public function payment(Application $app, Request $request)
407
    {
408
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
409 2
        if (!$Order) {
410
            $app->addError('front.shopping.order.error');
411
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
412
        }
413
414
        if ('POST' !== $request->getMethod()) {
415
            return $app->redirect($app->url('shopping'));
416
        }
417
418
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
419
420
        $event = new EventArgs(
421
            array(
422
                'builder' => $builder,
423
                'Order' => $Order,
424 2
            ),
425
            $request
426
        );
427
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_PAYMENT_INITIALIZE, $event);
428
429
        $form = $builder->getForm();
430
431
        $form->handleRequest($request);
432
433
        if ($form->isSubmitted() && $form->isValid()) {
434
            $data = $form->getData();
435 1
            $payment = $data['payment'];
436 1
            $message = $data['message'];
437
438
            $Order->setPayment($payment);
439
            $Order->setPaymentMethod($payment->getMethod());
440
            $Order->setMessage($message);
441
            $Order->setCharge($payment->getCharge());
442
443
            // 合計金額の再計算
444
            $Order = $app['eccube.service.shopping']->getAmount($Order);
445
446
            // 受注関連情報を最新状態に更新
447
            $app['orm.em']->flush();
448
449
            $event = new EventArgs(
450
                array(
451
                    'form' => $form,
452
                    'Order' => $Order,
453 1
                ),
454
                $request
455
            );
456
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_PAYMENT_COMPLETE, $event);
457
458
            return $app->redirect($app->url('shopping'));
459
        }
460
461 1
        return $app->render('Shopping/index.twig', array(
462 1
            'form' => $form->createView(),
463
            'Order' => $Order,
464
        ));
465 2
    }
466
467
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
introduced by
Doc comment for parameter "$id" missing
Loading history...
468
     * お届け先変更がクリックされた場合の処理
469
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
470 3 View Code Duplication
    public function shippingChange(Application $app, Request $request, $id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
471
    {
472
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
473 3
        if (!$Order) {
474
            $app->addError('front.shopping.order.error');
475
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
476
        }
477
478
        if ('POST' !== $request->getMethod()) {
479
            return $app->redirect($app->url('shopping'));
480
        }
481
482
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
483
484
        $event = new EventArgs(
485
            array(
486
                'builder' => $builder,
487
                'Order' => $Order,
488 3
            ),
489
            $request
490
        );
491
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_CHANGE_INITIALIZE, $event);
492
493
        $form = $builder->getForm();
494
495
        $form->handleRequest($request);
496
497
        if ($form->isSubmitted() && $form->isValid()) {
498
            $data = $form->getData();
499 3
            $message = $data['message'];
500
            $Order->setMessage($message);
501
            // 受注情報を更新
502
            $app['orm.em']->flush();
503
504
            // お届け先設定一覧へリダイレクト
505
            return $app->redirect($app->url('shopping_shipping', array('id' => $id)));
506
        }
507
508
        return $app->render('Shopping/index.twig', array(
509
            'form' => $form->createView(),
510
            'Order' => $Order,
511
        ));
512 3
    }
513
514
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
introduced by
Doc comment for parameter "$id" missing
Loading history...
515
     * お届け先の設定一覧からの選択
516
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
517 2
    public function shipping(Application $app, Request $request, $id)
518
    {
519
        // カートチェック
520
        if (!$app['eccube.service.cart']->isLocked()) {
521
            // カートが存在しない、カートがロックされていない時はエラー
522
            return $app->redirect($app->url('cart'));
523
        }
524
525
        if ('POST' === $request->getMethod()) {
526
            $address = $request->get('address');
527
528
            if (is_null($address)) {
529
                // 選択されていなければエラー
530
                return $app->render(
531
                    'Shopping/shipping.twig',
532
                    array(
533
                        'Customer' => $app->user(),
534
                        'shippingId' => $id,
535
                        'error' => true,
536
                    )
537
                );
538
            }
539
540
            // 選択されたお届け先情報を取得
541
            $CustomerAddress = $app['eccube.repository.customer_address']->findOneBy(array(
542
                'Customer' => $app->user(),
543
                'id' => $address,
544
            ));
545
            if (is_null($CustomerAddress)) {
546
                throw new NotFoundHttpException();
547
            }
548
549
            $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
550
            if (!$Order) {
551
                $app->addError('front.shopping.order.error');
552
553
                return $app->redirect($app->url('shopping_error'));
554
            }
555
556
            $Shipping = $Order->findShipping($id);
557
            if (!$Shipping) {
558
                throw new NotFoundHttpException();
559
            }
560
561
            // お届け先情報を更新
562
            $Shipping
563
                ->setFromCustomerAddress($CustomerAddress);
564
565
            // 配送料金の設定
566
            $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
567
568
            // 合計金額の再計算
569
            $Order = $app['eccube.service.shopping']->getAmount($Order);
570
571
            // 配送先を更新
572
            $app['orm.em']->flush();
573
574
            $event = new EventArgs(
575
                array(
576
                    'Order' => $Order,
577
                    'shippingId' => $id,
578
                ),
579
                $request
580
            );
581
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_COMPLETE, $event);
582
583
            return $app->redirect($app->url('shopping'));
584
        }
585
586
        return $app->render(
587 2
            'Shopping/shipping.twig',
588
            array(
589 2
                'Customer' => $app->user(),
590
                'shippingId' => $id,
591 2
                'error' => false,
592
            )
593
        );
594 2
    }
595
596
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
introduced by
Doc comment for parameter "$id" missing
Loading history...
597
     * お届け先の設定(非会員)がクリックされた場合の処理
598
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
599 View Code Duplication
    public function shippingEditChange(Application $app, Request $request, $id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
600
    {
601
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
602
        if (!$Order) {
603
            $app->addError('front.shopping.order.error');
604
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
605
        }
606
607
        if ('POST' !== $request->getMethod()) {
608
            return $app->redirect($app->url('shopping'));
609
        }
610
611
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
612
613
        $event = new EventArgs(
614
            array(
615
                'builder' => $builder,
616
                'Order' => $Order,
617
            ),
618
            $request
619
        );
620
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_CHANGE_INITIALIZE, $event);
621
622
        $form = $builder->getForm();
623
624
        $form->handleRequest($request);
625
626
        if ($form->isSubmitted() && $form->isValid()) {
627
            $data = $form->getData();
628
            $message = $data['message'];
629
            $Order->setMessage($message);
630
            // 受注情報を更新
631
            $app['orm.em']->flush();
632
633
            // お届け先設定一覧へリダイレクト
634
            return $app->redirect($app->url('shopping_shipping_edit', array('id' => $id)));
635
        }
636
637
        return $app->render('Shopping/index.twig', array(
638
            'form' => $form->createView(),
639
            'Order' => $Order,
640
        ));
641
    }
642
643
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
introduced by
Doc comment for parameter "$id" missing
Loading history...
644
     * お届け先の設定(非会員でも使用する)
645
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
646 1
    public function shippingEdit(Application $app, Request $request, $id)
647
    {
648
        // 配送先住所最大値判定
649
        $Customer = $app->user();
650 View Code Duplication
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
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...
651
            $addressCurrNum = count($app->user()->getCustomerAddresses());
652
            $addressMax = $app['config']['deliv_addr_max'];
653
            if ($addressCurrNum >= $addressMax) {
654
                throw new NotFoundHttpException();
655
            }
656
        }
657
658
        // カートチェック
659
        if (!$app['eccube.service.cart']->isLocked()) {
660
            // カートが存在しない、カートがロックされていない時はエラー
661
            return $app->redirect($app->url('cart'));
662
        }
663
664
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
665
        if (!$Order) {
666
            $app->addError('front.shopping.order.error');
667
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
668
        }
669
670
        $Shipping = $Order->findShipping($id);
671
        if (!$Shipping) {
672
            throw new NotFoundHttpException();
673
        }
674
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
675
            $Shipping->clearCustomerAddress();
676
        }
677
678
        $CustomerAddress = new CustomerAddress();
679
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
680
            $CustomerAddress->setCustomer($Customer);
681
        } else {
682
            $CustomerAddress->setFromShipping($Shipping);
683
        }
684
685
        $builder = $app['form.factory']->createBuilder('shopping_shipping', $CustomerAddress);
686
687
        $event = new EventArgs(
688
            array(
689
                'builder' => $builder,
690
                'Order' => $Order,
691
                'Shipping' => $Shipping,
692
                'CustomerAddress' => $CustomerAddress,
693
            ),
694
            $request
695
        );
696
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_INITIALIZE, $event);
697
698
        $form = $builder->getForm();
699
700
        $form->handleRequest($request);
701
702
        if ($form->isSubmitted() && $form->isValid()) {
703
            // 会員の場合、お届け先情報を新規登録
704
            $Shipping->setFromCustomerAddress($CustomerAddress);
705
706 1
            if ($Customer instanceof Customer) {
0 ignored issues
show
Bug introduced by
The class Eccube\Entity\Customer does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
707
                $app['orm.em']->persist($CustomerAddress);
708
            }
709
710
            // 配送料金の設定
711
            $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
712
713
            // 合計金額の再計算
714
            $app['eccube.service.shopping']->getAmount($Order);
715
716
            // 配送先を更新 
717
            $app['orm.em']->flush();
718
719
            $event = new EventArgs(
720
                array(
721
                    'form' => $form,
722
                    'Shipping' => $Shipping,
723
                    'CustomerAddress' => $CustomerAddress,
724 1
                ),
725
                $request
726
            );
727
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_COMPLETE, $event);
728
729
            return $app->redirect($app->url('shopping'));
730
        }
731
732 1
        return $app->render('Shopping/shipping_edit.twig', array(
733 1
            'form' => $form->createView(),
734
            'shippingId' => $id,
735
        ));
736
    }
737
738
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
739
     * お客様情報の変更(非会員)
740
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
741
    public function customer(Application $app, Request $request)
742
    {
743
        if ($request->isXmlHttpRequest()) {
744
            try {
745
                $data = $request->request->all();
746
747
                // 入力チェック
748
                $errors = $this->customerValidation($app, $data);
749
750
                foreach ($errors as $error) {
751 View Code Duplication
                    if ($error->count() != 0) {
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...
752
                        $response = new Response(json_encode('NG'), 400);
753
                        $response->headers->set('Content-Type', 'application/json');
754
                        return $response;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
755
                    }
756
                }
757
758
                $pref = $app['eccube.repository.master.pref']->findOneBy(array('name' => $data['customer_pref']));
759 View Code Duplication
                if (!$pref) {
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...
760
                    $response = new Response(json_encode('NG'), 400);
761
                    $response->headers->set('Content-Type', 'application/json');
762
                    return $response;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
763
                }
764
765
                $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
766
                if (!$Order) {
767
                    $app->addError('front.shopping.order.error');
768
                    return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
769
                }
770
771
                $Order
772
                    ->setName01($data['customer_name01'])
773
                    ->setName02($data['customer_name02'])
774
                    ->setCompanyName($data['customer_company_name'])
775
                    ->setTel01($data['customer_tel01'])
776
                    ->setTel02($data['customer_tel02'])
777
                    ->setTel03($data['customer_tel03'])
778
                    ->setZip01($data['customer_zip01'])
779
                    ->setZip02($data['customer_zip02'])
780
                    ->setZipCode($data['customer_zip01'].$data['customer_zip02'])
781
                    ->setPref($pref)
782
                    ->setAddr01($data['customer_addr01'])
783
                    ->setAddr02($data['customer_addr02'])
784
                    ->setEmail($data['customer_email']);
785
786
                // 配送先を更新
787
                $app['orm.em']->flush();
788
789
                // 受注関連情報を最新状態に更新
790
                $app['orm.em']->refresh($Order);
791
792
                $event = new EventArgs(
793
                    array(
794
                        'Order' => $Order,
795
                        'data' => $data,
796
                    ),
797
                    $request
798
                );
799
                $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CUSTOMER_INITIALIZE, $event);
800
801
                $response = new Response(json_encode('OK'));
802
                $response->headers->set('Content-Type', 'application/json');
803
            } catch (\Exception $e) {
804
                $app['monolog']->error($e);
805
806
                $response = new Response(json_encode('NG'), 500);
807
                $response->headers->set('Content-Type', 'application/json');
808
            }
809
810
            return $response;
811
        }
812
    }
813
814
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
815
     * ログイン
816
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
817 2
    public function login(Application $app, Request $request)
818
    {
819
        if (!$app['eccube.service.cart']->isLocked()) {
820
            return $app->redirect($app->url('cart'));
821
        }
822
823
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
824
            return $app->redirect($app->url('shopping'));
825
        }
826
827
        /* @var $form \Symfony\Component\Form\FormInterface */
828
        $builder = $app['form.factory']->createNamedBuilder('', 'customer_login');
829
830 View Code Duplication
        if ($app->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
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...
831
            $Customer = $app->user();
832
            if ($Customer) {
833
                $builder->get('login_email')->setData($Customer->getEmail());
834
            }
835
        }
836
837
        $event = new EventArgs(
838
            array(
839
                'builder' => $builder,
840 1
            ),
841
            $request
842
        );
843
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_LOGIN_INITIALIZE, $event);
844
845
        $form = $builder->getForm();
846
847 1
        return $app->render('Shopping/login.twig', array(
848
            'error' => $app['security.last_error']($request),
849 1
            'form' => $form->createView(),
850
        ));
851 2
    }
852
853
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
854
     * 非会員処理
855
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
856 2
    public function nonmember(Application $app, Request $request)
857
    {
858
        $cartService = $app['eccube.service.cart'];
859
860
        // カートチェック
861
        if (!$cartService->isLocked()) {
862
            // カートが存在しない、カートがロックされていない時はエラー
863
            return $app->redirect($app->url('cart'));
864
        }
865
866
        // ログイン済みの場合は, 購入画面へリダイレクト.
867
        if ($app->isGranted('ROLE_USER')) {
868
            return $app->redirect($app->url('shopping'));
869
        }
870
871
        // カートチェック
872
        if (count($cartService->getCart()->getCartItems()) <= 0) {
873
            // カートが存在しない時はエラー
874
            return $app->redirect($app->url('cart'));
875
        }
876
877
        $builder = $app['form.factory']->createBuilder('nonmember');
878
879
        $event = new EventArgs(
880
            array(
881
                'builder' => $builder,
882 2
            ),
883
            $request
884
        );
885
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_NONMEMBER_INITIALIZE, $event);
886
887
        $form = $builder->getForm();
888
889
        $form->handleRequest($request);
890
891
        if ($form->isSubmitted() && $form->isValid()) {
892
            $data = $form->getData();
893
            $Customer = new Customer();
894
            $Customer
895 2
                ->setName01($data['name01'])
896 2
                ->setName02($data['name02'])
897 2
                ->setKana01($data['kana01'])
898 2
                ->setKana02($data['kana02'])
899 2
                ->setCompanyName($data['company_name'])
900 2
                ->setEmail($data['email'])
901 2
                ->setTel01($data['tel01'])
902 2
                ->setTel02($data['tel02'])
903 2
                ->setTel03($data['tel03'])
904 2
                ->setZip01($data['zip01'])
905 2
                ->setZip02($data['zip02'])
906 2
                ->setZipCode($data['zip01'].$data['zip02'])
907 2
                ->setPref($data['pref'])
908 2
                ->setAddr01($data['addr01'])
909
                ->setAddr02($data['addr02']);
910
911
            // 非会員複数配送用
912
            $CustomerAddress = new CustomerAddress();
913
            $CustomerAddress
914 2
                ->setCustomer($Customer)
915 2
                ->setName01($data['name01'])
916 2
                ->setName02($data['name02'])
917 2
                ->setKana01($data['kana01'])
918 2
                ->setKana02($data['kana02'])
919 2
                ->setCompanyName($data['company_name'])
920 2
                ->setTel01($data['tel01'])
921 2
                ->setTel02($data['tel02'])
922 2
                ->setTel03($data['tel03'])
923 2
                ->setZip01($data['zip01'])
924 2
                ->setZip02($data['zip02'])
925 2
                ->setZipCode($data['zip01'].$data['zip02'])
926 2
                ->setPref($data['pref'])
927 2
                ->setAddr01($data['addr01'])
928 2
                ->setAddr02($data['addr02'])
929
                ->setDelFlg(Constant::DISABLED);
930
            $Customer->addCustomerAddress($CustomerAddress);
931
932
            // 受注情報を取得
933
            $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
934
935
            // 初回アクセス(受注データがない)の場合は, 受注情報を作成
936
            if (is_null($Order)) {
937
                // 受注情報を作成
938
                try {
939
                    // 受注情報を作成
940
                    $app['eccube.service.shopping']->createOrder($Customer);
941
                } catch (CartException $e) {
942
                    $app->addRequestError($e->getMessage());
943
                    return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
944 2
                }
945
            }
946
947
            // 非会員用セッションを作成
948 2
            $nonMember = array();
949 2
            $nonMember['customer'] = $Customer;
950
            $nonMember['pref'] = $Customer->getPref()->getId();
951
            $app['session']->set($this->sessionKey, $nonMember);
952
953 2
            $customerAddresses = array();
954 2
            $customerAddresses[] = $CustomerAddress;
955
            $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses));
956
957
            $event = new EventArgs(
958
                array(
959
                    'form' => $form,
960
                    'Order' => $Order,
961 2
                ),
962
                $request
963
            );
964
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_NONMEMBER_COMPLETE, $event);
965
966
            if ($event->getResponse() !== null) {
967
                return $event->getResponse();
968
            }
969
970
            return $app->redirect($app->url('shopping'));
971
        }
972
973
        return $app->render('Shopping/nonmember.twig', array(
974
            'form' => $form->createView(),
975
        ));
976 2
    }
977
978
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
979
     * 複数配送処理がクリックされた場合の処理
980
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
981 View Code Duplication
    public function shippingMultipleChange(Application $app, Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
982
    {
983
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
984
        if (!$Order) {
985
            $app->addError('front.shopping.order.error');
986
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
987
        }
988
989
        if ('POST' !== $request->getMethod()) {
990
            return $app->redirect($app->url('shopping'));
991
        }
992
993
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
994
995
        $event = new EventArgs(
996
            array(
997
                'builder' => $builder,
998
                'Order' => $Order,
999
            ),
1000
            $request
1001
        );
1002
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_CHANGE_INITIALIZE, $event);
1003
1004
        $form = $builder->getForm();
1005
1006
        $form->handleRequest($request);
1007
1008
        if ($form->isSubmitted() && $form->isValid()) {
1009
            $data = $form->getData();
1010
            $message = $data['message'];
1011
            $Order->setMessage($message);
1012
            // 受注情報を更新
1013
            $app['orm.em']->flush();
1014
1015
            // 複数配送設定へリダイレクト
1016
            return $app->redirect($app->url('shopping_shipping_multiple'));
1017
        }
1018
1019
        return $app->render('Shopping/index.twig', array(
1020
            'form' => $form->createView(),
1021
            'Order' => $Order,
1022
        ));
1023
    }
1024
1025
1026
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1027
     * 複数配送処理
1028
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1029
    public function shippingMultiple(Application $app, Request $request)
1030
    {
1031
        $cartService = $app['eccube.service.cart'];
1032
1033
        // カートチェック
1034
        if (!$cartService->isLocked()) {
1035
            // カートが存在しない、カートがロックされていない時はエラー
1036
            return $app->redirect($app->url('cart'));
1037
        }
1038
1039
        // カートチェック
1040
        if (count($cartService->getCart()->getCartItems()) <= 0) {
1041
            // カートが存在しない時はエラー
1042
            return $app->redirect($app->url('cart'));
1043
        }
1044
1045
        /** @var \Eccube\Entity\Order $Order */
1046
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
1047
        if (!$Order) {
1048
            $app->addError('front.shopping.order.error');
1049
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1050
        }
1051
1052
        // 複数配送時は商品毎でお届け先を設定する為、商品をまとめた数量を設定
1053
        $compItemQuantities = array();
1054 View Code Duplication
        foreach ($Order->getShippings() 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...
1055
            foreach ($Shipping->getShipmentItems() as $ShipmentItem) {
1056
                $itemId = $ShipmentItem->getProductClass()->getId();
1057
                $quantity = $ShipmentItem->getQuantity();
1058
                if (array_key_exists($itemId, $compItemQuantities)) {
1059
                    $compItemQuantities[$itemId] = $compItemQuantities[$itemId] + $quantity;
1060
                } else {
1061
                    $compItemQuantities[$itemId] = $quantity;
1062
                }
1063
            }
1064
        }
1065
1066
        // 商品に紐づく商品情報を取得
1067
        $shipmentItems = array();
1068
        $productClassIds = array();
1069
        foreach ($Order->getShippings() as $Shipping) {
1070
            foreach ($Shipping->getShipmentItems() as $ShipmentItem) {
1071
                if (!in_array($ShipmentItem->getProductClass()->getId(), $productClassIds)) {
1072
                    $shipmentItems[] = $ShipmentItem;
1073
                }
1074
                $productClassIds[] = $ShipmentItem->getProductClass()->getId();
1075
            }
1076
        }
1077
1078
        $builder = $app->form();
1079
        $builder
1080
            ->add('shipping_multiple', 'collection', array(
1081
                'type' => 'shipping_multiple',
1082
                'data' => $shipmentItems,
1083
                'allow_add' => true,
1084
                'allow_delete' => true,
1085
            ));
1086
1087
        $event = new EventArgs(
1088
            array(
1089
                'builder' => $builder,
1090
                'Order' => $Order,
1091
            ),
1092
            $request
1093
        );
1094
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_INITIALIZE, $event);
1095
1096
        $form = $builder->getForm();
1097
1098
        $form->handleRequest($request);
1099
1100
        $errors = array();
1101
        if ($form->isSubmitted() && $form->isValid()) {
1102
            $data = $form['shipping_multiple'];
1103
1104
            // 数量が超えていないか、同一でないとエラー
1105
            $itemQuantities = array();
1106
            foreach ($data as $mulitples) {
1107
                /** @var \Eccube\Entity\ShipmentItem $multipleItem */
1108
                $multipleItem = $mulitples->getData();
1109 View Code Duplication
                foreach ($mulitples as $items) {
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...
1110
                    foreach ($items as $item) {
1111
                        $quantity = $item['quantity']->getData();
1112
                        $itemId = $multipleItem->getProductClass()->getId();
1113
                        if (array_key_exists($itemId, $itemQuantities)) {
1114
                            $itemQuantities[$itemId] = $itemQuantities[$itemId] + $quantity;
1115
                        } else {
1116
                            $itemQuantities[$itemId] = $quantity;
1117
                        }
1118
                    }
1119
                }
1120
            }
1121
1122
            foreach ($compItemQuantities as $key => $value) {
1123
                if (array_key_exists($key, $itemQuantities)) {
1124
                    if ($itemQuantities[$key] != $value) {
1125
                        $errors[] = array('message' => '数量の数が異なっています。');
1126
1127
                        // 対象がなければエラー
1128
                        return $app->render('Shopping/shipping_multiple.twig', array(
1129
                            'form' => $form->createView(),
1130
                            'shipmentItems' => $shipmentItems,
1131
                            'compItemQuantities' => $compItemQuantities,
1132
                            'errors' => $errors,
1133
                        ));
1134
                    }
1135
                }
1136
            }
1137
1138
            // お届け先情報をdelete/insert
1139
            $shippings = $Order->getShippings();
1140
            foreach ($shippings as $Shipping) {
1141
                $Order->removeShipping($Shipping);
1142
                $app['orm.em']->remove($Shipping);
1143
            }
1144
1145
            foreach ($data as $mulitples) {
1146
                /** @var \Eccube\Entity\ShipmentItem $multipleItem */
1147
                $multipleItem = $mulitples->getData();
1148
1149
                foreach ($mulitples as $items) {
1150
                    foreach ($items as $item) {
1151
                        // 追加された配送先情報を作成
1152
                        $Delivery = $multipleItem->getShipping()->getDelivery();
1153
1154
                        // 選択された情報を取得
1155
                        $data = $item['customer_address']->getData();
1156
                        if ($data instanceof CustomerAddress) {
0 ignored issues
show
Bug introduced by
The class Eccube\Entity\CustomerAddress does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
1157
                            // 会員の場合、CustomerAddressオブジェクトを取得
1158
                            $CustomerAddress = $data;
1159
                        } else {
1160
                            // 非会員の場合、選択されたindexが取得される
1161
                            $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey);
1162
                            $customerAddresses = unserialize($customerAddresses);
1163
                            $CustomerAddress = $customerAddresses[$data];
1164
                            $pref = $app['eccube.repository.master.pref']->find($CustomerAddress->getPref()->getId());
1165
                            $CustomerAddress->setPref($pref);
1166
                        }
1167
1168
                        $Shipping = new Shipping();
1169
                        $Shipping
1170
                            ->setFromCustomerAddress($CustomerAddress)
1171
                            ->setDelivery($Delivery)
1172
                            ->setDelFlg(Constant::DISABLED)
1173
                            ->setOrder($Order);
1174
                        $app['orm.em']->persist($Shipping);
1175
1176
                        $ProductClass = $multipleItem->getProductClass();
1177
                        $Product = $multipleItem->getProduct();
1178
                        $quantity = $item['quantity']->getData();
1179
1180
                        $ShipmentItem = new ShipmentItem();
1181
                        $ShipmentItem->setShipping($Shipping)
1182
                            ->setOrder($Order)
1183
                            ->setProductClass($ProductClass)
1184
                            ->setProduct($Product)
1185
                            ->setProductName($Product->getName())
1186
                            ->setProductCode($ProductClass->getCode())
1187
                            ->setPrice($ProductClass->getPrice02())
1188
                            ->setQuantity($quantity);
1189
1190
                        $ClassCategory1 = $ProductClass->getClassCategory1();
1191
                        if (!is_null($ClassCategory1)) {
1192
                            $ShipmentItem->setClasscategoryName1($ClassCategory1->getName());
1193
                            $ShipmentItem->setClassName1($ClassCategory1->getClassName()->getName());
1194
                        }
1195
                        $ClassCategory2 = $ProductClass->getClassCategory2();
1196
                        if (!is_null($ClassCategory2)) {
1197
                            $ShipmentItem->setClasscategoryName2($ClassCategory2->getName());
1198
                            $ShipmentItem->setClassName2($ClassCategory2->getClassName()->getName());
1199
                        }
1200
                        $Shipping->addShipmentItem($ShipmentItem);
1201
                        $app['orm.em']->persist($ShipmentItem);
1202
1203
                        // 配送料金の設定
1204
                        $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
1205
1206
                        $Order->addShipping($Shipping);
1207
                    }
1208
                }
1209
            }
1210
1211
            // 合計金額の再計算
1212
            $Order = $app['eccube.service.shopping']->getAmount($Order);
1213
1214
            // 配送先を更新
1215
            $app['orm.em']->flush();
1216
1217
            $event = new EventArgs(
1218
                array(
1219
                    'form' => $form,
1220
                    'Order' => $Order,
1221
                ),
1222
                $request
1223
            );
1224
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_COMPLETE, $event);
1225
1226
            return $app->redirect($app->url('shopping'));
1227
        }
1228
1229
        return $app->render('Shopping/shipping_multiple.twig', array(
1230
            'form' => $form->createView(),
1231
            'shipmentItems' => $shipmentItems,
1232
            'compItemQuantities' => $compItemQuantities,
1233
            'errors' => $errors,
1234
        ));
1235
    }
1236
1237
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1238
     * 非会員用複数配送設定時の新規お届け先の設定
1239
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1240
    public function shippingMultipleEdit(Application $app, Request $request)
1241
    {
1242
        // カートチェック
1243
        if (!$app['eccube.service.cart']->isLocked()) {
1244
            // カートが存在しない、カートがロックされていない時はエラー
1245
            return $app->redirect($app->url('cart'));
1246
        }
1247
1248
        // 非会員用Customerを取得
1249
        $Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey);
1250
        $CustomerAddress = new CustomerAddress();
1251
        $CustomerAddress->setCustomer($Customer);
1252
        $Customer->addCustomerAddress($CustomerAddress);
1253
1254
        $builder = $app['form.factory']->createBuilder('shopping_shipping', $CustomerAddress);
1255
1256
        $event = new EventArgs(
1257
            array(
1258
                'builder' => $builder,
1259
                'Customer' => $Customer,
1260
            ),
1261
            $request
1262
        );
1263
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_EDIT_INITIALIZE, $event);
1264
1265
        $form = $builder->getForm();
1266
1267
        $form->handleRequest($request);
1268
1269
        if ($form->isSubmitted() && $form->isValid()) {
1270
            // 非会員用のセッションに追加
1271
            $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey);
1272
            $customerAddresses = unserialize($customerAddresses);
1273
            $customerAddresses[] = $CustomerAddress;
1274
            $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses));
1275
1276
            $event = new EventArgs(
1277
                array(
1278
                    'form' => $form,
1279
                    'CustomerAddresses' => $customerAddresses,
1280
                ),
1281
                $request
1282
            );
1283
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_EDIT_COMPLETE, $event);
1284
1285
            return $app->redirect($app->url('shopping_shipping_multiple'));
1286
        }
1287
1288
        return $app->render('Shopping/shipping_multiple_edit.twig', array(
1289
            'form' => $form->createView(),
1290
        ));
1291
    }
1292
1293
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1294
     * 購入エラー画面表示
1295
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1296 1
    public function shoppingError(Application $app, Request $request)
1297
    {
1298
1299
        $event = new EventArgs(
1300 1
            array(),
1301
            $request
1302
        );
1303
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_ERROR_COMPLETE, $event);
1304
1305
        if ($event->getResponse() !== null) {
1306
            return $event->getResponse();
1307
        }
1308
1309
        return $app->render('Shopping/shopping_error.twig');
1310 1
    }
1311
1312
    /**
1313
     * 非会員でのお客様情報変更時の入力チェック
1314
     *
1315
     * @param Application $app
1316
     * @param array       $data リクエストパラメータ
1317
     * @return array
1318
     */
1319
    private function customerValidation(Application $app, array $data)
1320
    {
1321
        // 入力チェック
1322
        $errors = array();
1323
1324
        $errors[] = $app['validator']->validateValue($data['customer_name01'], array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
1325
            new Assert\NotBlank(),
1326
            new Assert\Length(array('max' => $app['config']['name_len'],)),
0 ignored issues
show
introduced by
Add a single space after each comma delimiter
Loading history...
1327
            new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace'))
1328
        ));
1329
1330
        $errors[] = $app['validator']->validateValue($data['customer_name02'], array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
1331
            new Assert\NotBlank(),
1332
            new Assert\Length(array('max' => $app['config']['name_len'],)),
0 ignored issues
show
introduced by
Add a single space after each comma delimiter
Loading history...
1333
            new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace'))
1334
        ));
1335
1336
        $errors[] = $app['validator']->validateValue($data['customer_company_name'], array(
1337
            new Assert\Length(array('max' => $app['config']['stext_len'])),
1338
        ));
1339
1340
        $errors[] = $app['validator']->validateValue($data['customer_tel01'], array(
1341
            new Assert\NotBlank(),
1342
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1343
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1344
        ));
1345
1346
        $errors[] = $app['validator']->validateValue($data['customer_tel02'], array(
1347
            new Assert\NotBlank(),
1348
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1349
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1350
        ));
1351
1352
        $errors[] = $app['validator']->validateValue($data['customer_tel03'], array(
1353
            new Assert\NotBlank(),
1354
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1355
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1356
        ));
1357
1358
        $errors[] = $app['validator']->validateValue($data['customer_zip01'], array(
1359
            new Assert\NotBlank(),
1360
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1361
            new Assert\Length(array('min' => $app['config']['zip01_len'], 'max' => $app['config']['zip01_len'])),
1362
        ));
1363
1364
        $errors[] = $app['validator']->validateValue($data['customer_zip02'], array(
1365
            new Assert\NotBlank(),
1366
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1367
            new Assert\Length(array('min' => $app['config']['zip02_len'], 'max' => $app['config']['zip02_len'])),
1368
        ));
1369
1370
        $errors[] = $app['validator']->validateValue($data['customer_addr01'], array(
1371
            new Assert\NotBlank(),
1372
            new Assert\Length(array('max' => $app['config']['address1_len'])),
1373
        ));
1374
1375
        $errors[] = $app['validator']->validateValue($data['customer_addr02'], array(
1376
            new Assert\NotBlank(),
1377
            new Assert\Length(array('max' => $app['config']['address2_len'])),
1378
        ));
1379
1380
        $errors[] = $app['validator']->validateValue($data['customer_email'], array(
1381
            new Assert\NotBlank(),
1382
            new Assert\Email(),
1383
        ));
1384
1385
        return $errors;
1386
    }
1387
}
1388