Failed Conditions
Pull Request — master (#2047)
by
unknown
424:13 queued 417:09
created

ShoppingController::shoppingError()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
ccs 6
cts 7
cp 0.8571
rs 9.4285
cc 2
eloc 8
nc 2
nop 2
crap 2.0116
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 73
    public function index(Application $app, Request $request)
73
    {
74 73
        $cartService = $app['eccube.service.cart'];
75
76
        // カートチェック
77 73
        if (!$cartService->isLocked()) {
78 4
            log_info('カートが存在しません');
79
            // カートが存在しない、カートがロックされていない時はエラー
80 4
            return $app->redirect($app->url('cart'));
81
        }
82
83
        // カートチェック
84 69 View Code Duplication
        if (count($cartService->getCart()->getCartItems()) <= 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
85 1
            log_info('カートに商品が入っていないためショッピングカート画面にリダイレクト');
86
            // カートが存在しない時はエラー
87 1
            return $app->redirect($app->url('cart'));
88
        }
89
90
        // 登録済みの受注情報を取得
91 68
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
92
93
        // 初回アクセス(受注情報がない)の場合は, 受注情報を作成
94 68
        if (is_null($Order)) {
95
            // 未ログインの場合, ログイン画面へリダイレクト.
96 68
            if (!$app->isGranted('IS_AUTHENTICATED_FULLY')) {
97
                // 非会員でも一度会員登録されていればショッピング画面へ遷移
98 31
                $Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey);
99
100 31
                if (is_null($Customer)) {
101
                    log_info('未ログインのためログイン画面にリダイレクト');
102 31
                    return $app->redirect($app->url('shopping_login'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
103
                }
104
            } else {
105 37
                $Customer = $app->user();
106
            }
107
108
            try {
109
                // 受注情報を作成
110 68
                $Order = $app['eccube.service.shopping']->createOrder($Customer);
111
            } catch (CartException $e) {
112
                log_error('初回受注情報作成エラー', array($e->getMessage()));
113
                $app->addRequestError($e->getMessage());
114
                return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
115
            }
116
117
            // セッション情報を削除
118 68
            $app['session']->remove($this->sessionOrderKey);
119 68
            $app['session']->remove($this->sessionMultipleKey);
120
        }
121
122
        // 受注関連情報を最新状態に更新
123 68
        $app['orm.em']->refresh($Order);
124
125
        // form作成
126 68
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
127
128 68
        $event = new EventArgs(
129
            array(
130 68
                'builder' => $builder,
131 68
                'Order' => $Order,
132
            ),
133
            $request
134
        );
135 68
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_INDEX_INITIALIZE, $event);
136
137 68
        $form = $builder->getForm();
138
139 68
        if ($Order->getTotalPrice() < 0) {
140
            // 合計金額がマイナスの場合、エラー
141
            log_info('受注金額マイナスエラー', array($Order->getId()));
142
            $message = $app->trans('shopping.total.price', array('totalPrice' => number_format($Order->getTotalPrice())));
143
            $app->addError($message);
144
145
            return $app->redirect($app->url('shopping_error'));
146
        }
147
148
        // 複数配送の場合、エラーメッセージを一度だけ表示
149 68
        if (!$app['session']->has($this->sessionMultipleKey)) {
150 68
            if (count($Order->getShippings()) > 1) {
151 5
                $app->addRequestError('shopping.multiple.delivery');
152
            }
153 68
            $app['session']->set($this->sessionMultipleKey, 'multiple');
154
        }
155
156 68
        return $app->render('Shopping/index.twig', array(
157 68
            'form' => $form->createView(),
158 68
            'Order' => $Order,
159
        ));
160
    }
161
162
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
163
     * 購入処理
164
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
165 16
    public function confirm(Application $app, Request $request)
166
    {
167 16
        $cartService = $app['eccube.service.cart'];
168
169
        // カートチェック
170 16
        if (!$cartService->isLocked()) {
171
            // カートが存在しない、カートがロックされていない時はエラー
172
            log_info('カートが存在しません');
173
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
174
        }
175
176 16
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
177 16
        if (!$Order) {
178
            log_info('購入処理中の受注情報がないため購入エラー');
179
            $app->addError('front.shopping.order.error');
180
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
181
        }
182
183 16
        if ('POST' !== $request->getMethod()) {
184
            return $app->redirect($app->url('cart'));
185
        }
186
187
        // form作成
188 16
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
189
190 16
        $event = new EventArgs(
191
            array(
192 16
                'builder' => $builder,
193 16
                'Order' => $Order,
194
            ),
195
            $request
196
        );
197 16
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CONFIRM_INITIALIZE, $event);
198
199 16
        $form = $builder->getForm();
200
201 16
        $form->handleRequest($request);
202
203 16
        if ($form->isSubmitted() && $form->isValid()) {
204 16
            $data = $form->getData();
205
206 16
            log_info('購入処理開始', array($Order->getId()));
207
208
            // トランザクション制御
209 16
            $em = $app['orm.em'];
210 16
            $em->getConnection()->beginTransaction();
211
            try {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
212
213
                // お問い合わせ、配送時間などのフォーム項目をセット
214 16
                $app['eccube.service.shopping']->setFormData($Order, $data);
215
                // 購入処理
216 16
                $app['eccube.service.shopping']->processPurchase($Order);
217
218 16
                $em->flush();
219 16
                $em->getConnection()->commit();
220
221 16
                log_info('購入処理完了', array($Order->getId()));
222
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
223
            } catch (ShoppingException $e) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
224
225
                log_error('購入エラー', array($e->getMessage()));
226
227
                $em->getConnection()->rollback();
228
229
                $app->log($e);
230
                $app->addError($e->getMessage());
231
232
                return $app->redirect($app->url('shopping_error'));
233
            } catch (\Exception $e) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
234
235
                log_error('予期しないエラー', array($e->getMessage()));
236
237
                $em->getConnection()->rollback();
238
239
                $app->log($e);
240
241
                $app->addError('front.shopping.system.error');
242
                return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
243
            }
244
245
            // カート削除
246 16
            $app['eccube.service.cart']->clear()->save();
247
248 16
            $event = new EventArgs(
249
                array(
250 16
                    'form' => $form,
251 16
                    'Order' => $Order,
252
                ),
253
                $request
254
            );
255 16
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CONFIRM_PROCESSING, $event);
256
257 16 View Code Duplication
            if ($event->getResponse() !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
258
                log_info('イベントレスポンス返却', array($Order->getId()));
259
                return $event->getResponse();
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
260
            }
261
262
            // 受注IDをセッションにセット
263 16
            $app['session']->set($this->sessionOrderKey, $Order->getId());
264
265
            // メール送信
