Completed
Push — master ( 344f0a...037a05 )
by Ryo
443:22 queued 435:22
created

ShoppingController::shippingChange()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 43
Code Lines 25

Duplication

Lines 43
Ratio 100 %

Code Coverage

Tests 19
CRAP Score 5.4877

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 43
loc 43
ccs 19
cts 26
cp 0.7308
rs 8.439
cc 5
eloc 25
nc 4
nop 3
crap 5.4877
1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
25
namespace Eccube\Controller;
26
27
use Eccube\Application;
28
use Eccube\Common\Constant;
29
use Eccube\Entity\Customer;
30
use Eccube\Entity\CustomerAddress;
31
use Eccube\Entity\ShipmentItem;
32
use Eccube\Entity\Shipping;
33
use Eccube\Event\EccubeEvents;
34
use Eccube\Event\EventArgs;
35
use Eccube\Exception\CartException;
36
use Eccube\Exception\ShoppingException;
37
use Symfony\Component\HttpFoundation\Request;
38
use Symfony\Component\HttpFoundation\Response;
39
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
40
use Symfony\Component\Validator\Constraints as Assert;
41
42
class ShoppingController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
43
{
44
45
    /**
46
     * @var string 非会員用セッションキー
47
     */
48
    private $sessionKey = 'eccube.front.shopping.nonmember';
49
50
    /**
51
     * @var string 非会員用セッションキー
52
     */
53
    private $sessionCustomerAddressKey = 'eccube.front.shopping.nonmember.customeraddress';
54
55
    /**
56
     * @var string 複数配送警告メッセージ
57
     */
58
    private $sessionMultipleKey = 'eccube.front.shopping.multiple';
59
60
    /**
61
     * @var string 受注IDキー
62
     */
63
    private $sessionOrderKey = 'eccube.front.shopping.order.id';
64
65
    /**
66
     * 購入画面表示
67
     *
68
     * @param Application $app
69
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
70
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
71
     */
72 35
    public function index(Application $app, Request $request)
73
    {
74 35
        $cartService = $app['eccube.service.cart'];
75
76
        // カートチェック
77 35
        if (!$cartService->isLocked()) {
78
            // カートが存在しない、カートがロックされていない時はエラー
79 3
            return $app->redirect($app->url('cart'));
80
        }
81
82
        // カートチェック
83 32
        if (count($cartService->getCart()->getCartItems()) <= 0) {
84
            // カートが存在しない時はエラー
85 1
            return $app->redirect($app->url('cart'));
86
        }
87
88
        // 登録済みの受注情報を取得
89 31
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
90
91
        // 初回アクセス(受注情報がない)の場合は, 受注情報を作成
92 31
        if (is_null($Order)) {
93
            // 未ログインの場合, ログイン画面へリダイレクト.
94 31
            if (!$app->isGranted('IS_AUTHENTICATED_FULLY')) {
95
                // 非会員でも一度会員登録されていればショッピング画面へ遷移
96 12
                $Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey);
97
98 12
                if (is_null($Customer)) {
99
                    return $app->redirect($app->url('shopping_login'));
100
                }
101 12
            } else {
102 19
                $Customer = $app->user();
103 2
            }
104
105
            try {
106
                // 受注情報を作成
107 31
                $Order = $app['eccube.service.shopping']->createOrder($Customer);
108 31
            } 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 12
            }
112
113
            // セッション情報を削除
114 31
            $app['session']->remove($this->sessionOrderKey);
115 31
            $app['session']->remove($this->sessionMultipleKey);
116 31
        }
117
118
        // 受注関連情報を最新状態に更新
119 31
        $app['orm.em']->refresh($Order);
120
121
        // form作成
122 31
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
123
124 31
        $event = new EventArgs(
125
            array(
126 31
                'builder' => $builder,
127 31
                'Order' => $Order,
128 31
            ),
129
            $request
130 31
        );
131 31
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_INDEX_INITIALIZE, $event);
132
133 31
        $form = $builder->getForm();
134
135 31
        if ($Order->getTotalPrice() < 0) {
136
            // 合計金額がマイナスの場合、エラー
137
            $message = $app->trans('shopping.total.price', array('totalPrice' => number_format($Order->getTotalPrice())));
138
            $app->addError($message);
139
140
            return $app->redirect($app->url('shopping_error'));
141
        }
142
143
        // 複数配送の場合、エラーメッセージを一度だけ表示
144 31
        if (!$app['session']->has($this->sessionMultipleKey)) {
145 31
            if (count($Order->getShippings()) > 1) {
146
                $app->addRequestError('shopping.multiple.delivery');
147
            }
148 31
            $app['session']->set($this->sessionMultipleKey, 'multiple');
149 31
        }
150
151 31
        return $app->render('Shopping/index.twig', array(
152 31
            'form' => $form->createView(),
153 31
            'Order' => $Order,
154 31
        ));
