Failed Conditions
Push — 3.0.9-dev ( 4e695e...ec0f79 )
by chihiro
26:04
created

ShoppingController::customer()   C

Complexity

Conditions 7
Paths 43

Size

Total Lines 72
Code Lines 48

Duplication

Lines 10
Ratio 13.89 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 10
loc 72
ccs 0
cts 0
cp 0
rs 6.7427
cc 7
eloc 48
nc 43
nop 2
crap 56

How to fix   Long Method   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
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 19
    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 7
            }
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 7
            }
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 7
        }
120
121
        // 受注関連情報を最新状態に更新
122
        $app['orm.em']->refresh($Order);
123
124
        // form作成
125
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
126
127
        $event = new EventArgs(
128
            array(
129
                'form' => $form,
130
                'order' => $Order,
131 7
            ),
132
            $request
133
        );
134
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_INDEX_INITIALIZE, $event);
135
136
        // 複数配送の場合、エラーメッセージを一度だけ表示
137
        if (!$app['session']->has($this->sessionMultipleKey)) {
138
            if (count($Order->getShippings()) > 1) {
139
                $app->addRequestError('shopping.multiple.delivery');
140
            }
141
            $app['session']->set($this->sessionMultipleKey, 'multiple');
142
        }
143
144 7
        return $app->render('Shopping/index.twig', array(
145 7
            'form' => $form->createView(),
146
            'Order' => $Order,
147
        ));
148 19
    }
149
150
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
151
     * 購入処理
152
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
153 2
    public function confirm(Application $app, Request $request)
154
    {
155
        $cartService = $app['eccube.service.cart'];
156
157
        // カートチェック
158
        if (!$cartService->isLocked()) {
159
            // カートが存在しない、カートがロックされていない時はエラー
160
            return $app->redirect($app->url('cart'));
161
        }
162
163
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
164 2
        if (!$Order) {
165
            $app->addError('front.shopping.order.error');
166
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
167
        }
168
169
        if ('POST' !== $request->getMethod()) {
170
            return $app->redirect($app->url('cart'));
171
        }
172
173
        // form作成
174
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
175
176
        $event = new EventArgs(
177
            array(
178
                'form' => $form,
179
                'order' => $Order,
180 2
            ),
181
            $request
182
        );
183
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CONFIRM_INITIALIZE, $event);
184
185
        $form->handleRequest($request);
186
187
        if ($form->isSubmitted() && $form->isValid()) {
188
            $data = $form->getData();
189
190
            // トランザクション制御
191
            $em = $app['orm.em'];
192
            $em->getConnection()->beginTransaction();
193
            try {
194
                // 商品公開ステータスチェック、商品制限数チェック、在庫チェック
195
                $check = $app['eccube.service.shopping']->isOrderProduct($em, $Order);
196 2
                if (!$check) {
197
                    $em->getConnection()->rollback();
198
199
                    $app->addError('front.shopping.stock.error');
200
                    return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
201
                }
202
203
                // 受注情報、配送情報を更新
204
                $app['eccube.service.shopping']->setOrderUpdate($Order, $data);
205
                // 在庫情報を更新
206
                $app['eccube.service.shopping']->setStockUpdate($em, $Order);
207
208
                if ($app->isGranted('ROLE_USER')) {
209
                    // 会員の場合、購入金額を更新
210
                    $app['eccube.service.shopping']->setCustomerUpdate($Order, $app->user());
211
                }
212
213
                $em->flush();
214
                $em->getConnection()->commit();
215
216
            } catch (\Exception $e) {
217
                $em->getConnection()->rollback();
218
219
                $app->log($e);
220
221
                $app->addError('front.shopping.system.error');
222
                return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
223 2
            }
224
225
            // カート削除
226
            $app['eccube.service.cart']->clear()->save();
227
228
            $event = new EventArgs(
229
                array(
230
                    'form' => $form,
231
                    'order' => $Order,
232 2
                ),
233
                $request
234
            );
235
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CONFIRM_PROCESSING, $event);
236
237
            if ($event->getResponse() !== null) {
238
                return $event->getResponse();
239
            }
240
241
            // メール送信
242
            $app['eccube.service.mail']->sendOrderMail($Order);
243
244
            // 受注IDをセッションにセット
245
            $app['session']->set($this->sessionOrderKey, $Order->getId());
246
247
            // 送信履歴を保存.
248
            $MailTemplate = $app['eccube.repository.mail_template']->find(1);
249
250 2
            $body = $app->renderView($MailTemplate->getFileName(), array(
251 2
                'header' => $MailTemplate->getHeader(),
252 2
                'footer' => $MailTemplate->getFooter(),
253
                'Order' => $Order,
254
            ));
255
256
            $MailHistory = new MailHistory();
257
            $MailHistory
258
                ->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...
259 2
                ->setMailBody($body)
260 2
                ->setMailTemplate($MailTemplate)
261
                ->setSendDate(new \DateTime())
262
                ->setOrder($Order);
263
            $app['orm.em']->persist($MailHistory);
264
            $app['orm.em']->flush($MailHistory);