266 16
            $MailHistory = $app['eccube.service.shopping']->sendOrderMail($Order);
267
268 16
            $event = new EventArgs(
269
                array(
270 16
                    'form' => $form,
271 16
                    'Order' => $Order,
272 16
                    'MailHistory' => $MailHistory,
273
                ),
274
                $request
275
            );
276 16
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CONFIRM_COMPLETE, $event);
277
278 16 View Code Duplication
            if ($event->getResponse() !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
279
                log_info('イベントレスポンス返却', array($Order->getId()));
280
                return $event->getResponse();
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
281
            }
282
283
            // 完了画面表示
284 16
            return $app->redirect($app->url('shopping_complete'));
285
        }
286
287
        log_info('購入チェックエラー', array($Order->getId()));
288
289
        return $app->render('Shopping/index.twig', array(
290
            'form' => $form->createView(),
291
            'Order' => $Order,
292
        ));
293
    }
294
295
296
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
297
     * 購入完了画面表示
298
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
299 2
    public function complete(Application $app, Request $request)
300
    {
301
        // 受注IDを取得
302 2
        $orderId = $app['session']->get($this->sessionOrderKey);
303
304 2
        $event = new EventArgs(
305
            array(
306 2
                'orderId' => $orderId,
307
            ),
308
            $request
309
        );
310 2
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_COMPLETE_INITIALIZE, $event);
311
312 2
        if ($event->getResponse() !== null) {
313
            return $event->getResponse();
314
        }
315
316
        // 受注IDセッションを削除
317 2
        $app['session']->remove($this->sessionOrderKey);
318
319 2
        log_info('購入処理完了', array($orderId));
320
321 2
        return $app->render('Shopping/complete.twig', array(
322 2
            'orderId' => $orderId,
323
        ));
324
    }
325
326
327
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
328
     * 配送業者選択処理
329
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
330 6
    public function delivery(Application $app, Request $request)
331
    {
332
        // カートチェック
333 6
        if (!$app['eccube.service.cart']->isLocked()) {
334
            // カートが存在しない、カートがロックされていない時はエラー
335
            log_info('カートが存在しません');
336
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
337
        }
338
339 6
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
340 6
        if (!$Order) {
341
            log_info('購入処理中の受注情報がないため購入エラー');
342
            $app->addError('front.shopping.order.error');
343
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
344
        }
345
346 6
        if ('POST' !== $request->getMethod()) {
347
            return $app->redirect($app->url('shopping'));
348
        }
349
350 6
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
351
352 6
        $event = new EventArgs(
353
            array(
354 6
                'builder' => $builder,
355 6
                'Order' => $Order,
356
            ),
357
            $request
358
        );
359 6
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_DELIVERY_INITIALIZE, $event);
360
361 6
        $form = $builder->getForm();
362
363 6
        $form->handleRequest($request);
364
365 6
        if ($form->isSubmitted() && $form->isValid()) {
366 2
            log_info('配送業者変更処理開始', array($Order->getId()));
367
368 2
            $data = $form->getData();
369
370 2
            $shippings = $data['shippings'];
371
372 2
            $productDeliveryFeeTotal = 0;
373 2
            $BaseInfo = $app['eccube.repository.base_info']->get();
374
375 2
            foreach ($shippings as $Shipping) {
376 2
                $Delivery = $Shipping->getDelivery();
377
378 2
                if ($Delivery) {
379 2
                    $deliveryFee = $app['eccube.repository.delivery_fee']->findOneBy(array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
380 2
                        'Delivery' => $Delivery,
381 2
                        'Pref' => $Shipping->getPref()
382
                    ));
383
384
                    // 商品ごとの配送料合計
385 2
                    if (!is_null($BaseInfo->getOptionProductDeliveryFee())) {
386 2
                        $productDeliveryFeeTotal += $app['eccube.service.shopping']->getProductDeliveryFee($Shipping);
387
                    }
388
389 2
                    $Shipping->setDeliveryFee($deliveryFee);
390 2
                    $Shipping->setShippingDeliveryFee($deliveryFee->getFee() + $productDeliveryFeeTotal);
391 2
                    $Shipping->setShippingDeliveryName($Delivery->getName());
392
                }
393
            }
394
395
            // 支払い情報をセット
396 2
            $payment = $data['payment'];
397 2
            $message = $data['message'];
398
399 2
            $Order->setPayment($payment);
400 2
            $Order->setPaymentMethod($payment->getMethod());
401 2
            $Order->setMessage($message);
402 2
            $Order->setCharge($payment->getCharge());
403
404 2
            $Order->setDeliveryFeeTotal($app['eccube.service.shopping']->getShippingDeliveryFeeTotal($shippings));
405
406
            // 合計金額の再計算
407 2
            $Order = $app['eccube.service.shopping']->getAmount($Order);
408
409
            // 受注関連情報を最新状態に更新
410 2
            $app['orm.em']->flush();
411
412 2
            $event = new EventArgs(
413
                array(
414 2
                    'form' => $form,
415 2
                    'Order' => $Order,
416
                ),
417
                $request
418
            );
419 2
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_DELIVERY_COMPLETE, $event);
420
421 2
            log_info('配送業者変更処理完了', array($Order->getId()));
422 2
            return $app->redirect($app->url('shopping'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
423
        }
424
425 4
        log_info('配送業者変更入力チェックエラー', array($Order->getId()));
426 4
        return $app->render('Shopping/index.twig', array(
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
427 4
            'form' => $form->createView(),
428 4
            'Order' => $Order,
429
        ));
430
    }
431
432
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
433
     * 支払い方法選択処理
434
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
435 4
    public function payment(Application $app, Request $request)
436
    {
437 4
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
438 4
        if (!$Order) {
439
            log_info('購入処理中の受注情報がないため購入エラー');
440
            $app->addError('front.shopping.order.error');
441
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
442
        }
443
444 4
        if ('POST' !== $request->getMethod()) {
445
            return $app->redirect($app->url('shopping'));
446
        }
447
448 4
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
449
450 4
        $event = new EventArgs(
451
            array(
452 4
                'builder' => $builder,
453 4
                'Order' => $Order,
454
            ),
455
            $request
456
        );
457 4
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_PAYMENT_INITIALIZE, $event);
458
459 4
        $form = $builder->getForm();
460
461 4
        $form->handleRequest($request);