155
    }
156
157
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
158
     * 購入処理
159
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
160 37
    public function confirm(Application $app, Request $request)
161
    {
162 35
        $cartService = $app['eccube.service.cart'];
163
164
        // カートチェック
165 9
        if (!$cartService->isLocked()) {
166
            // カートが存在しない、カートがロックされていない時はエラー
167
            return $app->redirect($app->url('cart'));
168
        }
169
170 9
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
171 9
        if (!$Order) {
172
            $app->addError('front.shopping.order.error');
173
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
174
        }
175
176 9
        if ('POST' !== $request->getMethod()) {
177
            return $app->redirect($app->url('cart'));
178
        }
179
180
        // form作成
181 9
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
182
183 9
        $event = new EventArgs(
184
            array(
185 9
                'builder' => $builder,
186 9
                'Order' => $Order,
187 9
            ),
188
            $request
189 9
        );
190 9
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CONFIRM_INITIALIZE, $event);
191
192 9
        $form = $builder->getForm();
193
194 9
        $form->handleRequest($request);
195
196 9
        if ($form->isSubmitted() && $form->isValid()) {
197 9
            $data = $form->getData();
198
199
            // トランザクション制御
200 9
            $em = $app['orm.em'];
201 9
            $em->getConnection()->beginTransaction();
202
            try {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
203
204
                // お問い合わせ、配送時間などのフォーム項目をセット
205 9
                $app['eccube.service.shopping']->setFormData($Order, $data);
206
                // 購入処理
207 9
                $app['eccube.service.shopping']->processPurchase($Order);
208
209 9
                $em->flush();
210 9
                $em->getConnection()->commit();
211
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
212 9
            } catch (ShoppingException $e) {
213
                $em->getConnection()->rollback();
214
215
                $app->log($e);
216
                $app->addError($e->getMessage());
217
218
                return $app->redirect($app->url('shopping_error'));
219
            } catch (\Exception $e) {
220
                $em->getConnection()->rollback();
221
222
                $app->log($e);
223
224
                $app->addError('front.shopping.system.error');
225 37
                return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
226
            }
227
228
            // カート削除
229 9
            $app['eccube.service.cart']->clear()->save();
230
231 9
            $event = new EventArgs(
232
                array(
233 9
                    'form' => $form,
234 9
                    'Order' => $Order,
235 9
                ),
236
                $request
237 9
            );
238 9
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CONFIRM_PROCESSING, $event);
239
240 9
            if ($event->getResponse() !== null) {
241 37
                return $event->getResponse();
242
            }
243
244
            // 受注IDをセッションにセット
245 9
            $app['session']->set($this->sessionOrderKey, $Order->getId());
246
247
            // メール送信
248 9
            $MailHistory = $app['eccube.service.shopping']->sendOrderMail($Order);
249
250 9
            $event = new EventArgs(
251
                array(
252 9
                    'form' => $form,
253 9
                    'Order' => $Order,
254 9
                    'MailHistory' => $MailHistory,
255 9
                ),
256
                $request
257 9
            );
258 9
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CONFIRM_COMPLETE, $event);
259
260 9
            if ($event->getResponse() !== null) {
261
                return $event->getResponse();
262
            }
263
264
            // 完了画面表示
265 9
            return $app->redirect($app->url('shopping_complete'));
266
        }
267
268
        return $app->render('Shopping/index.twig', array(
269
            'form' => $form->createView(),
270
            'Order' => $Order,
271
        ));
272
    }
273
274
275
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
276
     * 購入完了画面表示
277
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
278 37
    public function complete(Application $app, Request $request)
279
    {
280
        // 受注IDを取得
281 2
        $orderId = $app['session']->get($this->sessionOrderKey);
282
283 2
        $event = new EventArgs(
284
            array(
285 2
                'orderId' => $orderId,
286 2
            ),
287
            $request
288 2
        );
289 2
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_COMPLETE_INITIALIZE, $event);
290
291 2
        if ($event->getResponse() !== null) {
292
            return $event->getResponse();
293
        }
294
295
        // 受注IDセッションを削除
296 2
        $app['session']->remove($this->sessionOrderKey);
297
298 2
        return $app->render('Shopping/complete.twig', array(
299 2
            'orderId' => $orderId,
300 37
        ));
301
    }
302
303
304
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
305
     * 配送業者選択処理
306
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
307 6
    public function delivery(Application $app, Request $request)
308
    {
309
        // カートチェック
310 6
        if (!$app['eccube.service.cart']->isLocked()) {
311
            // カートが存在しない、カートがロックされていない時はエラー
312
            return $app->redirect($app->url('cart'));
313
        }
314
315 6
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
316 6
        if (!$Order) {
317
            $app->addError('front.shopping.order.error');
318
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
319
        }
320
321 6
        if ('POST' !== $request->getMethod()) {
322
            return $app->redirect($app->url('shopping'));
323
        }
324
325 6
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
326
327 6
        $event = new EventArgs(
328
            array(
329 6
                'builder' => $builder,
330 6
                'Order' => $Order,
331 6
            ),
332
            $request
333 6
        );
334 6
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_DELIVERY_INITIALIZE, $event);
335
336 6
        $form = $builder->getForm();