265
266
            $event = new EventArgs(
267
                array(
268
                    'form' => $form,
269
                    'order' => $Order,
270
                    'mailHistory' => $MailHistory,
271 2
                ),
272
                $request
273
            );
274
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CONFIRM_COMPLETE, $event);
275
276
            if ($event->getResponse() !== null) {
277
                return $event->getResponse();
278
            }
279
280
            // 完了画面表示
281
            return $app->redirect($app->url('shopping_complete'));
282
        }
283
284
        return $app->render('Shopping/index.twig', array(
285
            'form' => $form->createView(),
286
            'Order' => $Order,
287
        ));
288 2
    }
289
290
291
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
292
     * 購入完了画面表示
293
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
294 1
    public function complete(Application $app, Request $request)
295
    {
296
        // 受注IDを取得
297
        $orderId = $app['session']->get($this->sessionOrderKey);
298
299
        $event = new EventArgs(
300
            array(
301
                'orderId' => $orderId,
302 1
            ),
303
            $request
304
        );
305
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_COMPLETE_INITIALIZE, $event);
306
307
        if ($event->getResponse() !== null) {
308
            return $event->getResponse();
309
        }
310
311
        // 受注IDセッションを削除
312
        $app['session']->remove($this->sessionOrderKey);
313
314 1
        return $app->render('Shopping/complete.twig', array(
315
            'orderId' => $orderId,
316
        ));
317 1
    }
318
319
320
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
321
     * 配送業者選択処理
322
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
323 3
    public function delivery(Application $app, Request $request)
324
    {
325
        // カートチェック
326
        if (!$app['eccube.service.cart']->isLocked()) {
327
            // カートが存在しない、カートがロックされていない時はエラー
328
            return $app->redirect($app->url('cart'));
329
        }
330
331
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
332 3
        if (!$Order) {
333
            $app->addError('front.shopping.order.error');
334
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
335
        }
336
337
        if ('POST' !== $request->getMethod()) {
338
            return $app->redirect($app->url('shopping'));
339
        }
340
341
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
342
343
        $event = new EventArgs(
344
            array(
345
                'form' => $form,
346
                'order' => $Order,
347
            ),
348
            $request
349
        );
350
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_DELIVERY_INITIALIZE, $event);
351
352
        $form->handleRequest($request);
353
354
        if ($form->isSubmitted() && $form->isValid()) {
355
            $data = $form->getData();
356
357
            $shippings = $data['shippings'];
358
359
            $productDeliveryFeeTotal = 0;
360
            $BaseInfo = $app['eccube.repository.base_info']->get();
361
362
            foreach ($shippings as $Shipping) {
363
                $Delivery = $Shipping->getDelivery();
364
365
                if ($Delivery) {
366
                    $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...
367
                        'Delivery' => $Delivery,
368
                        'Pref' => $Shipping->getPref()
369
                    ));
370
371
                    // 商品ごとの配送料合計
372
                    if (!is_null($BaseInfo->getOptionProductDeliveryFee())) {
373
                        $productDeliveryFeeTotal += $app['eccube.service.shopping']->getProductDeliveryFee($Shipping);
374
                    }
375
376
                    $Shipping->setDeliveryFee($deliveryFee);
377
                    $Shipping->setShippingDeliveryFee($deliveryFee->getFee() + $productDeliveryFeeTotal);
378
                    $Shipping->setShippingDeliveryName($Delivery->getName());
379
                }
380
            }
381
382
            // 支払い情報をセット
383
            $payment = $data['payment'];
384
            $message = $data['message'];
385
386
            $Order->setPayment($payment);
387
            $Order->setPaymentMethod($payment->getMethod());
388
            $Order->setMessage($message);
389
            $Order->setCharge($payment->getCharge());
390
391
            $Order->setDeliveryFeeTotal($app['eccube.service.shopping']->getShippingDeliveryFeeTotal($shippings));
392
393
            $total = $Order->getSubTotal() + $Order->getCharge() + $Order->getDeliveryFeeTotal();
394
395
            $Order->setTotal($total);
396
            $Order->setPaymentTotal($total);
397
398
            // 受注関連情報を最新状態に更新
399
            $app['orm.em']->flush();
400
401
            $event = new EventArgs(
402
                array(
403
                    'form' => $form,
404
                    'order' => $Order,
405
                ),
406
                $request
407
            );
408
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_DELIVERY_COMPLETE, $event);
409
410
            return $app->redirect($app->url('shopping'));
411
        }
412
413
        return $app->render('Shopping/index.twig', array(
414
            'form' => $form->createView(),
415
            'Order' => $Order,
416
        ));
417 3
    }
418
419
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
420
     * 支払い方法選択処理
421
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
422 2
    public function payment(Application $app, Request $request)
423
    {
424
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
425 2
        if (!$Order) {
426
            $app->addError('front.shopping.order.error');
427
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
428
        }
429
430
        if ('POST' !== $request->getMethod()) {
431
            return $app->redirect($app->url('shopping'));
432
        }
433
434
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
435
436
        $event = new EventArgs(
437
            array(
438
                'form' => $form,
439
                'order' => $Order,
440
            ),
441
            $request
442
        );
443
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_PAYMENT_INITIALIZE, $event);
444
445
        $form->handleRequest($request);