462
463 4
        if ($form->isSubmitted() && $form->isValid()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
464
465 2
            log_info('支払い方法変更処理開始', array("id" => $Order->getId()));
466
467 2
            $data = $form->getData();
468 2
            $payment = $data['payment'];
469 2
            $message = $data['message'];
470
471 2
            $Order->setPayment($payment);
472 2
            $Order->setPaymentMethod($payment->getMethod());
473 2
            $Order->setMessage($message);
474 2
            $Order->setCharge($payment->getCharge());
475
476
            // 合計金額の再計算
477 2
            $Order = $app['eccube.service.shopping']->getAmount($Order);
478
479
            // 受注関連情報を最新状態に更新
480 2
            $app['orm.em']->flush();
481
482 2
            $event = new EventArgs(
483
                array(
484 2
                    'form' => $form,
485 2
                    'Order' => $Order,
486
                ),
487
                $request
488
            );
489 2
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_PAYMENT_COMPLETE, $event);
490
491 2
            log_info('支払い方法変更処理完了', array("id" => $Order->getId(), "payment" => $payment->getId()));
492
493 2
            return $app->redirect($app->url('shopping'));
494
        }
495
496 2
        log_info('支払い方法変更入力チェックエラー', array("id" => $Order->getId()));
497 2
        return $app->render('Shopping/index.twig', array(
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
498 2
            'form' => $form->createView(),
499 2
            'Order' => $Order,
500
        ));
501
    }
502
503
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
introduced by
Doc comment for parameter "$id" missing
Loading history...
504
     * お届け先変更がクリックされた場合の処理
505
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
506 18 View Code Duplication
    public function shippingChange(Application $app, Request $request, $id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
507
    {
508 18
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
509 18
        if (!$Order) {
510
            $app->addError('front.shopping.order.error');
511
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
512
        }
513
514 18
        if ('POST' !== $request->getMethod()) {
515
            return $app->redirect($app->url('shopping'));
516
        }
517
518 18
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
519
520 18
        $event = new EventArgs(
521
            array(
522 18
                'builder' => $builder,
523 18
                'Order' => $Order,
524
            ),
525
            $request
526
        );
527 18
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_CHANGE_INITIALIZE, $event);
528
529 18
        $form = $builder->getForm();
530
531 18
        $form->handleRequest($request);
532
533 18
        if ($form->isSubmitted() && $form->isValid()) {
534 18
            $data = $form->getData();
535 18
            $message = $data['message'];
536 18
            $Order->setMessage($message);
537
            // 受注情報を更新
538 18
            $app['orm.em']->flush();
539
540
            // お届け先設定一覧へリダイレクト
541 18
            return $app->redirect($app->url('shopping_shipping', array('id' => $id)));
542
        }
543
544
        return $app->render('Shopping/index.twig', array(
545
            'form' => $form->createView(),
546
            'Order' => $Order,
547
        ));
548
    }
549
550
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
introduced by
Doc comment for parameter "$id" missing
Loading history...
551
     * お届け先の設定一覧からの選択
552
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
553 4
    public function shipping(Application $app, Request $request, $id)
554
    {
555
        // カートチェック
556 4
        if (!$app['eccube.service.cart']->isLocked()) {
557
            // カートが存在しない、カートがロックされていない時はエラー
558
            log_info('カートが存在しません');
559
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
560
        }
561
562 4
        if ('POST' === $request->getMethod()) {
563
            $address = $request->get('address');
564
565
            if (is_null($address)) {
566
                // 選択されていなければエラー
567
                log_info('お届け先入力チェックエラー');
568
                return $app->render(
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
569
                    'Shopping/shipping.twig',
570
                    array(
571
                        'Customer' => $app->user(),
572
                        'shippingId' => $id,
573
                        'error' => true,
574
                    )
575
                );
576
            }
577
578
            // 選択されたお届け先情報を取得
579
            $CustomerAddress = $app['eccube.repository.customer_address']->findOneBy(array(
580
                'Customer' => $app->user(),
581
                'id' => $address,
582
            ));
583
            if (is_null($CustomerAddress)) {
584
                throw new NotFoundHttpException('選択されたお届け先住所が存在しない');
585
            }
586
587
            $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
588
            if (!$Order) {
589
                log_info('購入処理中の受注情報がないため購入エラー');
590
                $app->addError('front.shopping.order.error');
591
592
                return $app->redirect($app->url('shopping_error'));
593
            }
594
595
            $Shipping = $Order->findShipping($id);
596
            if (!$Shipping) {
597
                throw new NotFoundHttpException('お届け先情報が存在しない');
598
            }
599
600
            log_info('お届先情報更新開始', array($Shipping->getId()));
601
602
            // お届け先情報を更新
603
            $Shipping
604
                ->setFromCustomerAddress($CustomerAddress);
605
606
            // 配送料金の設定
607
            $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
608
609
            // 合計金額の再計算
610
            $Order = $app['eccube.service.shopping']->getAmount($Order);
611
612
            // 配送先を更新
613
            $app['orm.em']->flush();
614
615
            $event = new EventArgs(
616
                array(
617
                    'Order' => $Order,
618
                    'shippingId' => $id,
619
                ),
620
                $request
621
            );
622
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_COMPLETE, $event);
623
624
            log_info('お届先情報更新完了', array($Shipping->getId()));
625
            return $app->redirect($app->url('shopping'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
626
        }
627
628 4
        return $app->render(
629 4
            'Shopping/shipping.twig',
630
            array(
631 4
                'Customer' => $app->user(),
632 4
                'shippingId' => $id,
633
                'error' => false,
634
            )
635
        );
636
    }
637
638
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
introduced by
Doc comment for parameter "$id" missing
Loading history...
639
     * お届け先の設定(非会員)がクリックされた場合の処理
640
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
641 19 View Code Duplication
    public function shippingEditChange(Application $app, Request $request, $id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
642
    {
643 19
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
644 19
        if (!$Order) {
645
            $app->addError('front.shopping.order.error');
646
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
647
        }
648
649 19
        if ('POST' !== $request->getMethod()) {
650 1
            return $app->redirect($app->url('shopping'));
651
        }
652
653 18
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
654
655 18
        $event = new EventArgs(
656
            array(
657 18
                'builder' => $builder,
658 18
                'Order' => $Order,
659
            ),
660
            $request
661
        );
662 18
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_CHANGE_INITIALIZE, $event);
663
664 18
        $form = $builder->getForm();
665
666 18
        $form->handleRequest($request);
667
668 18
        if ($form->isSubmitted() && $form->isValid()) {
669 17
            $data = $form->getData();
670 17
            $message = $data['message'];
671 17
            $Order->setMessage($message);
672
            // 受注情報を更新
673 17
            $app['orm.em']->flush();
674
675
            // お届け先設定一覧へリダイレクト
676 17
            return $app->redirect($app->url('shopping_shipping_edit', array('id' => $id)));
677
        }
678
679 1
        return $app->render('Shopping/index.twig', array(
680 1
            'form' => $form->createView(),
681 1
            'Order' => $Order,
682
        ));
683
    }
684
685
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
introduced by
Doc comment for parameter "$id" missing
Loading history...
686
     * お届け先の設定(非会員でも使用する)
687
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
688 6
    public function shippingEdit(Application $app, Request $request, $id)
689
    {
690
        // Change title when non-member.
691 6
        $subtitle = '商品購入';
692 6
        $title = 'お届け先の変更';
693
        // 配送先住所最大値判定
694 6
        $Customer = $app->user();
695 6
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
696 3
            $title = 'お届け先の追加';
697 3
            $addressCurrNum = count($app->user()->getCustomerAddresses());
698 3
            $addressMax = $app['config']['deliv_addr_max'];
699 3
            if ($addressCurrNum >= $addressMax) {
700
                throw new NotFoundHttpException('配送先住所最大数エラー');
701
            }
702
        }
703
704
        // カートチェック
705 6
        if (!$app['eccube.service.cart']->isLocked()) {
706
            // カートが存在しない、カートがロックされていない時はエラー
707
            log_info('カートが存在しません');
708
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
709
        }
710
711 6
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
712 6
        if (!$Order) {
713
            log_info('購入処理中の受注情報がないため購入エラー');
714
            $app->addError('front.shopping.order.error');
715
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
716
        }
717
718 6
        $Shipping = $Order->findShipping($id);
719 6
        if (!$Shipping) {
720
            throw new NotFoundHttpException('設定されている配送先が存在しない');
721
        }
722 6
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
723 3
            $Shipping->clearCustomerAddress();
724
        }