337
338 6
        $form->handleRequest($request);
339
340 6
        if ($form->isSubmitted() && $form->isValid()) {
341 2
            $data = $form->getData();
342
343 2
            $shippings = $data['shippings'];
344
345 2
            $productDeliveryFeeTotal = 0;
346 2
            $BaseInfo = $app['eccube.repository.base_info']->get();
347
348 2
            foreach ($shippings as $Shipping) {
349 2
                $Delivery = $Shipping->getDelivery();
350
351 2
                if ($Delivery) {
352 2
                    $deliveryFee = $app['eccube.repository.delivery_fee']->findOneBy(array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
353 2
                        'Delivery' => $Delivery,
354 2
                        'Pref' => $Shipping->getPref()
355 2
                    ));
356
357
                    // 商品ごとの配送料合計
358 2
                    if (!is_null($BaseInfo->getOptionProductDeliveryFee())) {
359 2
                        $productDeliveryFeeTotal += $app['eccube.service.shopping']->getProductDeliveryFee($Shipping);
360 2
                    }
361
362 2
                    $Shipping->setDeliveryFee($deliveryFee);
363 2
                    $Shipping->setShippingDeliveryFee($deliveryFee->getFee() + $productDeliveryFeeTotal);
364 2
                    $Shipping->setShippingDeliveryName($Delivery->getName());
365 2
                }
366 2
            }
367
368
            // 支払い情報をセット
369 2
            $payment = $data['payment'];
370 2
            $message = $data['message'];
371
372 2
            $Order->setPayment($payment);
373 2
            $Order->setPaymentMethod($payment->getMethod());
374 2
            $Order->setMessage($message);
375 2
            $Order->setCharge($payment->getCharge());
376
377 2
            $Order->setDeliveryFeeTotal($app['eccube.service.shopping']->getShippingDeliveryFeeTotal($shippings));
378
379
            // 合計金額の再計算
380 2
            $Order = $app['eccube.service.shopping']->getAmount($Order);
381
382
            // 受注関連情報を最新状態に更新
383 2
            $app['orm.em']->flush();
384
385 2
            $event = new EventArgs(
386
                array(
387 2
                    'form' => $form,
388 2
                    'Order' => $Order,
389 2
                ),
390
                $request
391 2
            );
392 2
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_DELIVERY_COMPLETE, $event);
393
394 2
            return $app->redirect($app->url('shopping'));
395
        }
396
397 4
        return $app->render('Shopping/index.twig', array(
398 4
            'form' => $form->createView(),
399 4
            'Order' => $Order,
400 4
        ));
401
    }
402
403
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
404
     * 支払い方法選択処理
405
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
406 34
    public function payment(Application $app, Request $request)
407
    {
408 4
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
409 34
        if (!$Order) {
410
            $app->addError('front.shopping.order.error');
411
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
412
        }
413
414 4
        if ('POST' !== $request->getMethod()) {
415
            return $app->redirect($app->url('shopping'));
416
        }
417
418 4
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
419
420 4
        $event = new EventArgs(
421
            array(
422 4
                'builder' => $builder,
423 4
                'Order' => $Order,
424 4
            ),
425
            $request
426 4
        );
427 4
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_PAYMENT_INITIALIZE, $event);
428
429 4
        $form = $builder->getForm();
430
431 4
        $form->handleRequest($request);
432
433 4
        if ($form->isSubmitted() && $form->isValid()) {
434 2
            $data = $form->getData();
435 2
            $payment = $data['payment'];
436 2
            $message = $data['message'];
437
438 2
            $Order->setPayment($payment);
439 2
            $Order->setPaymentMethod($payment->getMethod());
440 2
            $Order->setMessage($message);
441 2
            $Order->setCharge($payment->getCharge());
442
443
            // 合計金額の再計算
444 2
            $Order = $app['eccube.service.shopping']->getAmount($Order);
445
446
            // 受注関連情報を最新状態に更新
447 2
            $app['orm.em']->flush();
448
449 2
            $event = new EventArgs(
450
                array(
451 2
                    'form' => $form,
452 2
                    'Order' => $Order,
453 2
                ),
454
                $request
455 2
            );
456 2
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_PAYMENT_COMPLETE, $event);
457
458 2
            return $app->redirect($app->url('shopping'));
459
        }
460
461 2
        return $app->render('Shopping/index.twig', array(
462 2
            'form' => $form->createView(),
463 2
            'Order' => $Order,
464 2
        ));
465
    }