446
447
        if ($form->isSubmitted() && $form->isValid()) {
448
            $data = $form->getData();
449
            $payment = $data['payment'];
450
            $message = $data['message'];
451
452
            $Order->setPayment($payment);
453
            $Order->setPaymentMethod($payment->getMethod());
454
            $Order->setMessage($message);
455
            $Order->setCharge($payment->getCharge());
456
457
            $total = $Order->getSubTotal() + $Order->getCharge() + $Order->getDeliveryFeeTotal();
458
459
            $Order->setTotal($total);
460
            $Order->setPaymentTotal($total);
461
462
            // 受注関連情報を最新状態に更新
463
            $app['orm.em']->flush();
464
465
            $event = new EventArgs(
466
                array(
467
                    'form' => $form,
468
                    'order' => $Order,
469
                ),
470
                $request
471
            );
472
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_PAYMENT_COMPLETE, $event);
473
474
            return $app->redirect($app->url('shopping'));
475
        }
476
477
        return $app->render('Shopping/index.twig', array(
478
            'form' => $form->createView(),
479
            'Order' => $Order,
480
        ));
481 2
    }
482
483
    /**
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...
484
     * お届け先変更がクリックされた場合の処理
485
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
486 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...
487
    {
488
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
489
        if (!$Order) {
490
            $app->addError('front.shopping.order.error');
491
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
492
        }
493
494
        if ('POST' !== $request->getMethod()) {
495
            return $app->redirect($app->url('shopping'));
496
        }
497
498
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
499
        $form->handleRequest($request);
500
501
        if ($form->isSubmitted() && $form->isValid()) {
502
            $data = $form->getData();
503
            $message = $data['message'];
504
            $Order->setMessage($message);
505
            // 受注情報を更新
506
            $app['orm.em']->flush();
507
508
            // お届け先設定一覧へリダイレクト
509
            return $app->redirect($app->url('shopping_shipping', array('id' => $id)));
510
        }
511
512
        return $app->render('Shopping/index.twig', array(
513
            'form' => $form->createView(),
514
            'Order' => $Order,
515
        ));
516
    }
517
518
    /**
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...
519
     * お届け先の設定一覧からの選択
520
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
521
    public function shipping(Application $app, Request $request, $id)
522
    {
523
        // カートチェック
524
        if (!$app['eccube.service.cart']->isLocked()) {
525
            // カートが存在しない、カートがロックされていない時はエラー
526
            return $app->redirect($app->url('cart'));
527
        }
528
529
        if ('POST' === $request->getMethod()) {
530
            $address = $request->get('address');
531
532
            if (is_null($address)) {
533
                // 選択されていなければエラー
534
                return $app->render(
535
                    'Shopping/shipping.twig',
536
                    array(
537
                        'Customer' => $app->user(),
538
                        'shippingId' => $id,
539
                        'error' => true,
540
                    )
541
                );
542
            }
543
544
            // 選択されたお届け先情報を取得
545
            $CustomerAddress = $app['eccube.repository.customer_address']->findOneBy(array(
546
                'Customer' => $app->user(),
547
                'id' => $address,
548
            ));
549
            if (is_null($CustomerAddress)) {
550
                throw new NotFoundHttpException();
551
            }
552
553
            $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
554
            if (!$Order) {
555
                $app->addError('front.shopping.order.error');
556
557
                return $app->redirect($app->url('shopping_error'));
558
            }
559
560
            $Shipping = $Order->findShipping($id);
561
            if (!$Shipping) {
562
                throw new NotFoundHttpException();
563
            }
564
565
            // お届け先情報を更新
566
            $Shipping
567
                ->setFromCustomerAddress($CustomerAddress);
568
569
            // 配送料金の設定
570
            $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
571
572
            // 配送先を更新
573
            $app['orm.em']->flush();
574
575
            $event = new EventArgs(
576
                array(
577
                    'order' => $Order,
578
                    'shippingId' => $id,
579
                ),
580
                $request
581
            );
582
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_COMPLETE, $event);
583
584
            return $app->redirect($app->url('shopping'));
585
        }
586
587
        return $app->render(
588
            'Shopping/shipping.twig',
589
            array(
590
                'Customer' => $app->user(),
591
                'shippingId' => $id,
592
                'error' => false,
593
            )
594
        );
595
    }
596
597
    /**
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...
598
     * お届け先の設定(非会員)がクリックされた場合の処理
599
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
600 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...
601
    {
602
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
603 5
        if (!$Order) {
604
            $app->addError('front.shopping.order.error');
605
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
606
        }
607
608
        if ('POST' !== $request->getMethod()) {
609
            return $app->redirect($app->url('shopping'));
610
        }
611
612
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
613
        $form->handleRequest($request);
614
615
        if ($form->isSubmitted() && $form->isValid()) {
616
            $data = $form->getData();
617 3
            $message = $data['message'];
618
            $Order->setMessage($message);
619
            // 受注情報を更新
620
            $app['orm.em']->flush();
621
622
            // お届け先設定一覧へリダイレクト
623
            return $app->redirect($app->url('shopping_shipping_edit', array('id' => $id)));
624
        }
625
626 1
        return $app->render('Shopping/index.twig', array(
627 1
            'form' => $form->createView(),
628
            'Order' => $Order,
629
        ));
630 5
    }
631
632
    /**
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...
633
     * お届け先の設定(非会員でも使用する)
634
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
635 2
    public function shippingEdit(Application $app, Request $request, $id)
636
    {
637
        // 配送先住所最大値判定
638
        $Customer = $app->user();
639 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...
640
            $addressCurrNum = count($app->user()->getCustomerAddresses());
641
            $addressMax = $app['config']['deliv_addr_max'];
642
            if ($addressCurrNum >= $addressMax) {
643
                throw new NotFoundHttpException();
644
            }
645
        }
646
647
        // カートチェック
648
        if (!$app['eccube.service.cart']->isLocked()) {
649
            // カートが存在しない、カートがロックされていない時はエラー
650
            return $app->redirect($app->url('cart'));
651
        }
652
653
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
654 2
        if (!$Order) {
655
            $app->addError('front.shopping.order.error');
656
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
657
        }
658
659
        $Shipping = $Order->findShipping($id);
660 2
        if (!$Shipping) {
661
            throw new NotFoundHttpException();
662
        }
663
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
664
            $Shipping->clearCustomerAddress();
665
        }
666
667
        $CustomerAddress = new CustomerAddress();
668
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
669
            $CustomerAddress->setCustomer($Customer);
670
        } else {
671
            $CustomerAddress->setFromShipping($Shipping);
672
        }
673
674
        $builder = $app['form.factory']->createBuilder('shopping_shipping', $CustomerAddress);
675
        $form = $builder->getForm();
676
677
        $event = new EventArgs(
678
            array(
679
                'form' => $form,
680
                'order' => $Order,
681
                'shipping' => $Shipping,
682
                'customerAdderss' => $CustomerAddress,
683 2
            ),
684
            $request
685
        );
686
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_INITIALIZE, $event);
687
688
        $form->handleRequest($request);
689
690
        if ($form->isSubmitted() && $form->isValid()) {
691
            // 会員の場合、お届け先情報を新規登録
692
            $Shipping->setFromCustomerAddress($CustomerAddress);
693
694 1
            if ($Customer instanceof Customer) {
0 ignored issues
show
Bug introduced by
The class Eccube\Entity\Customer does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

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

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

2. Missing use statement

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

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

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

Loading history...
695
                $app['orm.em']->persist($CustomerAddress);
696
            }
697
698
            // 配送料金の設定
699
            $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
700
701
            // 配送先を更新 
702
            $app['orm.em']->flush();
703
704
            $event = new EventArgs(
705
                array(
706
                    'form' => $form,
707
                    'shipping' => $Shipping,
708
                    'customerAdderss' => $CustomerAddress,
709 1
                ),
710
                $request
711
            );
712
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_COMPLETE, $event);
713
714
            return $app->redirect($app->url('shopping'));
715
        }
716
717 1
        return $app->render('Shopping/shipping_edit.twig', array(
718 1
            'form' => $form->createView(),
719
            'shippingId' => $id,
720
        ));
721 2
    }
722
723
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
724
     * お客様情報の変更(非会員)
725
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
726
    public function customer(Application $app, Request $request)
727
    {
728
        if ($request->isXmlHttpRequest()) {
729
            try {
730
                $data = $request->request->all();
731
732
                // 入力チェック
733
                $errors = $this->customerValidation($app, $data);
734
735
                foreach ($errors as $error) {
736 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...
737
                        $response = new Response(json_encode('NG'), 400);
738
                        $response->headers->set('Content-Type', 'application/json');
739
                        return $response;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
740
                    }
741
                }
742
743
                $pref = $app['eccube.repository.master.pref']->findOneBy(array('name' => $data['customer_pref']));
744 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...
745
                    $response = new Response(json_encode('NG'), 400);
746
                    $response->headers->set('Content-Type', 'application/json');
747
                    return $response;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
748
                }
749
750
                $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
751
                if (!$Order) {
752
                    $app->addError('front.shopping.order.error');
753
                    return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
754
                }
755
756
                $Order
757
                    ->setName01($data['customer_name01'])
758
                    ->setName02($data['customer_name02'])
759
                    ->setCompanyName($data['customer_company_name'])
760
                    ->setTel01($data['customer_tel01'])
761
                    ->setTel02($data['customer_tel02'])
762
                    ->setTel03($data['customer_tel03'])
763
                    ->setZip01($data['customer_zip01'])
764
                    ->setZip02($data['customer_zip02'])
765
                    ->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...
766
                    ->setPref($pref)
767
                    ->setAddr01($data['customer_addr01'])
768
                    ->setAddr02($data['customer_addr02'])
769
                    ->setEmail($data['customer_email']);
770
771
                // 配送先を更新
772
                $app['orm.em']->flush();
773
774
                // 受注関連情報を最新状態に更新
775
                $app['orm.em']->refresh($Order);
776
777
                $event = new EventArgs(
778
                    array(
779
                        'order' => $Order,
780
                        'data' => $data,
781
                    ),
782
                    $request
783
                );
784
                $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CUSTOMER_INITIALIZE, $event);
785
786
                $response = new Response(json_encode('OK'));
787
                $response->headers->set('Content-Type', 'application/json');
788
            } catch (\Exception $e) {
789
                $app['monolog']->error($e);
790
791
                $response = new Response(json_encode('NG'), 500);
792
                $response->headers->set('Content-Type', 'application/json');
793
            }
794
795
            return $response;
796
        }
797
    }
798
799
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
800
     * ログイン
801
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
802 2
    public function login(Application $app, Request $request)
803
    {
804
        if (!$app['eccube.service.cart']->isLocked()) {
805
            return $app->redirect($app->url('cart'));
806
        }
807
808
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
809
            return $app->redirect($app->url('shopping'));
810
        }
811
812
        /* @var $form \Symfony\Component\Form\FormInterface */
