ShoppingController   F
last analyzed

Complexity

Total Complexity 123

Size/Duplication

Total Lines 1426
Duplicated Lines 13.96 %

Coupling/Cohesion

Components 1
Dependencies 17

Test Coverage

Coverage 66.81%

Importance

Changes 0
Metric Value
dl 199
loc 1426
ccs 477
cts 714
cp 0.6681
rs 0.6314
c 0
b 0
f 0
wmc 123
lcom 1
cbo 17

17 Methods

Rating   Name   Duplication   Size   Complexity  
C index() 5 89 10
D confirm() 8 129 10
B complete() 0 26 2
D delivery() 0 101 9
B payment() 0 67 5
B shippingChange() 43 43 5
C shipping() 0 84 7
B shippingEditChange() 43 43 5
C shippingEdit() 7 101 11
C customer() 12 80 7
B login() 6 35 5
D nonmember() 5 128 9
B shippingMultipleChange() 43 43 5
F shippingMultiple() 27 214 26
A shippingMultipleEdit() 0 58 4
A shoppingError() 0 15 2
A customerValidation() 0 68 1

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 36
    public function index(Application $app, Request $request)
73
    {
74 36
        $cartService = $app['eccube.service.cart'];
75
76
        // カートチェック
77 36
        if (!$cartService->isLocked()) {
78 3
            log_info('カートが存在しません');
79
            // カートが存在しない、カートがロックされていない時はエラー
80 3
            return $app->redirect($app->url('cart'));
81
        }
82
83
        // カートチェック
84 33 View Code Duplication
        if (count($cartService->getCart()->getCartItems()) <= 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...
85 1
            log_info('カートに商品が入っていないためショッピングカート画面にリダイレクト');
86
            // カートが存在しない時はエラー
87 1
            return $app->redirect($app->url('cart'));
88
        }
89
90
        // 登録済みの受注情報を取得
91 32
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
92
93
        // 初回アクセス(受注情報がない)の場合は, 受注情報を作成
94 32
        if (is_null($Order)) {
95
            // 未ログインの場合, ログイン画面へリダイレクト.
96 32
            if (!$app->isGranted('IS_AUTHENTICATED_FULLY')) {
97
                // 非会員でも一度会員登録されていればショッピング画面へ遷移
98 12
                $Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey);
99
100 12
                if (is_null($Customer)) {
101
                    log_info('未ログインのためログイン画面にリダイレクト');
102 12
                    return $app->redirect($app->url('shopping_login'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
103
                }
104
            } else {
105 20
                $Customer = $app->user();
106
            }
107
108
            try {
109
                // 受注情報を作成
110 32
                $Order = $app['eccube.service.shopping']->createOrder($Customer);
111
            } catch (CartException $e) {
112
                log_error('初回受注情報作成エラー', array($e->getMessage()));
113
                $app->addRequestError($e->getMessage());
114
                return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
115
            }
116
117
            // セッション情報を削除
118 32
            $app['session']->remove($this->sessionOrderKey);
119 32
            $app['session']->remove($this->sessionMultipleKey);
120
        }
121
122
        // 受注関連情報を最新状態に更新
123 32
        $app['orm.em']->refresh($Order);
124
125
        // form作成
126 32
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
127
128 32
        $event = new EventArgs(
129
            array(
130 32
                'builder' => $builder,
131 32
                'Order' => $Order,
132
            ),
133
            $request
134
        );
135 32
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_INDEX_INITIALIZE, $event);
136
137 32
        $form = $builder->getForm();
138
139 32
        if ($Order->getTotalPrice() < 0) {
140
            // 合計金額がマイナスの場合、エラー
141
            log_info('受注金額マイナスエラー', array($Order->getId()));
142
            $message = $app->trans('shopping.total.price', array('totalPrice' => number_format($Order->getTotalPrice())));
143
            $app->addError($message);
144
145
            return $app->redirect($app->url('shopping_error'));
146
        }
147
148
        // 複数配送の場合、エラーメッセージを一度だけ表示
149 32
        if (!$app['session']->has($this->sessionMultipleKey)) {
150 32
            if (count($Order->getShippings()) > 1) {
151
                $app->addRequestError('shopping.multiple.delivery');
152
            }
153 32
            $app['session']->set($this->sessionMultipleKey, 'multiple');
154
        }
155
156 32
        return $app->render('Shopping/index.twig', array(
157 32
            'form' => $form->createView(),
158 32
            'Order' => $Order,
159
        ));
160
    }
161
162
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
163
     * 購入処理
164
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
165 9
    public function confirm(Application $app, Request $request)
166
    {
167 9
        $cartService = $app['eccube.service.cart'];
168
169
        // カートチェック
170 9
        if (!$cartService->isLocked()) {
171
            // カートが存在しない、カートがロックされていない時はエラー
172
            log_info('カートが存在しません');
173
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
174
        }
175
176 9
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
177 9
        if (!$Order) {
178
            log_info('購入処理中の受注情報がないため購入エラー');
179
            $app->addError('front.shopping.order.error');
180
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
181
        }
182
183 9
        if ('POST' !== $request->getMethod()) {
184
            return $app->redirect($app->url('cart'));
185
        }
186
187
        // form作成
188 9
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
189
190 9
        $event = new EventArgs(
191
            array(
192 9
                'builder' => $builder,
193 9
                'Order' => $Order,
194
            ),
195
            $request
196
        );
197 9
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CONFIRM_INITIALIZE, $event);
198
199 9
        $form = $builder->getForm();
200
201 9
        $form->handleRequest($request);
202
203 9
        if ($form->isSubmitted() && $form->isValid()) {
204 9
            $data = $form->getData();
205
206 9
            log_info('購入処理開始', array($Order->getId()));
207
208
            // トランザクション制御
209 9
            $em = $app['orm.em'];
210 9
            $em->getConnection()->beginTransaction();
211
            try {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
212
213
                // お問い合わせ、配送時間などのフォーム項目をセット
214 9
                $app['eccube.service.shopping']->setFormData($Order, $data);
215
                // 購入処理
216 9
                $app['eccube.service.shopping']->processPurchase($Order);
217
218 9
                $em->flush();
219 9
                $em->getConnection()->commit();
220
221 9
                log_info('購入処理完了', array($Order->getId()));
222
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
223
            } catch (ShoppingException $e) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
224
225
                log_error('購入エラー', array($e->getMessage()));
226
227
                $em->getConnection()->rollback();
228
229
                $app->log($e);
230
                $app->addError($e->getMessage());
231
232
                return $app->redirect($app->url('shopping_error'));
233
            } catch (\Exception $e) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