466
467
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
introduced by
Doc comment for parameter "$id" missing
Loading history...
468
     * お届け先変更がクリックされた場合の処理
469
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
470 6 View Code Duplication
    public function shippingChange(Application $app, Request $request, $id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
471
    {
472 6
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
473 6
        if (!$Order) {
474
            $app->addError('front.shopping.order.error');
475
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
476
        }
477
478 6
        if ('POST' !== $request->getMethod()) {
479
            return $app->redirect($app->url('shopping'));
480
        }
481
482 6
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
483
484 6
        $event = new EventArgs(
485
            array(
486 6
                'builder' => $builder,
487 6
                'Order' => $Order,
488 6
            ),
489
            $request
490 6
        );
491 6
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_CHANGE_INITIALIZE, $event);
492
493 6
        $form = $builder->getForm();
494
495 6
        $form->handleRequest($request);
496
497 6
        if ($form->isSubmitted() && $form->isValid()) {
498 6
            $data = $form->getData();
499 6
            $message = $data['message'];
500 6
            $Order->setMessage($message);
501
            // 受注情報を更新
502 6
            $app['orm.em']->flush();
503
504
            // お届け先設定一覧へリダイレクト
505 6
            return $app->redirect($app->url('shopping_shipping', array('id' => $id)));
506
        }
507
508
        return $app->render('Shopping/index.twig', array(
509
            'form' => $form->createView(),
510
            'Order' => $Order,
511
        ));
512
    }
513
514
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
introduced by
Doc comment for parameter "$id" missing
Loading history...
515
     * お届け先の設定一覧からの選択
516
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
517 6
    public function shipping(Application $app, Request $request, $id)
518
    {
519
        // カートチェック
520 4
        if (!$app['eccube.service.cart']->isLocked()) {
521
            // カートが存在しない、カートがロックされていない時はエラー
522
            return $app->redirect($app->url('cart'));
523
        }
524
525 4
        if ('POST' === $request->getMethod()) {
526
            $address = $request->get('address');
527
528
            if (is_null($address)) {
529
                // 選択されていなければエラー
530
                return $app->render(
531
                    'Shopping/shipping.twig',
532
                    array(
533
                        'Customer' => $app->user(),
534
                        'shippingId' => $id,
535
                        'error' => true,
536
                    )
537
                );
538
            }
539
540
            // 選択されたお届け先情報を取得
541
            $CustomerAddress = $app['eccube.repository.customer_address']->findOneBy(array(
542
                'Customer' => $app->user(),
543
                'id' => $address,
544
            ));
545
            if (is_null($CustomerAddress)) {
546
                throw new NotFoundHttpException();
547
            }
548
549
            $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
550
            if (!$Order) {
551
                $app->addError('front.shopping.order.error');
552
553
                return $app->redirect($app->url('shopping_error'));
554
            }
555
556
            $Shipping = $Order->findShipping($id);
557
            if (!$Shipping) {
558
                throw new NotFoundHttpException();
559
            }
560
561
            // お届け先情報を更新
562
            $Shipping
563
                ->setFromCustomerAddress($CustomerAddress);
564
565
            // 配送料金の設定
566
            $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
567
568
            // 合計金額の再計算
569
            $Order = $app['eccube.service.shopping']->getAmount($Order);
570
571
            // 配送先を更新
572
            $app['orm.em']->flush();
573
574
            $event = new EventArgs(
575
                array(
576
                    'Order' => $Order,
577
                    'shippingId' => $id,
578
                ),
579
                $request
580
            );
581
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_COMPLETE, $event);
582
583
            return $app->redirect($app->url('shopping'));
584
        }
585
586 4
        return $app->render(
587 6
            'Shopping/shipping.twig',
588
            array(
589 4
                'Customer' => $app->user(),
590 4
                'shippingId' => $id,
591 4
                'error' => false,
592
            )
593 4
        );
594
    }
595
596
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
introduced by
Doc comment for parameter "$id" missing
Loading history...
597
     * お届け先の設定(非会員)がクリックされた場合の処理
598
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
599 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...
600
    {
601 5
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
602 5
        if (!$Order) {
603
            $app->addError('front.shopping.order.error');
604
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
605 2
        }
606
607 5
        if ('POST' !== $request->getMethod()) {
608 1
            return $app->redirect($app->url('shopping'));
609
        }
610
611 4
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
612
613 4
        $event = new EventArgs(
614
            array(
615 4
                'builder' => $builder,
616 4
                'Order' => $Order,
617 4
            ),
618
            $request
619 4
        );
620 4
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_CHANGE_INITIALIZE, $event);
621
622 4
        $form = $builder->getForm();
623
624 4
        $form->handleRequest($request);