725
726 6
        $CustomerAddress = new CustomerAddress();
727 6
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
728 3
            $CustomerAddress->setCustomer($Customer);
729
        } else {
730 3
            $CustomerAddress->setFromShipping($Shipping);
731
        }
732
733 6
        $builder = $app['form.factory']->createBuilder('shopping_shipping', $CustomerAddress);
734
735 6
        $event = new EventArgs(
736
            array(
737 6
                'builder' => $builder,
738 6
                'Order' => $Order,
739 6
                'Shipping' => $Shipping,
740 6
                'CustomerAddress' => $CustomerAddress,
741
            ),
742
            $request
743
        );
744 6
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_INITIALIZE, $event);
745
746 6
        $form = $builder->getForm();
747
748 6
        $form->handleRequest($request);
749
750 6
        if ($form->isSubmitted() && $form->isValid()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
751
752 3
            log_info('お届け先追加処理開始', array('id' => $Order->getId(), 'shipping' => $id));
753
754
            // 会員の場合、お届け先情報を新規登録
755 3
            $Shipping->setFromCustomerAddress($CustomerAddress);
756
757 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...
758 2
                $app['orm.em']->persist($CustomerAddress);
759 2
                log_info('新規お届け先登録', array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
760 2
                    'id' => $Order->getId(),
761 2
                    'shipping' => $id,
762 2
                    'customer address' => $CustomerAddress->getId()));
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 20.
Loading history...
763
            }
764
765
            // 配送料金の設定
766 3
            $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
767
768
            // 合計金額の再計算
769 3
            $app['eccube.service.shopping']->getAmount($Order);
770
771
            // 配送先を更新 
772 3
            $app['orm.em']->flush();
773
774 3
            $event = new EventArgs(
775
                array(
776 3
                    'form' => $form,
777 3
                    'Shipping' => $Shipping,
778 3
                    'CustomerAddress' => $CustomerAddress,
779
                ),
780
                $request
781
            );
782 3
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_COMPLETE, $event);
783
784 3
            log_info('お届け先追加処理完了', array('id' => $Order->getId(), 'shipping' => $id));
785 3
            return $app->redirect($app->url('shopping'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
786
        }
787
788
        // Subtitle for page
789 5
        $subtitle = $subtitle.' / '.$title;
790
791 5
        return $app->render('Shopping/shipping_edit.twig', array(
792 5
            'form' => $form->createView(),
793 5
            'shippingId' => $id,
794 5
            'subtitle' => $subtitle,
795 5
            'title' => $title,
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
    public function customer(Application $app, Request $request)
803
    {
804
        if ($request->isXmlHttpRequest()) {
805
            try {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
806
807
                log_info('非会員お客様情報変更処理開始');
808
809
                $data = $request->request->all();
810
811
                // 入力チェック
812
                $errors = $this->customerValidation($app, $data);
813
814
                foreach ($errors as $error) {
815 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...
816
                        log_info('非会員お客様情報変更入力チェックエラー');
817
                        $response = new Response(json_encode('NG'), 400);
818
                        $response->headers->set('Content-Type', 'application/json');
819
                        return $response;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
820
                    }
821
                }
822
823
                $pref = $app['eccube.repository.master.pref']->findOneBy(array('name' => $data['customer_pref']));
824 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...
825
                    log_info('非会員お客様情報変更入力チェックエラー');
826
                    $response = new Response(json_encode('NG'), 400);
827
                    $response->headers->set('Content-Type', 'application/json');
828
                    return $response;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
829
                }
830
831
                $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
832
                if (!$Order) {
833
                    log_info('カートが存在しません');
834
                    $app->addError('front.shopping.order.error');
835
                    return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
836
                }
837
838
                $Order
839
                    ->setName01($data['customer_name01'])
840
                    ->setName02($data['customer_name02'])
841
                    ->setCompanyName($data['customer_company_name'])
842
                    ->setTel01($data['customer_tel01'])
843
                    ->setTel02($data['customer_tel02'])
844
                    ->setTel03($data['customer_tel03'])
845
                    ->setZip01($data['customer_zip01'])
846
                    ->setZip02($data['customer_zip02'])
847
                    ->setZipCode($data['customer_zip01'].$data['customer_zip02'])
848
                    ->setPref($pref)
849
                    ->setAddr01($data['customer_addr01'])
850
                    ->setAddr02($data['customer_addr02'])
851
                    ->setEmail($data['customer_email']);
852
853
                // 配送先を更新
854
                $app['orm.em']->flush();
855
856
                // 受注関連情報を最新状態に更新
857
                $app['orm.em']->refresh($Order);
858
859
                $event = new EventArgs(
860
                    array(
861
                        'Order' => $Order,
862
                        'data' => $data,
863
                    ),
864
                    $request
865
                );
866
                $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CUSTOMER_INITIALIZE, $event);
867
868
                log_info('非会員お客様情報変更処理完了', array($Order->getId()));
869
                $response = new Response(json_encode('OK'));
870
                $response->headers->set('Content-Type', 'application/json');
871
            } catch (\Exception $e) {
872
                log_error('予期しないエラー', array($e->getMessage()));
873
                $app['monolog']->error($e);
874
875
                $response = new Response(json_encode('NG'), 500);
876
                $response->headers->set('Content-Type', 'application/json');
877
            }
878
879
            return $response;
880
        }
881
    }