234
235
                log_error('予期しないエラー', array($e->getMessage()));
236
237
                $em->getConnection()->rollback();
238
239
                $app->log($e);
240
241
                $app->addError('front.shopping.system.error');
242
                return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
243
            }
244
245
            // カート削除
246 9
            $app['eccube.service.cart']->clear()->save();
247
248 9
            $event = new EventArgs(
249
                array(
250 9
                    'form' => $form,
251 9
                    'Order' => $Order,
252
                ),
253
                $request
254
            );
255 9
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CONFIRM_PROCESSING, $event);
256
257 9 View Code Duplication
            if ($event->getResponse() !== null) {
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...
258
                log_info('イベントレスポンス返却', array($Order->getId()));
259
                return $event->getResponse();
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
260
            }
261
262
            // 受注IDをセッションにセット
263 9
            $app['session']->set($this->sessionOrderKey, $Order->getId());
264
265
            // メール送信
266 9
            $MailHistory = $app['eccube.service.shopping']->sendOrderMail($Order);
267
268 9
            $event = new EventArgs(
269
                array(
270 9
                    'form' => $form,
271 9
                    'Order' => $Order,
272 9
                    'MailHistory' => $MailHistory,
273
                ),
274
                $request
275
            );
276 9
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CONFIRM_COMPLETE, $event);
277
278 9 View Code Duplication
            if ($event->getResponse() !== null) {
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...
279
                log_info('イベントレスポンス返却', array($Order->getId()));
280
                return $event->getResponse();
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
281
            }
282
283
            // 完了画面表示
284 9
            return $app->redirect($app->url('shopping_complete'));
285
        }
286
287
        log_info('購入チェックエラー', array($Order->getId()));
288
289
        return $app->render('Shopping/index.twig', array(
290
            'form' => $form->createView(),
291
            'Order' => $Order,
292
        ));
293
    }
294
295
296
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
297
     * 購入完了画面表示
298
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
299 2
    public function complete(Application $app, Request $request)
300
    {
301
        // 受注IDを取得
302 2
        $orderId = $app['session']->get($this->sessionOrderKey);
303
304 2
        $event = new EventArgs(
305
            array(
306 2
                'orderId' => $orderId,
307
            ),
308
            $request
309
        );
310 2
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_COMPLETE_INITIALIZE, $event);
311
312 2
        if ($event->getResponse() !== null) {
313
            return $event->getResponse();
314
        }
315
316
        // 受注IDセッションを削除
317 2
        $app['session']->remove($this->sessionOrderKey);
318
319 2
        log_info('購入処理完了', array($orderId));
320
321 2
        return $app->render('Shopping/complete.twig', array(
322 2
            'orderId' => $orderId,
323
        ));
324
    }
325
326
327
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
328
     * 配送業者選択処理
329
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
330 6
    public function delivery(Application $app, Request $request)
331
    {
332
        // カートチェック
333 6
        if (!$app['eccube.service.cart']->isLocked()) {
334
            // カートが存在しない、カートがロックされていない時はエラー
335
            log_info('カートが存在しません');
336
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
337
        }
338
339 6
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
340 6
        if (!$Order) {
341
            log_info('購入処理中の受注情報がないため購入エラー');
342
            $app->addError('front.shopping.order.error');
343
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
344
        }
345
346 6
        if ('POST' !== $request->getMethod()) {
347
            return $app->redirect($app->url('shopping'));
348
        }
349
350 6
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
351
352 6
        $event = new EventArgs(
353
            array(
354 6
                'builder' => $builder,
355 6
                'Order' => $Order,
356
            ),
357
            $request
358
        );
359 6
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_DELIVERY_INITIALIZE, $event);
360
361 6
        $form = $builder->getForm();
362
363 6
        $form->handleRequest($request);
364
365 6
        if ($form->isSubmitted() && $form->isValid()) {
366 2
            log_info('配送業者変更処理開始', array($Order->getId()));
367
368 2
            $data = $form->getData();
369
370 2
            $shippings = $data['shippings'];
371
372 2
            $productDeliveryFeeTotal = 0;
373 2
            $BaseInfo = $app['eccube.repository.base_info']->get();
374
375 2
            foreach ($shippings as $Shipping) {
376 2
                $Delivery = $Shipping->getDelivery();
377
378 2
                if ($Delivery) {
379 2
                    $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...
380 2
                        'Delivery' => $Delivery,
381 2
                        'Pref' => $Shipping->getPref()
382
                    ));
383
384
                    // 商品ごとの配送料合計
385 2
                    if (!is_null($BaseInfo->getOptionProductDeliveryFee())) {
386 2
                        $productDeliveryFeeTotal += $app['eccube.service.shopping']->getProductDeliveryFee($Shipping);
387
                    }
388
389 2
                    $Shipping->setDeliveryFee($deliveryFee);
390 2
                    $Shipping->setShippingDeliveryFee($deliveryFee->getFee() + $productDeliveryFeeTotal);
391 2
                    $Shipping->setShippingDeliveryName($Delivery->getName());
392
                }
393
            }
394
395
            // 支払い情報をセット
396 2
            $payment = $data['payment'];
397 2
            $message = $data['message'];
398
399 2
            $Order->setPayment($payment);
400 2
            $Order->setPaymentMethod($payment->getMethod());
401 2
            $Order->setMessage($message);
402 2
            $Order->setCharge($payment->getCharge());
403
404 2
            $Order->setDeliveryFeeTotal($app['eccube.service.shopping']->getShippingDeliveryFeeTotal($shippings));
405
406
            // 合計金額の再計算
407 2
            $Order = $app['eccube.service.shopping']->getAmount($Order);
408
409
            // 受注関連情報を最新状態に更新