813
        $builder = $app['form.factory']->createNamedBuilder('', 'customer_login');
814
815 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...
816
            $Customer = $app->user();
817
            if ($Customer) {
818
                $builder->get('login_email')->setData($Customer->getEmail());
819
            }
820
        }
821
822
        $form = $builder->getForm();
823
824
        $event = new EventArgs(
825
            array(
826
                'form' => $form,
827
            ),
828
            $request
829
        );
830
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_LOGIN_INITIALIZE, $event);
831
832
        return $app->render('Shopping/login.twig', array(
833
            'error' => $app['security.last_error']($request),
834
            'form' => $form->createView(),
835
        ));
836 2
    }
837
838
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
839
     * 非会員処理
840
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
841 11
    public function nonmember(Application $app, Request $request)
842
    {
843
        $cartService = $app['eccube.service.cart'];
844
845
        // カートチェック
846
        if (!$cartService->isLocked()) {
847
            // カートが存在しない、カートがロックされていない時はエラー
848
            return $app->redirect($app->url('cart'));
849
        }
850
851
        // ログイン済みの場合は, 購入画面へリダイレクト.
852
        if ($app->isGranted('ROLE_USER')) {
853
            return $app->redirect($app->url('shopping'));
854
        }
855
856
        // カートチェック
857
        if (count($cartService->getCart()->getCartItems()) <= 0) {
858
            // カートが存在しない時はエラー
859
            return $app->redirect($app->url('cart'));
860
        }
861
862
        $form = $app['form.factory']->createBuilder('nonmember')->getForm();
863
864
        $event = new EventArgs(
865
            array(
866
                'form' => $form,
867 10
            ),
868
            $request
869
        );
870
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_NONMEMBER_INITIALIZE, $event);
871
872
        $form->handleRequest($request);