882
883
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
884
     * ログイン
885
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
886 4
    public function login(Application $app, Request $request)
887
    {
888 4
        if (!$app['eccube.service.cart']->isLocked()) {
889 3
            return $app->redirect($app->url('cart'));
890
        }
891
892 1
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
893
            return $app->redirect($app->url('shopping'));
894
        }
895
896
        /* @var $form \Symfony\Component\Form\FormInterface */
897 1
        $builder = $app['form.factory']->createNamedBuilder('', 'customer_login');
898
899 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...
900
            $Customer = $app->user();
901
            if ($Customer) {
902
                $builder->get('login_email')->setData($Customer->getEmail());
903
            }
904
        }
905
906 1
        $event = new EventArgs(
907
            array(
908 1
                'builder' => $builder,
909
            ),
910
            $request
911
        );
912 1
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_LOGIN_INITIALIZE, $event);
913
914 1
        $form = $builder->getForm();
915
916 1
        return $app->render('Shopping/login.twig', array(
917 1
            'error' => $app['security.last_error']($request),
918 1
            'form' => $form->createView(),
919
        ));
920
    }
921
922
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
923
     * 非会員処理
924
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
925 36
    public function nonmember(Application $app, Request $request)
926
    {
927 36
        $cartService = $app['eccube.service.cart'];
928
929
        // カートチェック
930 36
        if (!$cartService->isLocked()) {
931
            // カートが存在しない、カートがロックされていない時はエラー
932 2
            log_info('カートが存在しません');
933 2
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
934
        }
935
936
        // ログイン済みの場合は, 購入画面へリダイレクト.
937 34
        if ($app->isGranted('ROLE_USER')) {
938 1
            return $app->redirect($app->url('shopping'));
939
        }
940
941
        // カートチェック
942 33 View Code Duplication
        if (count($cartService->getCart()->getCartItems()) <= 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
943
            // カートが存在しない時はエラー
944
            log_info('カートに商品が入っていないためショッピングカート画面にリダイレクト');
945
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
946
        }
947
948 33
        $builder = $app['form.factory']->createBuilder('nonmember');
949
950 33
        $event = new EventArgs(
951
            array(
952 33
                'builder' => $builder,
953
            ),
954
            $request
955
        );
956 33
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_NONMEMBER_INITIALIZE, $event);
957
958 33
        $form = $builder->getForm();
959
960 33
        $form->handleRequest($request);
961
962 33
        if ($form->isSubmitted() && $form->isValid()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
963
964 32
            log_info('非会員お客様情報登録開始');
965
966 32
            $data = $form->getData();
967 32
            $Customer = new Customer();
968
            $Customer
969 32
                ->setName01($data['name01'])
970 32
                ->setName02($data['name02'])
971 32
                ->setKana01($data['kana01'])
972 32
                ->setKana02($data['kana02'])
973 32
                ->setCompanyName($data['company_name'])
974 32
                ->setEmail($data['email'])
975 32
                ->setTel01($data['tel01'])
976 32
                ->setTel02($data['tel02'])
977 32
                ->setTel03($data['tel03'])
978 32
                ->setZip01($data['zip01'])
979 32
                ->setZip02($data['zip02'])
980 32
                ->setZipCode($data['zip01'].$data['zip02'])
981 32
                ->setPref($data['pref'])
982 32
                ->setAddr01($data['addr01'])
983 32
                ->setAddr02($data['addr02']);
984
985
            // 非会員複数配送用
986 32
            $CustomerAddress = new CustomerAddress();
987
            $CustomerAddress
988 32
                ->setCustomer($Customer)
989 32
                ->setName01($data['name01'])
990 32
                ->setName02($data['name02'])
991 32
                ->setKana01($data['kana01'])
992 32
                ->setKana02($data['kana02'])
993 32
                ->setCompanyName($data['company_name'])
994 32
                ->setTel01($data['tel01'])
995 32
                ->setTel02($data['tel02'])
996 32
                ->setTel03($data['tel03'])
997 32
                ->setZip01($data['zip01'])
998 32
                ->setZip02($data['zip02'])
999 32
                ->setZipCode($data['zip01'].$data['zip02'])
1000 32
                ->setPref($data['pref'])
1001 32
                ->setAddr01($data['addr01'])
1002 32
                ->setAddr02($data['addr02'])
1003 32
                ->setDelFlg(Constant::DISABLED);
1004 32
            $Customer->addCustomerAddress($CustomerAddress);
1005
1006
            // 受注情報を取得
1007 32
            $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
1008
1009
            // 初回アクセス(受注データがない)の場合は, 受注情報を作成
1010 32
            if (is_null($Order)) {
1011
                // 受注情報を作成
1012
                try {
1013
                    // 受注情報を作成
1014 32
                    $Order = $app['eccube.service.shopping']->createOrder($Customer);
1015
                } catch (CartException $e) {
1016
                    $app->addRequestError($e->getMessage());
1017
                    return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1018
                }
1019
            }
1020
1021
            // 非会員用セッションを作成
1022 32
            $nonMember = array();
1023 32
            $nonMember['customer'] = $Customer;
1024 32
            $nonMember['pref'] = $Customer->getPref()->getId();
1025 32
            $app['session']->set($this->sessionKey, $nonMember);
1026
1027 32
            $customerAddresses = array();
1028 32
            $customerAddresses[] = $CustomerAddress;
1029 32
            $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses));
1030
1031 32
            $event = new EventArgs(
1032
                array(
1033 32
                    'form' => $form,
1034 32
                    'Order' => $Order,
1035
                ),
1036
                $request
1037
            );
1038 32
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_NONMEMBER_COMPLETE, $event);
1039
1040 32
            if ($event->getResponse() !== null) {
1041
                return $event->getResponse();
1042
            }
1043
1044 32
            log_info('非会員お客様情報登録完了', array($Order->getId()));
1045
1046 32
            return $app->redirect($app->url('shopping'));
1047
        }
1048
1049 1
        return $app->render('Shopping/nonmember.twig', array(
1050 1
            'form' => $form->createView(),
1051
        ));
1052
    }
1053
1054
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1055
     * 複数配送処理がクリックされた場合の処理
1056
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1057 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...
1058
    {
1059
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
1060
        if (!$Order) {
1061
            $app->addError('front.shopping.order.error');
1062
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1063
        }
1064
1065
        if ('POST' !== $request->getMethod()) {
1066
            return $app->redirect($app->url('shopping'));
1067
        }
1068
1069
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
1070
1071
        $event = new EventArgs(
1072
            array(
1073
                'builder' => $builder,
1074
                'Order' => $Order,
1075
            ),
1076
            $request
1077
        );
1078
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_CHANGE_INITIALIZE, $event);
1079
1080
        $form = $builder->getForm();