410 2
            $app['orm.em']->flush();
411
412 2
            $event = new EventArgs(
413
                array(
414 2
                    'form' => $form,
415 2
                    'Order' => $Order,
416
                ),
417
                $request
418
            );
419 2
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_DELIVERY_COMPLETE, $event);
420
421 2
            log_info('配送業者変更処理完了', array($Order->getId()));
422 2
            return $app->redirect($app->url('shopping'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
423
        }
424
425 4
        log_info('配送業者変更入力チェックエラー', array($Order->getId()));
426 4
        return $app->render('Shopping/index.twig', array(
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
427 4
            'form' => $form->createView(),
428 4
            'Order' => $Order,
429
        ));
430
    }
431
432
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
433
     * 支払い方法選択処理
434
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
435 4
    public function payment(Application $app, Request $request)
436
    {
437 4
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
438 4
        if (!$Order) {
439
            log_info('購入処理中の受注情報がないため購入エラー');
440
            $app->addError('front.shopping.order.error');
441
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
442
        }
443
444 4
        if ('POST' !== $request->getMethod()) {
445
            return $app->redirect($app->url('shopping'));
446
        }
447
448 4
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
449
450 4
        $event = new EventArgs(
451
            array(
452 4
                'builder' => $builder,
453 4
                'Order' => $Order,
454
            ),
455
            $request
456
        );
457 4
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_PAYMENT_INITIALIZE, $event);
458
459 4
        $form = $builder->getForm();
460
461 4
        $form->handleRequest($request);
462
463 4
        if ($form->isSubmitted() && $form->isValid()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
464
465 2
            log_info('支払い方法変更処理開始', array("id" => $Order->getId()));
466
467 2
            $data = $form->getData();
468 2
            $payment = $data['payment'];
469 2
            $message = $data['message'];
470
471 2
            $Order->setPayment($payment);
472 2
            $Order->setPaymentMethod($payment->getMethod());
473 2
            $Order->setMessage($message);
474 2
            $Order->setCharge($payment->getCharge());
475
476
            // 合計金額の再計算
477 2
            $Order = $app['eccube.service.shopping']->getAmount($Order);
478
479
            // 受注関連情報を最新状態に更新
480 2
            $app['orm.em']->flush();
481
482 2
            $event = new EventArgs(
483
                array(
484 2
                    'form' => $form,
485 2
                    'Order' => $Order,
486
                ),
487
                $request
488
            );
489 2
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_PAYMENT_COMPLETE, $event);
490
491 2
            log_info('支払い方法変更処理完了', array("id" => $Order->getId(), "payment" => $payment->getId()));
492
493 2
            return $app->redirect($app->url('shopping'));
494
        }
495
496 2
        log_info('支払い方法変更入力チェックエラー', array("id" => $Order->getId()));
497 2
        return $app->render('Shopping/index.twig', array(
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
498 2
            'form' => $form->createView(),
499 2
            'Order' => $Order,
500
        ));
501
    }
