ShoppingController::shippingMultiple()   F
last analyzed

Complexity

Conditions 26
Paths 5379

Size

Total Lines 199
Code Lines 125

Duplication

Lines 22
Ratio 11.06 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
dl 22
loc 199
rs 2
c 3
b 0
f 0
cc 26
eloc 125
nc 5379
nop 2

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

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