1081
1082
        $form->handleRequest($request);
1083
1084
        if ($form->isSubmitted() && $form->isValid()) {
1085
            $data = $form->getData();
1086
            $message = $data['message'];
1087
            $Order->setMessage($message);
1088
            // 受注情報を更新
1089
            $app['orm.em']->flush();
1090
1091
            // 複数配送設定へリダイレクト
1092
            return $app->redirect($app->url('shopping_shipping_multiple'));
1093
        }
1094
1095
        return $app->render('Shopping/index.twig', array(
1096
            'form' => $form->createView(),
1097
            'Order' => $Order,
1098
        ));
1099
    }
1100
1101
1102
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1103
     * 複数配送処理
1104
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1105 37
    public function shippingMultiple(Application $app, Request $request)
1106
    {
1107 37
        $cartService = $app['eccube.service.cart'];
1108
1109
        // カートチェック
1110 37
        if (!$cartService->isLocked()) {
1111
            // カートが存在しない、カートがロックされていない時はエラー
1112 4
            log_info('カートが存在しません');
1113 4
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1114
        }
1115
1116
        // カートチェック
1117 33 View Code Duplication
        if (count($cartService->getCart()->getCartItems()) <= 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
1118
            // カートが存在しない時はエラー
1119
            log_info('カートに商品が入っていないためショッピングカート画面にリダイレクト');
1120
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1121
        }
1122
1123
        /** @var \Eccube\Entity\Order $Order */
1124 33
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
1125 33
        if (!$Order) {
1126
            log_info('購入処理中の受注情報がないため購入エラー');
1127
            $app->addError('front.shopping.order.error');
1128
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1129
        }
1130
1131
        // 処理しやすいようにすべてのShippingItemをまとめる
1132 33
        $ShipmentItems = array();
1133 33
        foreach ($Order->getShippings() as $Shipping) {
1134 33
            foreach ($Shipping->getShipmentItems() as $ShipmentItem) {
1135 33
                $ShipmentItems[] = $ShipmentItem;
1136
            }
1137
        }
1138
1139
        // Orderに含まれる商品ごとの数量を求める
1140 33
        $ItemQuantitiesByClassId = array();
1141 33
        foreach ($ShipmentItems as $item) {
1142 33
            $itemId = $item->getProductClass()->getId();
1143 33
            $quantity = $item->getQuantity();
1144 33
            if (array_key_exists($itemId, $ItemQuantitiesByClassId)) {
1145
                $ItemQuantitiesByClassId[$itemId] += $quantity;
1146
            } else {
1147 33
                $ItemQuantitiesByClassId[$itemId] = $quantity;
1148
            }
1149
        }
1150
1151
        // FormBuilder用に商品ごとにShippingItemをまとめる
1152 33
        $ShipmentItemsForFormBuilder = array();
1153 33
        $tmpAddedClassIds = array();
1154 33
        foreach ($ShipmentItems as $item) {
1155 33
            $itemId = $item->getProductClass()->getId();
1156 33
            if (!in_array($itemId, $tmpAddedClassIds)) {
1157 33
                $ShipmentItemsForFormBuilder[] = $item;
1158 33
                $tmpAddedClassIds[] = $itemId;
1159
            }
1160
        }
1161
1162
        // Form生成
1163 33
        $builder = $app->form();
1164
        $builder
1165 33
            ->add('shipping_multiple', 'collection', array(
1166 33
                'type' => 'shipping_multiple',
1167 33
                'data' => $ShipmentItemsForFormBuilder,
1168
                'allow_add' => true,
1169
                'allow_delete' => true,
1170
            ));
1171
        // Event
1172 33
        $event = new EventArgs(
1173
            array(
1174 33
                'builder' => $builder,
1175 33
                'Order' => $Order,
1176
            ),
1177
            $request
1178
        );
1179 33
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_INITIALIZE, $event);
1180
1181 33
        $form = $builder->getForm();
1182 33
        $form->handleRequest($request);
1183
1184 33
        $errors = array();