502
503
    /**
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...
504
     * お届け先変更がクリックされた場合の処理
505
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
506 6 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...
507
    {
508 6
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
509 6
        if (!$Order) {
510
            $app->addError('front.shopping.order.error');
511
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
512
        }
513
514 6
        if ('POST' !== $request->getMethod()) {
515
            return $app->redirect($app->url('shopping'));
516
        }
517
518 6
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
519
520 6
        $event = new EventArgs(
521
            array(
522 6
                'builder' => $builder,
523 6
                'Order' => $Order,
524
            ),
525
            $request
526
        );
527 6
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_CHANGE_INITIALIZE, $event);
528
529 6
        $form = $builder->getForm();
530
531 6
        $form->handleRequest($request);
532
533 6
        if ($form->isSubmitted() && $form->isValid()) {
534 6
            $data = $form->getData();
535 6
            $message = $data['message'];
536 6
            $Order->setMessage($message);
537
            // 受注情報を更新
538 6
            $app['orm.em']->flush();
539
540
            // お届け先設定一覧へリダイレクト
541 6
            return $app->redirect($app->url('shopping_shipping', array('id' => $id)));
542
        }
543
544
        return $app->render('Shopping/index.twig', array(
545
            'form' => $form->createView(),
546
            'Order' => $Order,
547
        ));
548
    }
549
550
    /**
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...
551
     * お届け先の設定一覧からの選択
552
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
553 4
    public function shipping(Application $app, Request $request, $id)
554
    {
555
        // カートチェック
556 4
        if (!$app['eccube.service.cart']->isLocked()) {
557
            // カートが存在しない、カートがロックされていない時はエラー
558
            log_info('カートが存在しません');
559
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
560
        }
561
562 4
        if ('POST' === $request->getMethod()) {
563
            $address = $request->get('address');
564
565
            if (is_null($address)) {
566
                // 選択されていなければエラー
567
                log_info('お届け先入力チェックエラー');
568
                return $app->render(
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
569
                    'Shopping/shipping.twig',
570
                    array(
571
                        'Customer' => $app->user(),
572
                        'shippingId' => $id,
573
                        'error' => true,
574
                    )
575
                );
576
            }
577
578
            // 選択されたお届け先情報を取得
579
            $CustomerAddress = $app['eccube.repository.customer_address']->findOneBy(array(
580
                'Customer' => $app->user(),
581
                'id' => $address,
582
            ));
583
            if (is_null($CustomerAddress)) {
584
                throw new NotFoundHttpException('選択されたお届け先住所が存在しない');
585
            }
586
587
            $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
588
            if (!$Order) {
589
                log_info('購入処理中の受注情報がないため購入エラー');
590
                $app->addError('front.shopping.order.error');
591
592
                return $app->redirect($app->url('shopping_error'));
593
            }
594
595
            $Shipping = $Order->findShipping($id);
596
            if (!$Shipping) {
597
                throw new NotFoundHttpException('お届け先情報が存在しない');
598
            }
599
600
            log_info('お届先情報更新開始', array($Shipping->getId()));
601
602
            // お届け先情報を更新
603
            $Shipping
604
                ->setFromCustomerAddress($CustomerAddress);
605
606
            // 配送料金の設定
607
            $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
608
609
            // 合計金額の再計算
610
            $Order = $app['eccube.service.shopping']->getAmount($Order);
611
612
            // 配送先を更新
613
            $app['orm.em']->flush();
614
615
            $event = new EventArgs(
616
                array(
617
                    'Order' => $Order,
618
                    'shippingId' => $id,
619
                ),
620
                $request
621
            );
622
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_COMPLETE, $event);
623
624
            log_info('お届先情報更新完了', array($Shipping->getId()));
625
            return $app->redirect($app->url('shopping'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
626
        }
627
628 4
        return $app->render(
629 4
            'Shopping/shipping.twig',
630
            array(
631 4
                'Customer' => $app->user(),
632 4
                'shippingId' => $id,
633
                'error' => false,
634
            )
635
        );
636
    }
637
638
    /**
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...
639
     * お届け先の設定(非会員)がクリックされた場合の処理
640
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
641 5 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...
642
    {
643 5
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
644 5
        if (!$Order) {
645
            $app->addError('front.shopping.order.error');
646
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
647
        }
648
649 5
        if ('POST' !== $request->getMethod()) {
650 1
            return $app->redirect($app->url('shopping'));
651
        }
652
653 4
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
654
655 4
        $event = new EventArgs(
656
            array(
657 4
                'builder' => $builder,
658 4
                'Order' => $Order,
659
            ),
660
            $request
661
        );
662 4
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_CHANGE_INITIALIZE, $event);
663
664 4
        $form = $builder->getForm();
665
666 4
        $form->handleRequest($request);
667
668 4
        if ($form->isSubmitted() && $form->isValid()) {
669 3
            $data = $form->getData();
670 3
            $message = $data['message'];
671 3
            $Order->setMessage($message);
672
            // 受注情報を更新
673 3
            $app['orm.em']->flush();
674
675
            // お届け先設定一覧へリダイレクト
676 3
            return $app->redirect($app->url('shopping_shipping_edit', array('id' => $id)));
677
        }
678
679 1
        return $app->render('Shopping/index.twig', array(
680 1
            'form' => $form->createView(),
681 1
            'Order' => $Order,
682
        ));
683
    }
684
685
    /**
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...
686
     * お届け先の設定(非会員でも使用する)
687
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
688 4
    public function shippingEdit(Application $app, Request $request, $id)
689
    {
690
        // 配送先住所最大値判定
691 4
        $Customer = $app->user();
692 4 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...
693 2
            $addressCurrNum = count($app->user()->getCustomerAddresses());
694 2
            $addressMax = $app['config']['deliv_addr_max'];
695 2
            if ($addressCurrNum >= $addressMax) {
696
                throw new NotFoundHttpException('配送先住所最大数エラー');
697
            }
698
        }
699
700
        // カートチェック
701 4
        if (!$app['eccube.service.cart']->isLocked()) {
702
            // カートが存在しない、カートがロックされていない時はエラー
703
            log_info('カートが存在しません');
704
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
705
        }
706
707 4
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
708 4
        if (!$Order) {
709
            log_info('購入処理中の受注情報がないため購入エラー');
710
            $app->addError('front.shopping.order.error');
711
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
712
        }
713
714 4
        $Shipping = $Order->findShipping($id);
715 4
        if (!$Shipping) {
716
            throw new NotFoundHttpException('設定されている配送先が存在しない');
717
        }
718 4
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
719 2
            $Shipping->clearCustomerAddress();
720
        }
721
722 4
        $CustomerAddress = new CustomerAddress();
723 4
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
724 2
            $CustomerAddress->setCustomer($Customer);
725
        } else {
726 2
            $CustomerAddress->setFromShipping($Shipping);
727
        }
728
729 4
        $builder = $app['form.factory']->createBuilder('shopping_shipping', $CustomerAddress);
730
731 4
        $event = new EventArgs(
732
            array(
733 4
                'builder' => $builder,
734 4
                'Order' => $Order,
735 4
                'Shipping' => $Shipping,
736 4
                'CustomerAddress' => $CustomerAddress,
737
            ),
738
            $request
739
        );
740 4
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_INITIALIZE, $event);
741
742 4
        $form = $builder->getForm();
743
744 4
        $form->handleRequest($request);
745
746 4
        if ($form->isSubmitted() && $form->isValid()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
747
748 3
            log_info('お届け先追加処理開始', array('id' => $Order->getId(), 'shipping' => $id));
749
750
            // 会員の場合、お届け先情報を新規登録
751 3
            $Shipping->setFromCustomerAddress($CustomerAddress);
752
753 3
            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...
754 2
                $app['orm.em']->persist($CustomerAddress);
755 2
                log_info('新規お届け先登録', array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
756 2
                    'id' => $Order->getId(),
757 2
                    'shipping' => $id,
758 2
                    'customer address' => $CustomerAddress->getId()));
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...
759
            }
760
761
            // 配送料金の設定
762 3
            $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
763
764
            // 合計金額の再計算
765 3
            $app['eccube.service.shopping']->getAmount($Order);
766
767
            // 配送先を更新 
768 3
            $app['orm.em']->flush();
769
770 3
            $event = new EventArgs(
771
                array(
772 3
                    'form' => $form,
773 3
                    'Shipping' => $Shipping,
774 3
                    'CustomerAddress' => $CustomerAddress,
775
                ),
776
                $request
777
            );
778 3
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_COMPLETE, $event);
779
780 3
            log_info('お届け先追加処理完了', array('id' => $Order->getId(), 'shipping' => $id));
781 3
            return $app->redirect($app->url('shopping'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
782
        }
783
784 3
        return $app->render('Shopping/shipping_edit.twig', array(
785 3
            'form' => $form->createView(),
786 3
            'shippingId' => $id,
787
        ));
788
    }
789
790
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
791
     * お客様情報の変更(非会員)
792
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
793
    public function customer(Application $app, Request $request)
794
    {
795
        if ($request->isXmlHttpRequest()) {
796
            try {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
797
798
                log_info('非会員お客様情報変更処理開始');
799
800
                $data = $request->request->all();
801
802
                // 入力チェック
803
                $errors = $this->customerValidation($app, $data);
804
805
                foreach ($errors as $error) {
806 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...
807
                        log_info('非会員お客様情報変更入力チェックエラー');
808
                        $response = new Response(json_encode('NG'), 400);
809
                        $response->headers->set('Content-Type', 'application/json');
810
                        return $response;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
811
                    }
812
                }
813
814
                $pref = $app['eccube.repository.master.pref']->findOneBy(array('name' => $data['customer_pref']));
815 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...
816
                    log_info('非会員お客様情報変更入力チェックエラー');
817
                    $response = new Response(json_encode('NG'), 400);
818
                    $response->headers->set('Content-Type', 'application/json');
819
                    return $response;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
820
                }
821
822
                $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
823
                if (!$Order) {
824
                    log_info('カートが存在しません');
825
                    $app->addError('front.shopping.order.error');
826
                    return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
827
                }
828
829
                $Order
830
                    ->setName01($data['customer_name01'])
831
                    ->setName02($data['customer_name02'])
832
                    ->setCompanyName($data['customer_company_name'])
833
                    ->setTel01($data['customer_tel01'])
834
                    ->setTel02($data['customer_tel02'])
835
                    ->setTel03($data['customer_tel03'])
836
                    ->setZip01($data['customer_zip01'])
837
                    ->setZip02($data['customer_zip02'])
838
                    ->setZipCode($data['customer_zip01'].$data['customer_zip02'])
839
                    ->setPref($pref)
840
                    ->setAddr01($data['customer_addr01'])
841
                    ->setAddr02($data['customer_addr02'])
842
                    ->setEmail($data['customer_email']);
843
844
                // 配送先を更新
845
                $app['orm.em']->flush();
846
847
                // 受注関連情報を最新状態に更新
848
                $app['orm.em']->refresh($Order);
849
850
                $event = new EventArgs(
851
                    array(
852
                        'Order' => $Order,
853
                        'data' => $data,
854
                    ),
855
                    $request
856
                );
857
                $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CUSTOMER_INITIALIZE, $event);
858
859
                log_info('非会員お客様情報変更処理完了', array($Order->getId()));
860
                $response = new Response(json_encode('OK'));
861
                $response->headers->set('Content-Type', 'application/json');
862
            } catch (\Exception $e) {
863
                log_error('予期しないエラー', array($e->getMessage()));
864
                $app['monolog']->error($e);
865
866
                $response = new Response(json_encode('NG'), 500);
867
                $response->headers->set('Content-Type', 'application/json');
868
            }
869
870
            return $response;
871
        }
872
    }
873
874
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
875
     * ログイン
876
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
877 4
    public function login(Application $app, Request $request)
878
    {
879 4
        if (!$app['eccube.service.cart']->isLocked()) {
880 3
            return $app->redirect($app->url('cart'));
881
        }
882
883 1
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
884
            return $app->redirect($app->url('shopping'));
885
        }
886
887
        /* @var $form \Symfony\Component\Form\FormInterface */