873
874
        if ($form->isSubmitted() && $form->isValid()) {
875
            $data = $form->getData();
876
            $Customer = new Customer();
877
            $Customer
878 8
                ->setName01($data['name01'])
879 8
                ->setName02($data['name02'])
880 8
                ->setKana01($data['kana01'])
881 8
                ->setKana02($data['kana02'])
882 8
                ->setCompanyName($data['company_name'])
883 8
                ->setEmail($data['email'])
884 8
                ->setTel01($data['tel01'])
885 8
                ->setTel02($data['tel02'])
886 8
                ->setTel03($data['tel03'])
887 8
                ->setZip01($data['zip01'])
888 8
                ->setZip02($data['zip02'])
889 8
                ->setZipCode($data['zip01'] . $data['zip02'])
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
890 8
                ->setPref($data['pref'])
891 8
                ->setAddr01($data['addr01'])
892
                ->setAddr02($data['addr02']);
893
894
            // 非会員複数配送用
895
            $CustomerAddress = new CustomerAddress();
896
            $CustomerAddress
897 8
                ->setCustomer($Customer)
898 8
                ->setName01($data['name01'])
899 8
                ->setName02($data['name02'])
900 8
                ->setKana01($data['kana01'])
901 8
                ->setKana02($data['kana02'])
902 8
                ->setCompanyName($data['company_name'])
903 8
                ->setTel01($data['tel01'])
904 8
                ->setTel02($data['tel02'])
905 8
                ->setTel03($data['tel03'])
906 8
                ->setZip01($data['zip01'])
907 8
                ->setZip02($data['zip02'])
908 8
                ->setZipCode($data['zip01'] . $data['zip02'])
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
909 8
                ->setPref($data['pref'])
910 8
                ->setAddr01($data['addr01'])
911 8
                ->setAddr02($data['addr02'])
912
                ->setDelFlg(Constant::DISABLED);
913
            $Customer->addCustomerAddress($CustomerAddress);
914
915
            // 受注情報を取得
916
            $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
917
918
            // 初回アクセス(受注データがない)の場合は, 受注情報を作成
919
            if (is_null($Order)) {
920
                // 受注情報を作成
921
                try {
922
                    // 受注情報を作成
923
                    $app['eccube.service.shopping']->createOrder($Customer);
924
                } catch (CartException $e) {
925
                    $app->addRequestError($e->getMessage());
926
                    return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
927 8
                }
928
            }
929
930
            // 非会員用セッションを作成
931 8
            $nonMember = array();
932 8
            $nonMember['customer'] = $Customer;
933
            $nonMember['pref'] = $Customer->getPref()->getId();
934
            $app['session']->set($this->sessionKey, $nonMember);
935
936 8
            $customerAddresses = array();
937 8
            $customerAddresses[] = $CustomerAddress;
938
            $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses));