625
626 4
        if ($form->isSubmitted() && $form->isValid()) {
627 3
            $data = $form->getData();
628 3
            $message = $data['message'];
629 3
            $Order->setMessage($message);
630
            // 受注情報を更新
631 3
            $app['orm.em']->flush();
632
633
            // お届け先設定一覧へリダイレクト
634 3
            return $app->redirect($app->url('shopping_shipping_edit', array('id' => $id)));
635
        }
636
637 1
        return $app->render('Shopping/index.twig', array(
638 1
            'form' => $form->createView(),
639 1
            'Order' => $Order,
640 1
        ));
641
    }
642
643
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
introduced by
Doc comment for parameter "$id" missing
Loading history...
644
     * お届け先の設定(非会員でも使用する)
645
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
646 5
    public function shippingEdit(Application $app, Request $request, $id)
647
    {
648
        // 配送先住所最大値判定
649 4
        $Customer = $app->user();
650 4 View Code Duplication
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
651 5
            $addressCurrNum = count($app->user()->getCustomerAddresses());
652 2
            $addressMax = $app['config']['deliv_addr_max'];
653 2
            if ($addressCurrNum >= $addressMax) {
654
                throw new NotFoundHttpException();
655
            }
656 2
        }
657
658
        // カートチェック
659 4
        if (!$app['eccube.service.cart']->isLocked()) {
660
            // カートが存在しない、カートがロックされていない時はエラー
661
            return $app->redirect($app->url('cart'));
662
        }
663
664 4
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
665 4
        if (!$Order) {
666
            $app->addError('front.shopping.order.error');
667
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
668
        }
669
670 4
        $Shipping = $Order->findShipping($id);
671 4
        if (!$Shipping) {
672
            throw new NotFoundHttpException();
673
        }
674 4
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
675 2
            $Shipping->clearCustomerAddress();
676 2
        }
677
678 4
        $CustomerAddress = new CustomerAddress();
679 4
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
680 2
            $CustomerAddress->setCustomer($Customer);
681 2
        } else {
682 2
            $CustomerAddress->setFromShipping($Shipping);
683
        }
684
685 4
        $builder = $app['form.factory']->createBuilder('shopping_shipping', $CustomerAddress);
686
687 4
        $event = new EventArgs(
688
            array(
689 4
                'builder' => $builder,
690 4
                'Order' => $Order,
691 4
                'Shipping' => $Shipping,
692 4
                'CustomerAddress' => $CustomerAddress,
693 4
            ),
694
            $request
695 4
        );
696 4
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_INITIALIZE, $event);
697
698 4
        $form = $builder->getForm();
699
700 4
        $form->handleRequest($request);
701
702 4
        if ($form->isSubmitted() && $form->isValid()) {
703
            // 会員の場合、お届け先情報を新規登録
704 3
            $Shipping->setFromCustomerAddress($CustomerAddress);
705
706 3
            if ($Customer instanceof Customer) {
0 ignored issues
show
Bug introduced by
The class Eccube\Entity\Customer does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

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

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

2. Missing use statement

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

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

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

Loading history...
707 2
                $app['orm.em']->persist($CustomerAddress);
708 2
            }
709
710
            // 配送料金の設定
711 3
            $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
712
713
            // 合計金額の再計算
714 3
            $app['eccube.service.shopping']->getAmount($Order);
715
716
            // 配送先を更新 
717 3
            $app['orm.em']->flush();
718
719 3
            $event = new EventArgs(
720
                array(
721 3
                    'form' => $form,
722 3
                    'Shipping' => $Shipping,
723 3
                    'CustomerAddress' => $CustomerAddress,
724 3
                ),
725
                $request
726 3
            );
727 3
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_COMPLETE, $event);
728
729 3
            return $app->redirect($app->url('shopping'));
730
        }
731
732 3
        return $app->render('Shopping/shipping_edit.twig', array(
733 3
            'form' => $form->createView(),
734 3
            'shippingId' => $id,
735 3
        ));
736
    }
737
738
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
739
     * お客様情報の変更(非会員)
740
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
741
    public function customer(Application $app, Request $request)