888 1
        $builder = $app['form.factory']->createNamedBuilder('', 'customer_login');
889
890 1 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...
891
            $Customer = $app->user();
892
            if ($Customer) {
893
                $builder->get('login_email')->setData($Customer->getEmail());
894
            }
895
        }
896
897 1
        $event = new EventArgs(
898
            array(
899 1
                'builder' => $builder,
900
            ),
901
            $request
902
        );
903 1
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_LOGIN_INITIALIZE, $event);
904
905 1
        $form = $builder->getForm();
906
907 1
        return $app->render('Shopping/login.twig', array(
908 1
            'error' => $app['security.last_error']($request),
909 1
            'form' => $form->createView(),
910
        ));
911
    }
912
913
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
914
     * 非会員処理
915
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
916 16
    public function nonmember(Application $app, Request $request)
917
    {
918 16
        $cartService = $app['eccube.service.cart'];
919
920
        // カートチェック
921 16
        if (!$cartService->isLocked()) {
922
            // カートが存在しない、カートがロックされていない時はエラー
923 1
            log_info('カートが存在しません');
924 1
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
925
        }
926
927
        // ログイン済みの場合は, 購入画面へリダイレクト.
928 15
        if ($app->isGranted('ROLE_USER')) {
929 1
            return $app->redirect($app->url('shopping'));
930
        }
931
932
        // カートチェック
933 14 View Code Duplication
        if (count($cartService->getCart()->getCartItems()) <= 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...
934
            // カートが存在しない時はエラー
935
            log_info('カートに商品が入っていないためショッピングカート画面にリダイレクト');
936
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
937
        }
938
939 14
        $builder = $app['form.factory']->createBuilder('nonmember');
940
941 14
        $event = new EventArgs(
942
            array(
943 14
                'builder' => $builder,
944
            ),
945
            $request
946
        );
947 14
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_NONMEMBER_INITIALIZE, $event);
948
949 14
        $form = $builder->getForm();
950
951 14
        $form->handleRequest($request);