939
940
            $event = new EventArgs(
941
                array(
942
                    'form' => $form,
943
                    'order' => $Order,
944 8
                ),
945
                $request
946
            );
947
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_NONMEMBER_COMPLETE, $event);
948
949
            if ($event->getResponse() !== null) {
950
                return $event->getResponse();
951
            }
952
953
            return $app->redirect($app->url('shopping'));
954
        }
955
956 2
        return $app->render('Shopping/nonmember.twig', array(
957 2
            'form' => $form->createView(),
958
        ));
959 11
    }
960
961
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
962
     * 複数配送処理がクリックされた場合の処理
963
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
964 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...
965
    {
966
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
967
        if (!$Order) {
968
            $app->addError('front.shopping.order.error');
969
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
970
        }
971
972
        if ('POST' !== $request->getMethod()) {
973
            return $app->redirect($app->url('shopping'));
974
        }
975
976
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
977
        $form->handleRequest($request);
978
979
        if ($form->isSubmitted() && $form->isValid()) {
980
            $data = $form->getData();
981
            $message = $data['message'];
982
            $Order->setMessage($message);
983
            // 受注情報を更新
984
            $app['orm.em']->flush();
985
986
            // 複数配送設定へリダイレクト
987
            return $app->redirect($app->url('shopping_shipping_multiple'));
988
        }
989
990
        return $app->render('Shopping/index.twig', array(
991
            'form' => $form->createView(),
992
            'Order' => $Order,
993
        ));
994
    }
995
996
997
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
998
     * 複数配送処理
999
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1000
    public function shippingMultiple(Application $app, Request $request)
1001
    {
1002
        $cartService = $app['eccube.service.cart'];
1003
1004
        // カートチェック
1005
        if (!$cartService->isLocked()) {
1006
            // カートが存在しない、カートがロックされていない時はエラー
1007
            return $app->redirect($app->url('cart'));
1008
        }
1009
1010
        // カートチェック
1011
        if (count($cartService->getCart()->getCartItems()) <= 0) {
1012
            // カートが存在しない時はエラー
1013
            return $app->redirect($app->url('cart'));
1014
        }
1015
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
1016
        if (!$Order) {
1017
            $app->addError('front.shopping.order.error');
1018
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1019
        }
1020
1021
        // 複数配送時は商品毎でお届け先を設定する為、商品をまとめた数量を設定
1022
        $compItemQuantities = array();
1023 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...
1024
            foreach ($Shipping->getShipmentItems() as $ShipmentItem) {
1025
                $itemId = $ShipmentItem->getProductClass()->getId();
1026
                $quantity = $ShipmentItem->getQuantity();
1027
                if (array_key_exists($itemId, $compItemQuantities)) {
1028
                    $compItemQuantities[$itemId] = $compItemQuantities[$itemId] + $quantity;
1029
                } else {
1030
                    $compItemQuantities[$itemId] = $quantity;
1031
                }
1032
            }
1033
        }
1034
1035
        // 商品に紐づく商品情報を取得
1036
        $shipmentItems = array();
1037
        $productClassIds = array();
1038
        foreach ($Order->getShippings() as $Shipping) {
1039
            foreach ($Shipping->getShipmentItems() as $ShipmentItem) {
1040
                if (!in_array($ShipmentItem->getProductClass()->getId(), $productClassIds)) {
1041
                    $shipmentItems[] = $ShipmentItem;
1042
                }
1043
                $productClassIds[] = $ShipmentItem->getProductClass()->getId();
1044
            }
1045
        }
1046
1047
        $form = $app->form()->getForm();
1048
        $form
1049
            ->add('shipping_multiple', 'collection', array(
1050
                'type' => 'shipping_multiple',
1051
                'data' => $shipmentItems,
1052
                'allow_add' => true,
1053
                'allow_delete' => true,
1054
            ));
1055
1056
        $event = new EventArgs(
1057
            array(
1058
                'form' => $form,
1059
                'order' => $Order,
1060
            ),
1061
            $request
1062
        );
1063
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_INITIALIZE, $event);
1064
1065
        $form->handleRequest($request);
1066
1067
        $errors = array();