1185 33
        if ($form->isSubmitted() && $form->isValid()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
1186
1187 32
            log_info('複数配送設定処理開始', array($Order->getId()));
1188
1189 32
            $data = $form['shipping_multiple'];
1190
1191
            // フォームの入力から、送り先ごとに商品の数量を集計する
1192 32
            $arrShipmentItemTemp = array();
1193 32
            foreach ($data as $mulitples) {
1194 32
                $ShipmentItem = $mulitples->getData();
1195 32
                foreach ($mulitples as $items) {
1196 32
                    foreach ($items as $item) {
1197 32
                        $cusAddId = $this->getCustomerAddressId($item['customer_address']->getData());
1198 32
                        $itemId = $ShipmentItem->getProductClass()->getId();
1199 32
                        $quantity = $item['quantity']->getData();
1200
1201 32
                        if (isset($arrShipmentItemTemp[$cusAddId]) && array_key_exists($itemId, $arrShipmentItemTemp[$cusAddId])) {
1202 10
                            $arrShipmentItemTemp[$cusAddId][$itemId] = $arrShipmentItemTemp[$cusAddId][$itemId] + $quantity;
1203
                        } else {
1204 32
                            $arrShipmentItemTemp[$cusAddId][$itemId] = $quantity;
1205
                        }
1206
                    }
1207
                }
1208
            }
1209
1210
            // フォームの入力から、商品ごとの数量を集計する
1211 32
            $itemQuantities = array();
1212 32
            foreach ($arrShipmentItemTemp as $FormItemByAddress) {
1213 32
                foreach ($FormItemByAddress as $itemId => $quantity) {
1214 32
                    if (array_key_exists($itemId, $itemQuantities)) {
1215 17
                        $itemQuantities[$itemId] = $itemQuantities[$itemId] + $quantity;
1216
                    } else {
1217 32
                        $itemQuantities[$itemId] = $quantity;
1218
                    }
1219
                }
1220
            }
1221
1222
            // 「Orderに含まれる商品ごとの数量」と「フォームに入力された商品ごとの数量」が一致しているかの確認
1223
            // 数量が異なっているならエラーを表示する
1224 32
            foreach ($ItemQuantitiesByClassId as $key => $value) {
1225 32
                if (array_key_exists($key, $itemQuantities)) {
1226 32
                    if ($itemQuantities[$key] != $value) {
1227 2
                        $errors[] = array('message' => $app->trans('shopping.multiple.quantity.diff'));
1228
1229
                        // 対象がなければエラー
1230 2
                        log_info('複数配送設定入力チェックエラー', array($Order->getId()));
1231 2
                        return $app->render('Shopping/shipping_multiple.twig', array(
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1232 2
                            'form' => $form->createView(),
1233 2
                            'shipmentItems' => $ShipmentItemsForFormBuilder,
1234 2
                            'compItemQuantities' => $ItemQuantitiesByClassId,
1235 32
                            'errors' => $errors,
1236
                        ));
1237
                    }
1238
                }
1239
            }
1240
1241
            // -- ここから先がお届け先を再生成する処理 --
1242
1243
            // お届け先情報をすべて削除
1244 30
            foreach ($Order->getShippings() as $Shipping) {
1245 30
                $Order->removeShipping($Shipping);
1246 30
                $app['orm.em']->remove($Shipping);
1247
            }
1248
1249
            // お届け先のリストを作成する
1250 30
            $ShippingList = array();
1251 30
            foreach ($data as $mulitples) {
1252 30
                $ShipmentItem = $mulitples->getData();
1253 30
                $ProductClass = $ShipmentItem->getProductClass();
1254 30
                $Delivery = $ShipmentItem->getShipping()->getDelivery();
1255 30
                $productTypeId = $ProductClass->getProductType()->getId();
1256
1257 30
                foreach ($mulitples as $items) {
1258 30
                    foreach ($items as $item) {
1259 30
                        $CustomerAddress = $this->getCustomerAddress($app, $item['customer_address']->getData());
1260 30
                        $cusAddId = $this->getCustomerAddressId($item['customer_address']->getData());
1261
1262 30
                        $Shipping = new Shipping();
1263
                        $Shipping
1264 30
                            ->setFromCustomerAddress($CustomerAddress)
1265 30
                            ->setDelivery($Delivery)
1266 30
                            ->setDelFlg(Constant::DISABLED)
1267 30
                            ->setOrder($Order);
1268
1269 30
                        $ShippingList[$cusAddId][$productTypeId] = $Shipping;
1270
                    }
1271
                }
1272
            }
1273
            // お届け先のリストを保存
1274 30
            foreach ($ShippingList as $ShippingListByAddress) {
1275 30
                foreach ($ShippingListByAddress as $Shipping) {
1276 30
                    $app['orm.em']->persist($Shipping);
1277
                }
1278
            }
1279
1280
            // お届け先に、配送商品の情報(ShipmentItem)を関連付ける
1281 30
            foreach ($data as $mulitples) {
1282 30
                $ShipmentItem = $mulitples->getData();
1283 30
                $ProductClass = $ShipmentItem->getProductClass();
1284 30
                $Product = $ShipmentItem->getProduct();
1285 30
                $productTypeId = $ProductClass->getProductType()->getId();
1286 30
                $productClassId = $ProductClass->getId();
1287
1288 30
                foreach ($mulitples as $items) {
1289 30
                    foreach ($items as $item) {
1290 30
                        $cusAddId = $this->getCustomerAddressId($item['customer_address']->getData());
1291
1292
                        // お届け先から商品の数量を取得
1293 30
                        $quantity = 0;
0 ignored issues
show
Unused Code introduced by
$quantity is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1294 30
                        if (isset($arrShipmentItemTemp[$cusAddId]) && array_key_exists($productClassId, $arrShipmentItemTemp[$cusAddId])) {
1295 30
                            $quantity = $arrShipmentItemTemp[$cusAddId][$productClassId];
1296 30
                            unset($arrShipmentItemTemp[$cusAddId][$productClassId]);
1297
                        } else {
1298
                            // この配送先には送る商品がないのでスキップ(通常ありえない)
1299 10
                            continue;
1300
                        }
1301
1302
                        // 関連付けるお届け先のインスタンスを取得
1303 30
                        $Shipping = $ShippingList[$cusAddId][$productTypeId];
1304
1305
                        // インスタンスを生成して保存
1306 30
                        $ShipmentItem = new ShipmentItem();
1307 30
                        $ShipmentItem->setShipping($Shipping)
1308 30
                            ->setOrder($Order)
1309 30
                            ->setProductClass($ProductClass)
1310 30
                            ->setProduct($Product)
1311 30
                            ->setProductName($Product->getName())
1312 30
                            ->setProductCode($ProductClass->getCode())
1313 30
                            ->setPrice($ProductClass->getPrice02())
1314 30
                            ->setQuantity($quantity);
1315
1316 30
                        $ClassCategory1 = $ProductClass->getClassCategory1();
1317 30
                        if (!is_null($ClassCategory1)) {
1318 30
                            $ShipmentItem->setClasscategoryName1($ClassCategory1->getName());
1319 30
                            $ShipmentItem->setClassName1($ClassCategory1->getClassName()->getName());
1320
                        }
1321 30
                        $ClassCategory2 = $ProductClass->getClassCategory2();
1322 30
                        if (!is_null($ClassCategory2)) {
1323 24
                            $ShipmentItem->setClasscategoryName2($ClassCategory2->getName());
1324 24
                            $ShipmentItem->setClassName2($ClassCategory2->getClassName()->getName());
1325
                        }
1326 30
                        $Shipping->addShipmentItem($ShipmentItem);
1327 30
                        $app['orm.em']->persist($ShipmentItem);
1328
                    }
1329
                }
1330
            }
1331
1332
            // 送料を計算(お届け先ごと)
1333 30
            foreach ($ShippingList as $data) {
1334
                // data is product type => shipping
1335 30
                foreach ($data as $Shipping) {
1336
                    // 配送料金の設定
1337 30
                    $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
1338 30
                    $Order->addShipping($Shipping);
1339
                }
1340
            }
1341
1342
            // 合計金額の再計算
1343 30
            $Order = $app['eccube.service.shopping']->getAmount($Order);
1344
1345
            // 配送先を更新
1346 30
            $app['orm.em']->flush();
1347
1348 30
            $event = new EventArgs(
1349
                array(
1350 30
                    'form' => $form,
1351 30
                    'Order' => $Order,
1352
                ),
1353
                $request
1354
            );
1355 30
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_COMPLETE, $event);
1356
1357 30
            log_info('複数配送設定処理完了', array($Order->getId()));
1358 30
            return $app->redirect($app->url('shopping'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1359
        }
1360
1361 5
        return $app->render('Shopping/shipping_multiple.twig', array(
1362 5
            'form' => $form->createView(),
1363 5
            'shipmentItems' => $ShipmentItemsForFormBuilder,
1364 5
            'compItemQuantities' => $ItemQuantitiesByClassId,
1365 5
            'errors' => $errors,
1366
        ));
1367
    }
1368
1369
    /**
1370
     * フォームの情報からお届け先のインデックスを返す
1371
     *
1372
     * @param Application $app
0 ignored issues
show
Bug introduced by
There is no parameter named $app. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1373
     * @param mixed $CustomerAddressData
1374
     * @return int
1375
     */