952
953 14
        if ($form->isSubmitted() && $form->isValid()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
954
955 13
            log_info('非会員お客様情報登録開始');
956
957 13
            $data = $form->getData();
958 13
            $Customer = new Customer();
959
            $Customer
960 13
                ->setName01($data['name01'])
961 13
                ->setName02($data['name02'])
962 13
                ->setKana01($data['kana01'])
963 13
                ->setKana02($data['kana02'])
964 13
                ->setCompanyName($data['company_name'])
965 13
                ->setEmail($data['email'])
966 13
                ->setTel01($data['tel01'])
967 13
                ->setTel02($data['tel02'])
968 13
                ->setTel03($data['tel03'])
969 13
                ->setZip01($data['zip01'])
970 13
                ->setZip02($data['zip02'])
971 13
                ->setZipCode($data['zip01'].$data['zip02'])
972 13
                ->setPref($data['pref'])
973 13
                ->setAddr01($data['addr01'])
974 13
                ->setAddr02($data['addr02']);
975
976
            // 非会員複数配送用
977 13
            $CustomerAddress = new CustomerAddress();
978
            $CustomerAddress
979 13
                ->setCustomer($Customer)
980 13
                ->setName01($data['name01'])
981 13
                ->setName02($data['name02'])
982 13
                ->setKana01($data['kana01'])
983 13
                ->setKana02($data['kana02'])
984 13
                ->setCompanyName($data['company_name'])
985 13
                ->setTel01($data['tel01'])
986 13
                ->setTel02($data['tel02'])
987 13
                ->setTel03($data['tel03'])
988 13
                ->setZip01($data['zip01'])
989 13
                ->setZip02($data['zip02'])
990 13
                ->setZipCode($data['zip01'].$data['zip02'])
991 13
                ->setPref($data['pref'])
992 13
                ->setAddr01($data['addr01'])
993 13
                ->setAddr02($data['addr02'])
994 13
                ->setDelFlg(Constant::DISABLED);
995 13
            $Customer->addCustomerAddress($CustomerAddress);
996
997
            // 受注情報を取得
998 13
            $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
999
1000
            // 初回アクセス(受注データがない)の場合は, 受注情報を作成
1001 13
            if (is_null($Order)) {
1002
                // 受注情報を作成
1003
                try {
1004
                    // 受注情報を作成
1005 13
                    $Order = $app['eccube.service.shopping']->createOrder($Customer);
1006
                } catch (CartException $e) {
1007
                    $app->addRequestError($e->getMessage());
1008
                    return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1009
                }
1010
            }
1011
1012
            // 非会員用セッションを作成
1013 13
            $nonMember = array();
1014 13
            $nonMember['customer'] = $Customer;
1015 13
            $nonMember['pref'] = $Customer->getPref()->getId();
1016 13
            $app['session']->set($this->sessionKey, $nonMember);
1017
1018 13
            $customerAddresses = array();
1019 13
            $customerAddresses[] = $CustomerAddress;
1020 13
            $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses));
1021
1022 13
            $event = new EventArgs(
1023
                array(
1024 13
                    'form' => $form,
1025 13
                    'Order' => $Order,
1026
                ),
1027
                $request
1028
            );
1029 13
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_NONMEMBER_COMPLETE, $event);
1030
1031 13
            if ($event->getResponse() !== null) {
1032
                return $event->getResponse();
1033
            }
1034
1035 13
            log_info('非会員お客様情報登録完了', array($Order->getId()));
1036
1037 13
            return $app->redirect($app->url('shopping'));
1038
        }
1039
1040 1
        return $app->render('Shopping/nonmember.twig', array(
1041 1
            'form' => $form->createView(),
1042
        ));
1043
    }
1044
1045
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1046
     * 複数配送処理がクリックされた場合の処理
1047
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1048 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...
1049
    {
1050
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
1051
        if (!$Order) {
1052
            $app->addError('front.shopping.order.error');
1053
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1054
        }
1055
1056
        if ('POST' !== $request->getMethod()) {
1057
            return $app->redirect($app->url('shopping'));
1058
        }
1059
1060
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
1061
1062
        $event = new EventArgs(
1063
            array(
1064
                'builder' => $builder,
1065
                'Order' => $Order,
1066
            ),
1067
            $request
1068
        );
1069
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_CHANGE_INITIALIZE, $event);
1070
1071
        $form = $builder->getForm();
1072
1073
        $form->handleRequest($request);
1074
1075
        if ($form->isSubmitted() && $form->isValid()) {
1076
            $data = $form->getData();
1077
            $message = $data['message'];
1078
            $Order->setMessage($message);
1079
            // 受注情報を更新
1080
            $app['orm.em']->flush();
1081
1082
            // 複数配送設定へリダイレクト
1083
            return $app->redirect($app->url('shopping_shipping_multiple'));
1084
        }
1085
1086
        return $app->render('Shopping/index.twig', array(
1087
            'form' => $form->createView(),
1088
            'Order' => $Order,
1089
        ));
1090
    }
1091
1092
1093
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1094
     * 複数配送処理
1095
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1096 3
    public function shippingMultiple(Application $app, Request $request)
1097
    {
1098 3
        $cartService = $app['eccube.service.cart'];
1099
1100
        // カートチェック
1101 3
        if (!$cartService->isLocked()) {
1102
            // カートが存在しない、カートがロックされていない時はエラー
1103
            log_info('カートが存在しません');
1104
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1105
        }
1106
1107
        // カートチェック
1108 3 View Code Duplication
        if (count($cartService->getCart()->getCartItems()) <= 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...
1109
            // カートが存在しない時はエラー
1110
            log_info('カートに商品が入っていないためショッピングカート画面にリダイレクト');
1111
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1112
        }
1113
1114
        /** @var \Eccube\Entity\Order $Order */
1115 3
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
1116 3
        if (!$Order) {
1117
            log_info('購入処理中の受注情報がないため購入エラー');
1118
            $app->addError('front.shopping.order.error');
1119
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1120
        }
1121
1122
        // 複数配送時は商品毎でお届け先を設定する為、商品をまとめた数量を設定
1123 3
        $compItemQuantities = array();
1124 3 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...
1125 3
            foreach ($Shipping->getShipmentItems() as $ShipmentItem) {
1126 3
                $itemId = $ShipmentItem->getProductClass()->getId();
1127 3
                $quantity = $ShipmentItem->getQuantity();
1128 3
                if (array_key_exists($itemId, $compItemQuantities)) {
1129
                    $compItemQuantities[$itemId] = $compItemQuantities[$itemId] + $quantity;
1130
                } else {
1131 3
                    $compItemQuantities[$itemId] = $quantity;
1132
                }
1133
            }
1134
        }
1135
1136
        // 商品に紐づく商品情報を取得
1137 3
        $shipmentItems = array();
1138 3
        $productClassIds = array();
1139 3
        foreach ($Order->getShippings() as $Shipping) {
1140 3
            foreach ($Shipping->getShipmentItems() as $ShipmentItem) {
1141 3
                if (!in_array($ShipmentItem->getProductClass()->getId(), $productClassIds)) {
1142 3
                    $shipmentItems[] = $ShipmentItem;
1143
                }
1144 3
                $productClassIds[] = $ShipmentItem->getProductClass()->getId();
1145
            }
1146
        }
1147
1148 3
        $builder = $app->form();
1149
        $builder