1068
        if ($form->isSubmitted() && $form->isValid()) {
1069
            $data = $form['shipping_multiple'];
1070
1071
            // 数量が超えていないか、同一でないとエラー
1072
            $itemQuantities = array();
1073
            foreach ($data as $mulitples) {
1074
                /** @var \Eccube\Entity\ShipmentItem $multipleItem */
1075
                $multipleItem = $mulitples->getData();
1076 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...
1077
                    foreach ($items as $item) {
1078
                        $quantity = $item['quantity']->getData();
1079
                        $itemId = $multipleItem->getProductClass()->getId();
1080
                        if (array_key_exists($itemId, $itemQuantities)) {
1081
                            $itemQuantities[$itemId] = $itemQuantities[$itemId] + $quantity;
1082
                        } else {
1083
                            $itemQuantities[$itemId] = $quantity;
1084
                        }
1085
                    }
1086
                }
1087
            }
1088
1089
            foreach ($compItemQuantities as $key => $value) {
1090
                if (array_key_exists($key, $itemQuantities)) {
1091
                    if ($itemQuantities[$key] != $value) {
1092
                        $errors[] = array('message' => '数量の数が異なっています。');
1093
1094
                        // 対象がなければエラー
1095
                        return $app->render('Shopping/shipping_multiple.twig', array(
1096
                            'form' => $form->createView(),
1097
                            'shipmentItems' => $shipmentItems,
1098
                            'compItemQuantities' => $compItemQuantities,
1099
                            'errors' => $errors,
1100
                        ));
1101
                    }
1102
                }
1103
            }
1104
1105
            // お届け先情報をdelete/insert
1106
            $shippings = $Order->getShippings();
1107
            foreach ($shippings as $Shipping) {
1108
                $Order->removeShipping($Shipping);
1109
                $app['orm.em']->remove($Shipping);
1110
            }
1111
1112
            foreach ($data as $mulitples) {
1113
                /** @var \Eccube\Entity\ShipmentItem $multipleItem */
1114
                $multipleItem = $mulitples->getData();
1115
1116
                foreach ($mulitples as $items) {
1117
                    foreach ($items as $item) {
1118
                        // 追加された配送先情報を作成
1119
                        $Delivery = $multipleItem->getShipping()->getDelivery();
1120
1121
                        // 選択された情報を取得
1122
                        $data = $item['customer_address']->getData();
1123
                        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...
1124
                            // 会員の場合、CustomerAddressオブジェクトを取得
1125
                            $CustomerAddress = $data;
1126
                        } else {
1127
                            // 非会員の場合、選択されたindexが取得される
1128
                            $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey);
1129
                            $customerAddresses = unserialize($customerAddresses);
1130
                            $CustomerAddress = $customerAddresses[$data];
1131
                            $pref = $app['eccube.repository.master.pref']->find($CustomerAddress->getPref()->getId());
1132
                            $CustomerAddress->setPref($pref);
1133
                        }
1134
1135
                        $Shipping = new Shipping();
1136
                        $Shipping
1137
                            ->setFromCustomerAddress($CustomerAddress)
1138
                            ->setDelivery($Delivery)
1139
                            ->setDelFlg(Constant::DISABLED)
1140
                            ->setOrder($Order);
1141
                        $app['orm.em']->persist($Shipping);
1142
1143
                        $ProductClass = $multipleItem->getProductClass();
1144
                        $Product = $multipleItem->getProduct();
1145
                        $quantity = $item['quantity']->getData();
1146
1147
                        $ShipmentItem = new ShipmentItem();
1148
                        $ShipmentItem->setShipping($Shipping)
1149
                            ->setOrder($Order)
1150
                            ->setProductClass($ProductClass)
1151
                            ->setProduct($Product)
1152
                            ->setProductName($Product->getName())
1153
                            ->setProductCode($ProductClass->getCode())
1154
                            ->setPrice($ProductClass->getPrice02())
1155
                            ->setQuantity($quantity);
1156
1157
                        $ClassCategory1 = $ProductClass->getClassCategory1();
1158
                        if (!is_null($ClassCategory1)) {
1159
                            $ShipmentItem->setClasscategoryName1($ClassCategory1->getName());
1160
                            $ShipmentItem->setClassName1($ClassCategory1->getClassName()->getName());
1161
                        }
1162
                        $ClassCategory2 = $ProductClass->getClassCategory2();
1163
                        if (!is_null($ClassCategory2)) {
1164
                            $ShipmentItem->setClasscategoryName2($ClassCategory2->getName());
1165
                            $ShipmentItem->setClassName2($ClassCategory2->getClassName()->getName());
1166
                        }
1167
                        $Shipping->addShipmentItem($ShipmentItem);
1168
                        $app['orm.em']->persist($ShipmentItem);
1169
1170
                        // 配送料金の設定
1171
                        $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
1172
                    }
1173
                }
1174
            }
1175
            // 配送先を更新
1176
            $app['orm.em']->flush();
1177
1178
            $event = new EventArgs(
1179
                array(
1180
                    'form' => $form,
1181
                    'order' => $Order,
1182
                ),
1183
                $request
1184
            );
1185
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_COMPLETE, $event);
1186
1187
            return $app->redirect($app->url('shopping'));
1188
        }
1189
1190
        return $app->render('Shopping/shipping_multiple.twig', array(
1191
            'form' => $form->createView(),
1192
            'shipmentItems' => $shipmentItems,
1193
            'compItemQuantities' => $compItemQuantities,
1194
            'errors' => $errors,
1195
        ));