742
    {
743
        if ($request->isXmlHttpRequest()) {
744
            try {
745
                $data = $request->request->all();
746
747
                // 入力チェック
748
                $errors = $this->customerValidation($app, $data);
749
750
                foreach ($errors as $error) {
751 View Code Duplication
                    if ($error->count() != 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
752
                        $response = new Response(json_encode('NG'), 400);
753
                        $response->headers->set('Content-Type', 'application/json');
754
                        return $response;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
755
                    }
756
                }
757
758
                $pref = $app['eccube.repository.master.pref']->findOneBy(array('name' => $data['customer_pref']));
759 View Code Duplication
                if (!$pref) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
760
                    $response = new Response(json_encode('NG'), 400);
761
                    $response->headers->set('Content-Type', 'application/json');
762
                    return $response;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
763
                }
764
765
                $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
766
                if (!$Order) {
767
                    $app->addError('front.shopping.order.error');
768
                    return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
769
                }
770
771
                $Order
772
                    ->setName01($data['customer_name01'])
773
                    ->setName02($data['customer_name02'])
774
                    ->setCompanyName($data['customer_company_name'])
775
                    ->setTel01($data['customer_tel01'])
776
                    ->setTel02($data['customer_tel02'])
777
                    ->setTel03($data['customer_tel03'])
778
                    ->setZip01($data['customer_zip01'])
779
                    ->setZip02($data['customer_zip02'])
780
                    ->setZipCode($data['customer_zip01'].$data['customer_zip02'])
781
                    ->setPref($pref)
782
                    ->setAddr01($data['customer_addr01'])
783
                    ->setAddr02($data['customer_addr02'])
784
                    ->setEmail($data['customer_email']);
785
786
                // 配送先を更新
787
                $app['orm.em']->flush();
788
789
                // 受注関連情報を最新状態に更新
790
                $app['orm.em']->refresh($Order);
791
792
                $event = new EventArgs(
793
                    array(
794
                        'Order' => $Order,
795
                        'data' => $data,
796
                    ),
797
                    $request
798
                );
799
                $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CUSTOMER_INITIALIZE, $event);
800
801
                $response = new Response(json_encode('OK'));
802
                $response->headers->set('Content-Type', 'application/json');
803
            } catch (\Exception $e) {
804
                $app['monolog']->error($e);
805
806
                $response = new Response(json_encode('NG'), 500);
807
                $response->headers->set('Content-Type', 'application/json');
808
            }
809
810
            return $response;
811
        }
812
    }
813
814
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
815
     * ログイン
816
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
817 4
    public function login(Application $app, Request $request)
818
    {
819 4
        if (!$app['eccube.service.cart']->isLocked()) {
820 3
            return $app->redirect($app->url('cart'));
821
        }
822
823 1
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
824
            return $app->redirect($app->url('shopping'));
825
        }
826
827
        /* @var $form \Symfony\Component\Form\FormInterface */
828 1
        $builder = $app['form.factory']->createNamedBuilder('', 'customer_login');
829
830 1 View Code Duplication
        if ($app->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
831
            $Customer = $app->user();
832
            if ($Customer) {
833
                $builder->get('login_email')->setData($Customer->getEmail());
834
            }
835
        }
836
837 1
        $event = new EventArgs(
838
            array(
839 1
                'builder' => $builder,
840 1
            ),
841
            $request
842 1
        );
843 1
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_LOGIN_INITIALIZE, $event);
844
845 1
        $form = $builder->getForm();
846
847 1
        return $app->render('Shopping/login.twig', array(
848 1
            'error' => $app['security.last_error']($request),
849 1
            'form' => $form->createView(),
850 1
        ));
851
    }
852
853
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
854
     * 非会員処理
855
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
856 16
    public function nonmember(Application $app, Request $request)
857
    {
858 16
        $cartService = $app['eccube.service.cart'];
859
860
        // カートチェック
861 16
        if (!$cartService->isLocked()) {
862
            // カートが存在しない、カートがロックされていない時はエラー
863 1
            return $app->redirect($app->url('cart'));
864
        }
865
866
        // ログイン済みの場合は, 購入画面へリダイレクト.
867 15
        if ($app->isGranted('ROLE_USER')) {
868 1
            return $app->redirect($app->url('shopping'));
869
        }
870
871
        // カートチェック
872 14
        if (count($cartService->getCart()->getCartItems()) <= 0) {
873
            // カートが存在しない時はエラー
874
            return $app->redirect($app->url('cart'));
875
        }
876
877 14
        $builder = $app['form.factory']->createBuilder('nonmember');
878
879 14
        $event = new EventArgs(
880
            array(
881 14
                'builder' => $builder,
882 14
            ),
883
            $request
884 14
        );
885 14
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_NONMEMBER_INITIALIZE, $event);
886
887 14
        $form = $builder->getForm();
888
889 14
        $form->handleRequest($request);