1376 32
    private function getCustomerAddressId($CustomerAddressData)
1377
    {
1378 32
        if ($CustomerAddressData 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...
1379 15
            return $CustomerAddressData->getId();
1380
        } else {
1381 17
            return $CustomerAddressData;
1382
        }
1383
    }
1384
1385
    /**
1386
     * フォームの情報からお届け先のインスタンスを返す
1387
     *
1388
     * @param Application $app
1389
     * @param mixed $CustomerAddressData
1390
     * @return CustomerAddress
1391
     */
1392 30
    private function getCustomerAddress(Application $app, $CustomerAddressData)
1393
    {
1394 30
        if ($CustomerAddressData 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...
1395 14
            return $CustomerAddressData;
1396
        } else {
1397 16
            $cusAddId = $CustomerAddressData;
1398 16
            $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey);
1399 16
            $customerAddresses = unserialize($customerAddresses);
1400
1401 16
            $CustomerAddress = $customerAddresses[$cusAddId];
1402 16
            $pref = $app['eccube.repository.master.pref']->find($CustomerAddress->getPref()->getId());
1403 16
            $CustomerAddress->setPref($pref);
1404
1405 16
            return $CustomerAddress;
1406
        }
1407
    }
1408
1409
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1410
     * 非会員用複数配送設定時の新規お届け先の設定
1411
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1412 10
    public function shippingMultipleEdit(Application $app, Request $request)
0 ignored issues
show
introduced by
Declare public methods first, then protected ones and finally private ones
Loading history...
1413
    {
1414
        // カートチェック
1415 10
        if (!$app['eccube.service.cart']->isLocked()) {
1416
            log_info('カートが存在しません');
1417
            // カートが存在しない、カートがロックされていない時はエラー
1418
            return $app->redirect($app->url('cart'));
1419
        }
1420
1421
        // 非会員用Customerを取得
1422 10
        $Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey);
1423 10
        $CustomerAddress = new CustomerAddress();
1424 10
        $CustomerAddress->setCustomer($Customer);
1425 10
        $Customer->addCustomerAddress($CustomerAddress);
1426
1427 10
        $builder = $app['form.factory']->createBuilder('shopping_shipping', $CustomerAddress);
1428
1429 10
        $event = new EventArgs(
1430
            array(
1431 10
                'builder' => $builder,
1432 10
                'Customer' => $Customer,
1433
            ),
1434
            $request
1435
        );
1436 10
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_EDIT_INITIALIZE, $event);
1437
1438 10
        $form = $builder->getForm();
1439
1440 10
        $form->handleRequest($request);
1441
1442 10
        if ($form->isSubmitted() && $form->isValid()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
1443
1444 10
            log_info('非会員お届け先追加処理開始');
1445
1446
            // 非会員用のセッションに追加
1447 10
            $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey);
1448 10
            $customerAddresses = unserialize($customerAddresses);
1449 10
            $customerAddresses[] = $CustomerAddress;
1450 10
            $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses));
1451
1452 10
            $event = new EventArgs(
1453
                array(
1454 10
                    'form' => $form,
1455 10
                    'CustomerAddresses' => $customerAddresses,
1456
                ),
1457
                $request
1458
            );
1459 10
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_EDIT_COMPLETE, $event);
1460
1461 10
            log_info('非会員お届け先追加処理完了');
1462
1463 10
            return $app->redirect($app->url('shopping_shipping_multiple'));
1464
        }
1465
1466 1
        return $app->render('Shopping/shipping_multiple_edit.twig', array(
1467 1
            'form' => $form->createView(),
1468
        ));
1469
    }
1470
1471
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1472
     * 購入エラー画面表示
1473
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1474 2
    public function shoppingError(Application $app, Request $request)
1475
    {
1476
1477 2
        $event = new EventArgs(
1478 2
            array(),
1479
            $request
1480
        );
1481 2
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_ERROR_COMPLETE, $event);
1482
1483 2
        if ($event->getResponse() !== null) {
1484
            return $event->getResponse();
1485
        }
1486
1487 2
        return $app->render('Shopping/shopping_error.twig');
1488
    }
1489
1490
    /**
1491
     * 非会員でのお客様情報変更時の入力チェック
1492
     *
1493
     * @param Application $app
1494
     * @param array $data リクエストパラメータ
1495
     * @return array
1496
     */
1497
    private function customerValidation(Application $app, array $data)
1498
    {
1499
        // 入力チェック
1500
        $errors = array();
1501
1502
        $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...
1503
            new Assert\NotBlank(),
1504
            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...
1505
            new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace'))
1506
        ));
1507
1508
        $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...
1509
            new Assert\NotBlank(),
1510
            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...
1511
            new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace'))
1512
        ));
1513
1514
        $errors[] = $app['validator']->validateValue($data['customer_company_name'], array(
1515
            new Assert\Length(array('max' => $app['config']['stext_len'])),
1516
        ));
1517
1518
        $errors[] = $app['validator']->validateValue($data['customer_tel01'], array(
1519
            new Assert\NotBlank(),
1520
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1521
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1522
        ));
1523
1524
        $errors[] = $app['validator']->validateValue($data['customer_tel02'], array(
1525
            new Assert\NotBlank(),
1526
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1527
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1528
        ));
1529
1530
        $errors[] = $app['validator']->validateValue($data['customer_tel03'], array(
1531
            new Assert\NotBlank(),
1532
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1533
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1534
        ));
1535
1536
        $errors[] = $app['validator']->validateValue($data['customer_zip01'], array(
1537
            new Assert\NotBlank(),
1538
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1539
            new Assert\Length(array('min' => $app['config']['zip01_len'], 'max' => $app['config']['zip01_len'])),
1540
        ));
1541
1542
        $errors[] = $app['validator']->validateValue($data['customer_zip02'], array(
1543
            new Assert\NotBlank(),
1544
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1545
            new Assert\Length(array('min' => $app['config']['zip02_len'], 'max' => $app['config']['zip02_len'])),
1546
        ));
1547
1548
        $errors[] = $app['validator']->validateValue($data['customer_addr01'], array(
1549
            new Assert\NotBlank(),
1550
            new Assert\Length(array('max' => $app['config']['address1_len'])),
1551
        ));
1552
1553
        $errors[] = $app['validator']->validateValue($data['customer_addr02'], array(
1554
            new Assert\NotBlank(),
1555
            new Assert\Length(array('max' => $app['config']['address2_len'])),
1556
        ));
1557
1558
        $errors[] = $app['validator']->validateValue($data['customer_email'], array(
1559
            new Assert\NotBlank(),
1560
            new Assert\Email(array('strict' => true)),
1561
        ));
1562
1563
        return $errors;
1564
    }
1565
}
1566