1196
    }
1197
1198
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1199
     * 非会員用複数配送設定時の新規お届け先の設定
1200
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1201
    public function shippingMultipleEdit(Application $app, Request $request)
1202
    {
1203
        // カートチェック
1204
        if (!$app['eccube.service.cart']->isLocked()) {
1205
            // カートが存在しない、カートがロックされていない時はエラー
1206
            return $app->redirect($app->url('cart'));
1207
        }
1208
1209
        // 非会員用Customerを取得
1210
        $Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey);
1211
        $CustomerAddress = new CustomerAddress();
1212
        $CustomerAddress->setCustomer($Customer);
1213
        $Customer->addCustomerAddress($CustomerAddress);
1214
1215
        $form = $app['form.factory']->createBuilder('shopping_shipping', $CustomerAddress)->getForm();
1216
1217
        $event = new EventArgs(
1218
            array(
1219
                'form' => $form,
1220
                'customer' => $Customer,
1221
            ),
1222
            $request
1223
        );
1224
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_EDIT_INITIALIZE, $event);
1225
1226
        $form->handleRequest($request);
1227
1228
        if ($form->isSubmitted() && $form->isValid()) {
1229
            // 非会員用のセッションに追加
1230
            $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey);
1231
            $customerAddresses = unserialize($customerAddresses);
1232
            $customerAddresses[] = $CustomerAddress;
1233
            $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses));
1234
1235
            $event = new EventArgs(
1236
                array(
1237
                    'form' => $form,
1238
                    'customerAddresses' => $customerAddresses,
1239
                ),
1240
                $request
1241
            );
1242
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_EDIT_COMPLETE, $event);
1243
1244
            return $app->redirect($app->url('shopping_shipping_multiple'));
1245
        }
1246
1247
        return $app->render('Shopping/shipping_multiple_edit.twig', array(
1248
            'form' => $form->createView(),
1249
        ));
1250
    }
1251
1252
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1253
     * 購入エラー画面表示
1254
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1255 1
    public function shoppingError(Application $app, Request $request)
1256
    {
1257
1258
        $event = new EventArgs(
1259 1
            array(),
1260
            $request
1261
        );
1262
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_ERROR_COMPLETE, $event);
1263
1264
        if ($event->getResponse() !== null) {
1265
            return $event->getResponse();
1266
        }
1267
1268
        return $app->render('Shopping/shopping_error.twig');
1269 1
    }
1270
1271
    /**
1272
     * 非会員でのお客様情報変更時の入力チェック
1273
     * @param $data リクエストパラメータ
1274
     */
1275
    private function customerValidation($app, $data)
1276
    {
1277
        // 入力チェック
1278
        $errors = array();
1279
1280
        $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...
1281
            new Assert\NotBlank(),
1282
            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...
1283
            new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace'))
1284
        ));
1285
1286
        $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...
1287
            new Assert\NotBlank(),
1288
            new Assert\Length(array('max' => $app['config']['name_len'], )),
1289
            new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace'))
1290
        ));
1291
1292
        $errors[] = $app['validator']->validateValue($data['customer_company_name'], array(
1293
            new Assert\Length(array('max' => $app['config']['stext_len'])),
1294
        ));
1295
1296
        $errors[] = $app['validator']->validateValue($data['customer_tel01'], array(
1297
            new Assert\NotBlank(),
1298
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1299
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1300
        ));
1301
1302
        $errors[] = $app['validator']->validateValue($data['customer_tel02'], array(
1303
            new Assert\NotBlank(),
1304
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1305
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1306
        ));
1307
1308
        $errors[] = $app['validator']->validateValue($data['customer_tel03'], array(
1309
            new Assert\NotBlank(),
1310
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1311
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1312
        ));
1313
1314
        $errors[] = $app['validator']->validateValue($data['customer_zip01'], array(
1315
            new Assert\NotBlank(),
1316
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1317
            new Assert\Length(array('min' => $app['config']['zip01_len'], 'max' => $app['config']['zip01_len'])),
1318
        ));
1319
1320
        $errors[] = $app['validator']->validateValue($data['customer_zip02'], array(
1321
            new Assert\NotBlank(),
1322
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1323
            new Assert\Length(array('min' => $app['config']['zip02_len'], 'max' => $app['config']['zip02_len'])),
1324
        ));
1325
1326
        $errors[] = $app['validator']->validateValue($data['customer_addr01'], array(
1327
            new Assert\NotBlank(),
1328
            new Assert\Length(array('max' => $app['config']['address1_len'])),
1329
        ));
1330
1331
        $errors[] = $app['validator']->validateValue($data['customer_addr02'], array(
1332
            new Assert\NotBlank(),
1333
            new Assert\Length(array('max' => $app['config']['address2_len'])),
1334
        ));
1335
1336
        $errors[] = $app['validator']->validateValue($data['customer_email'], array(
1337
            new Assert\NotBlank(),
1338
            new Assert\Email(),
1339
        ));
1340
1341
        return $errors;
1342
    }
1343
}
1344