890
891 14
        if ($form->isSubmitted() && $form->isValid()) {
892 13
            $data = $form->getData();
893 13
            $Customer = new Customer();
894
            $Customer
895 13
                ->setName01($data['name01'])
896 13
                ->setName02($data['name02'])
897 13
                ->setKana01($data['kana01'])
898 13
                ->setKana02($data['kana02'])
899 13
                ->setCompanyName($data['company_name'])
900 13
                ->setEmail($data['email'])
901 13
                ->setTel01($data['tel01'])
902 13
                ->setTel02($data['tel02'])
903 13
                ->setTel03($data['tel03'])
904 13
                ->setZip01($data['zip01'])
905 13
                ->setZip02($data['zip02'])
906 13
                ->setZipCode($data['zip01'].$data['zip02'])
907 13
                ->setPref($data['pref'])
908 13
                ->setAddr01($data['addr01'])
909 13
                ->setAddr02($data['addr02']);
910
911
            // 非会員複数配送用
912 13
            $CustomerAddress = new CustomerAddress();
913
            $CustomerAddress
914 13
                ->setCustomer($Customer)
915 13
                ->setName01($data['name01'])
916 13
                ->setName02($data['name02'])
917 13
                ->setKana01($data['kana01'])
918 13
                ->setKana02($data['kana02'])
919 13
                ->setCompanyName($data['company_name'])
920 13
                ->setTel01($data['tel01'])
921 13
                ->setTel02($data['tel02'])
922 13
                ->setTel03($data['tel03'])
923 13
                ->setZip01($data['zip01'])
924 13
                ->setZip02($data['zip02'])
925 13
                ->setZipCode($data['zip01'].$data['zip02'])
926 13
                ->setPref($data['pref'])
927 13
                ->setAddr01($data['addr01'])
928 13
                ->setAddr02($data['addr02'])
929 13
                ->setDelFlg(Constant::DISABLED);
930 13
            $Customer->addCustomerAddress($CustomerAddress);
931
932
            // 受注情報を取得
933 13
            $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
934
935
            // 初回アクセス(受注データがない)の場合は, 受注情報を作成
936 13
            if (is_null($Order)) {
937
                // 受注情報を作成
938
                try {
939
                    // 受注情報を作成
940 13
                    $app['eccube.service.shopping']->createOrder($Customer);
941 13
                } catch (CartException $e) {
942
                    $app->addRequestError($e->getMessage());
943
                    return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
944
                }
945 13
            }
946
947
            // 非会員用セッションを作成
948 13
            $nonMember = array();
949 13
            $nonMember['customer'] = $Customer;
950 13
            $nonMember['pref'] = $Customer->getPref()->getId();
951 13
            $app['session']->set($this->sessionKey, $nonMember);
952
953 13
            $customerAddresses = array();
954 13
            $customerAddresses[] = $CustomerAddress;
955 13
            $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses));
956
957 13
            $event = new EventArgs(
958
                array(
959 13
                    'form' => $form,
960 13
                    'Order' => $Order,
961 13
                ),
962
                $request
963 13
            );
964 13
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_NONMEMBER_COMPLETE, $event);
965
966 13
            if ($event->getResponse() !== null) {
967
                return $event->getResponse();
968
            }
969
970 13
            return $app->redirect($app->url('shopping'));
971
        }
972
973 1
        return $app->render('Shopping/nonmember.twig', array(
974 1
            'form' => $form->createView(),
975 1
        ));
976
    }
977
978
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
979
     * 複数配送処理がクリックされた場合の処理
980
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
981 View Code Duplication
    public function shippingMultipleChange(Application $app, Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
982
    {
983
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
984
        if (!$Order) {
985
            $app->addError('front.shopping.order.error');
986
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
987
        }
988
989
        if ('POST' !== $request->getMethod()) {
990
            return $app->redirect($app->url('shopping'));
991
        }
992
993
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
994
995
        $event = new EventArgs(
996
            array(
997
                'builder' => $builder,
998
                'Order' => $Order,
999
            ),
1000
            $request
1001
        );
1002
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_CHANGE_INITIALIZE, $event);
1003
1004
        $form = $builder->getForm();
1005
1006
        $form->handleRequest($request);
1007
1008
        if ($form->isSubmitted() && $form->isValid()) {
1009
            $data = $form->getData();
1010
            $message = $data['message'];
1011
            $Order->setMessage($message);
1012
            // 受注情報を更新
1013
            $app['orm.em']->flush();
1014
1015
            // 複数配送設定へリダイレクト
1016
            return $app->redirect($app->url('shopping_shipping_multiple'));
1017
        }
1018
1019
        return $app->render('Shopping/index.twig', array(
1020
            'form' => $form->createView(),
1021
            'Order' => $Order,
1022
        ));
1023
    }
1024
1025
1026
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1027
     * 複数配送処理
1028
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1029 33
    public function shippingMultiple(Application $app, Request $request)
1030
    {
1031 2
        $cartService = $app['eccube.service.cart'];
1032
1033
        // カートチェック
1034 2
        if (!$cartService->isLocked()) {
1035
            // カートが存在しない、カートがロックされていない時はエラー
1036
            return $app->redirect($app->url('cart'));
1037
        }
1038
1039
        // カートチェック
1040 2
        if (count($cartService->getCart()->getCartItems()) <= 0) {
1041
            // カートが存在しない時はエラー
1042
            return $app->redirect($app->url('cart'));
1043
        }
1044
1045
        /** @var \Eccube\Entity\Order $Order */
1046 2
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
1047 2
        if (!$Order) {
1048
            $app->addError('front.shopping.order.error');
1049
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1050
        }
1051
1052
        // 複数配送時は商品毎でお届け先を設定する為、商品をまとめた数量を設定
1053 2
        $compItemQuantities = array();
1054 2 View Code Duplication
        foreach ($Order->getShippings() as $Shipping) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1055 2
            foreach ($Shipping->getShipmentItems() as $ShipmentItem) {
1056 2
                $itemId = $ShipmentItem->getProductClass()->getId();
1057 2
                $quantity = $ShipmentItem->getQuantity();
1058 2
                if (array_key_exists($itemId, $compItemQuantities)) {
1059
                    $compItemQuantities[$itemId] = $compItemQuantities[$itemId] + $quantity;
1060 9
                } else {
1061 33
                    $compItemQuantities[$itemId] = $quantity;
1062
                }
1063 33
            }
1064 2
        }