1150 3
            ->add('shipping_multiple', 'collection', array(
1151 3
                'type' => 'shipping_multiple',
1152 3
                'data' => $shipmentItems,
1153
                'allow_add' => true,
1154
                'allow_delete' => true,
1155
            ));
1156
1157 3
        $event = new EventArgs(
1158
            array(
1159 3
                'builder' => $builder,
1160 3
                'Order' => $Order,
1161
            ),
1162
            $request
1163
        );
1164 3
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_INITIALIZE, $event);
1165
1166 3
        $form = $builder->getForm();
1167
1168 3
        $form->handleRequest($request);
1169
1170 3
        $errors = array();
1171 3
        if ($form->isSubmitted() && $form->isValid()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
1172
1173 2
            log_info('複数配送設定処理開始', array($Order->getId()));
1174 2
            $data = $form['shipping_multiple'];
1175
1176
            // 数量が超えていないか、同一でないとエラー
1177 2
            $itemQuantities = array();
1178 2
            foreach ($data as $mulitples) {
1179
                /** @var \Eccube\Entity\ShipmentItem $multipleItem */
1180 2
                $multipleItem = $mulitples->getData();
1181 2 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...
1182 2
                    foreach ($items as $item) {
1183 2
                        $quantity = $item['quantity']->getData();
1184 2
                        $itemId = $multipleItem->getProductClass()->getId();
1185 2
                        if (array_key_exists($itemId, $itemQuantities)) {
1186 2
                            $itemQuantities[$itemId] = $itemQuantities[$itemId] + $quantity;
1187
                        } else {
1188 2
                            $itemQuantities[$itemId] = $quantity;
1189
                        }
1190
                    }
1191
                }
1192
            }
1193
1194 2
            foreach ($compItemQuantities as $key => $value) {
1195 2
                if (array_key_exists($key, $itemQuantities)) {
1196 2
                    if ($itemQuantities[$key] != $value) {
1197
                        $errors[] = array('message' => $app->trans('shopping.multiple.quantity.diff'));
1198
1199
                        // 対象がなければエラー
1200
                        log_info('複数配送設定入力チェックエラー', array($Order->getId()));
1201
                        return $app->render('Shopping/shipping_multiple.twig', array(
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1202
                            'form' => $form->createView(),
1203
                            'shipmentItems' => $shipmentItems,
1204
                            'compItemQuantities' => $compItemQuantities,
1205 2
                            'errors' => $errors,
1206
                        ));
1207
                    }
1208
                }
1209
            }
1210
1211
            // お届け先情報をdelete/insert
1212 2
            $shippings = $Order->getShippings();
1213 2
            foreach ($shippings as $Shipping) {
1214 2
                $Order->removeShipping($Shipping);
1215 2
                $app['orm.em']->remove($Shipping);
1216
            }
1217
1218 2
            foreach ($data as $mulitples) {
1219
                /** @var \Eccube\Entity\ShipmentItem $multipleItem */
1220 2
                $multipleItem = $mulitples->getData();
1221
1222 2
                foreach ($mulitples as $items) {
1223 2
                    foreach ($items as $item) {
1224
                        // 追加された配送先情報を作成
1225 2
                        $Delivery = $multipleItem->getShipping()->getDelivery();
1226
1227
                        // 選択された情報を取得
1228 2
                        $data = $item['customer_address']->getData();
1229 2
                        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...
1230
                            // 会員の場合、CustomerAddressオブジェクトを取得
1231 1
                            $CustomerAddress = $data;
1232
                        } else {
1233
                            // 非会員の場合、選択されたindexが取得される
1234 1
                            $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey);
1235 1
                            $customerAddresses = unserialize($customerAddresses);
1236 1
                            $CustomerAddress = $customerAddresses[$data];
1237 1
                            $pref = $app['eccube.repository.master.pref']->find($CustomerAddress->getPref()->getId());
1238 1
                            $CustomerAddress->setPref($pref);
1239
                        }
1240
1241 2
                        $Shipping = new Shipping();
1242
                        $Shipping
1243 2
                            ->setFromCustomerAddress($CustomerAddress)
1244 2
                            ->setDelivery($Delivery)
1245 2
                            ->setDelFlg(Constant::DISABLED)
1246 2
                            ->setOrder($Order);
1247 2
                        $app['orm.em']->persist($Shipping);
1248
1249 2
                        $ProductClass = $multipleItem->getProductClass();
1250 2
                        $Product = $multipleItem->getProduct();
1251 2
                        $quantity = $item['quantity']->getData();
1252
1253 2
                        $ShipmentItem = new ShipmentItem();
1254 2
                        $ShipmentItem->setShipping($Shipping)
1255 2
                            ->setOrder($Order)
1256 2
                            ->setProductClass($ProductClass)
1257 2
                            ->setProduct($Product)
1258 2
                            ->setProductName($Product->getName())
1259 2
                            ->setProductCode($ProductClass->getCode())
1260 2
                            ->setPrice($ProductClass->getPrice02())
1261 2
                            ->setQuantity($quantity);
1262
1263 2
                        $ClassCategory1 = $ProductClass->getClassCategory1();
1264 2
                        if (!is_null($ClassCategory1)) {
1265 2
                            $ShipmentItem->setClasscategoryName1($ClassCategory1->getName());
1266 2
                            $ShipmentItem->setClassName1($ClassCategory1->getClassName()->getName());
1267
                        }
1268 2
                        $ClassCategory2 = $ProductClass->getClassCategory2();
1269 2
                        if (!is_null($ClassCategory2)) {
1270 2
                            $ShipmentItem->setClasscategoryName2($ClassCategory2->getName());
1271 2
                            $ShipmentItem->setClassName2($ClassCategory2->getClassName()->getName());
1272
                        }
1273 2
                        $Shipping->addShipmentItem($ShipmentItem);
1274 2
                        $app['orm.em']->persist($ShipmentItem);
1275
1276
                        // 配送料金の設定
1277 2
                        $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
1278
1279 2
                        $Order->addShipping($Shipping);
1280
                    }
1281
                }
1282
            }
1283
1284
            // 合計金額の再計算
1285 2
            $Order = $app['eccube.service.shopping']->getAmount($Order);
1286
1287
            // 配送先を更新