1065
1066
        // 商品に紐づく商品情報を取得
1067 2
        $shipmentItems = array();
1068 2
        $productClassIds = array();
1069 2
        foreach ($Order->getShippings() as $Shipping) {
1070 2
            foreach ($Shipping->getShipmentItems() as $ShipmentItem) {
1071 2
                if (!in_array($ShipmentItem->getProductClass()->getId(), $productClassIds)) {
1072 2
                    $shipmentItems[] = $ShipmentItem;
1073 2
                }
1074 2
                $productClassIds[] = $ShipmentItem->getProductClass()->getId();
1075 2
            }
1076 2
        }
1077
1078 2
        $builder = $app->form();
1079
        $builder
1080 2
            ->add('shipping_multiple', 'collection', array(
1081 2
                'type' => 'shipping_multiple',
1082 2
                'data' => $shipmentItems,
1083 2
                'allow_add' => true,
1084 2
                'allow_delete' => true,
1085 2
            ));
1086
1087 2
        $event = new EventArgs(
1088
            array(
1089 2
                'builder' => $builder,
1090 2
                'Order' => $Order,
1091 2
            ),
1092
            $request
1093 2
        );
1094 2
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_INITIALIZE, $event);
1095
1096 2
        $form = $builder->getForm();
1097
1098 2
        $form->handleRequest($request);
1099
1100 2
        $errors = array();
1101 2
        if ($form->isSubmitted() && $form->isValid()) {
1102 2
            $data = $form['shipping_multiple'];
1103
1104
            // 数量が超えていないか、同一でないとエラー
1105 2
            $itemQuantities = array();
1106 9
            foreach ($data as $mulitples) {
1107
                /** @var \Eccube\Entity\ShipmentItem $multipleItem */
1108 2
                $multipleItem = $mulitples->getData();
1109 2 View Code Duplication
                foreach ($mulitples as $items) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1110 2
                    foreach ($items as $item) {
1111 2
                        $quantity = $item['quantity']->getData();
1112 2
                        $itemId = $multipleItem->getProductClass()->getId();
1113 2
                        if (array_key_exists($itemId, $itemQuantities)) {
1114 2
                            $itemQuantities[$itemId] = $itemQuantities[$itemId] + $quantity;
1115 2
                        } else {
1116 2
                            $itemQuantities[$itemId] = $quantity;
1117
                        }
1118 2
                    }
1119 2
                }
1120 2
            }
1121
1122 2
            foreach ($compItemQuantities as $key => $value) {
1123 2
                if (array_key_exists($key, $itemQuantities)) {
1124 2
                    if ($itemQuantities[$key] != $value) {
1125
                        $errors[] = array('message' => $app->trans('shopping.multiple.quantity.diff'));
1126
1127
                        // 対象がなければエラー
1128
                        return $app->render('Shopping/shipping_multiple.twig', array(
1129
                            'form' => $form->createView(),
1130
                            'shipmentItems' => $shipmentItems,
1131
                            'compItemQuantities' => $compItemQuantities,
1132
                            'errors' => $errors,
1133
                        ));
1134
                    }
1135 2
                }
1136 2
            }
1137
1138
            // お届け先情報をdelete/insert
1139 2
            $shippings = $Order->getShippings();
1140 2
            foreach ($shippings as $Shipping) {
1141 2
                $Order->removeShipping($Shipping);
1142 2
                $app['orm.em']->remove($Shipping);
1143 2
            }
1144
1145 2
            foreach ($data as $mulitples) {
1146
                /** @var \Eccube\Entity\ShipmentItem $multipleItem */
1147 2
                $multipleItem = $mulitples->getData();
1148
1149 2
                foreach ($mulitples as $items) {
1150 2
                    foreach ($items as $item) {
1151
                        // 追加された配送先情報を作成
1152 2
                        $Delivery = $multipleItem->getShipping()->getDelivery();
1153
1154
                        // 選択された情報を取得
1155 2
                        $data = $item['customer_address']->getData();
1156 2
                        if ($data instanceof CustomerAddress) {
0 ignored issues
show
Bug introduced by
The class Eccube\Entity\CustomerAddress does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

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

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

2. Missing use statement

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

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

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

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