1288 2
            $app['orm.em']->flush();
1289
1290 2
            $event = new EventArgs(
1291
                array(
1292 2
                    'form' => $form,
1293 2
                    'Order' => $Order,
1294
                ),
1295
                $request
1296
            );
1297 2
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_COMPLETE, $event);
1298
1299 2
            log_info('複数配送設定処理完了', array($Order->getId()));
1300 2
            return $app->redirect($app->url('shopping'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1301
        }
1302
1303 3
        return $app->render('Shopping/shipping_multiple.twig', array(
1304 3
            'form' => $form->createView(),
1305 3
            'shipmentItems' => $shipmentItems,
1306 3
            'compItemQuantities' => $compItemQuantities,
1307 3
            'errors' => $errors,
1308
        ));
1309
    }
1310
1311
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1312
     * 非会員用複数配送設定時の新規お届け先の設定
1313
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1314 1
    public function shippingMultipleEdit(Application $app, Request $request)
1315
    {
1316
        // カートチェック
1317 1
        if (!$app['eccube.service.cart']->isLocked()) {
1318
            log_info('カートが存在しません');
1319
            // カートが存在しない、カートがロックされていない時はエラー
1320
            return $app->redirect($app->url('cart'));
1321
        }
1322
1323
        // 非会員用Customerを取得
1324 1
        $Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey);
1325 1
        $CustomerAddress = new CustomerAddress();
1326 1
        $CustomerAddress->setCustomer($Customer);
1327 1
        $Customer->addCustomerAddress($CustomerAddress);
1328
1329 1
        $builder = $app['form.factory']->createBuilder('shopping_shipping', $CustomerAddress);
1330
1331 1
        $event = new EventArgs(
1332
            array(
1333 1
                'builder' => $builder,
1334 1
                'Customer' => $Customer,
1335
            ),
1336
            $request
1337
        );
1338 1
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_EDIT_INITIALIZE, $event);
1339
1340 1
        $form = $builder->getForm();
1341
1342 1
        $form->handleRequest($request);
1343
1344 1
        if ($form->isSubmitted() && $form->isValid()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
1345
1346 1
            log_info('非会員お届け先追加処理開始');
1347
1348
            // 非会員用のセッションに追加
1349 1
            $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey);
1350 1
            $customerAddresses = unserialize($customerAddresses);
1351 1
            $customerAddresses[] = $CustomerAddress;
1352 1
            $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses));
1353
1354 1
            $event = new EventArgs(
1355
                array(
1356 1
                    'form' => $form,
1357 1
                    'CustomerAddresses' => $customerAddresses,
1358
                ),
1359
                $request
1360
            );
1361 1
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_EDIT_COMPLETE, $event);
1362
1363 1
            log_info('非会員お届け先追加処理完了');
1364
1365 1
            return $app->redirect($app->url('shopping_shipping_multiple'));
1366
        }
1367
1368 1
        return $app->render('Shopping/shipping_multiple_edit.twig', array(
1369 1
            'form' => $form->createView(),
1370
        ));
1371
    }
1372
1373
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1374
     * 購入エラー画面表示
1375
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1376 2
    public function shoppingError(Application $app, Request $request)
1377
    {
1378
1379 2
        $event = new EventArgs(
1380 2
            array(),
1381
            $request
1382
        );
1383 2
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_ERROR_COMPLETE, $event);
1384
1385 2
        if ($event->getResponse() !== null) {
1386
            return $event->getResponse();
1387
        }
1388
1389 2
        return $app->render('Shopping/shopping_error.twig');
1390
    }
1391
1392
    /**
1393
     * 非会員でのお客様情報変更時の入力チェック
1394
     *
1395
     * @param Application $app
1396
     * @param array $data リクエストパラメータ
1397
     * @return array
1398
     */
1399
    private function customerValidation(Application $app, array $data)
1400
    {
1401
        // 入力チェック
1402
        $errors = array();
1403
1404
        $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...
1405
            new Assert\NotBlank(),
1406
            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...
1407
            new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace'))
1408
        ));
1409
1410
        $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...
1411
            new Assert\NotBlank(),
1412
            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...
1413
            new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace'))
1414
        ));
1415
1416
        $errors[] = $app['validator']->validateValue($data['customer_company_name'], array(
1417
            new Assert\Length(array('max' => $app['config']['stext_len'])),
1418
        ));
1419
1420
        $errors[] = $app['validator']->validateValue($data['customer_tel01'], array(
1421
            new Assert\NotBlank(),
1422
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1423
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1424
        ));
1425
1426
        $errors[] = $app['validator']->validateValue($data['customer_tel02'], array(
1427
            new Assert\NotBlank(),
1428
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1429
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1430
        ));
1431
1432
        $errors[] = $app['validator']->validateValue($data['customer_tel03'], array(
1433
            new Assert\NotBlank(),
1434
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1435
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1436
        ));
1437
1438
        $errors[] = $app['validator']->validateValue($data['customer_zip01'], array(
1439
            new Assert\NotBlank(),
1440
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1441
            new Assert\Length(array('min' => $app['config']['zip01_len'], 'max' => $app['config']['zip01_len'])),
1442
        ));
1443
1444
        $errors[] = $app['validator']->validateValue($data['customer_zip02'], array(
1445
            new Assert\NotBlank(),
1446
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1447
            new Assert\Length(array('min' => $app['config']['zip02_len'], 'max' => $app['config']['zip02_len'])),
1448
        ));
1449
1450
        $errors[] = $app['validator']->validateValue($data['customer_addr01'], array(
1451
            new Assert\NotBlank(),
1452
            new Assert\Length(array('max' => $app['config']['address1_len'])),
1453
        ));
1454
1455
        $errors[] = $app['validator']->validateValue($data['customer_addr02'], array(
1456
            new Assert\NotBlank(),
1457
            new Assert\Length(array('max' => $app['config']['address2_len'])),
1458
        ));
1459
1460
        $errors[] = $app['validator']->validateValue($data['customer_email'], array(
1461
            new Assert\NotBlank(),
1462
            new Assert\Email(array('strict' => true)),
1463
        ));
1464
1465
        return $errors;
1466
    }
1467
}
1468