Failed Conditions
Push — master ( 9c9d2b...a2b736 )
by chihiro
43:30
created

ShoppingController::getCustomerAddress()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 2
dl 0
loc 16
ccs 10
cts 10
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
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 71
    public function index(Application $app, Request $request)
73
    {
74 71
        $cartService = $app['eccube.service.cart'];
75
76
        // カートチェック
77 71
        if (!$cartService->isLocked()) {
78 4
            log_info('カートが存在しません');
79
            // カートが存在しない、カートがロックされていない時はエラー
80 4
            return $app->redirect($app->url('cart'));
81
        }
82
83
        // カートチェック
84 67 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 66
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
92
93
        // 初回アクセス(受注情報がない)の場合は, 受注情報を作成
94 66
        if (is_null($Order)) {
95
            // 未ログインの場合, ログイン画面へリダイレクト.
96 66
            if (!$app->isGranted('IS_AUTHENTICATED_FULLY')) {
97
                // 非会員でも一度会員登録されていればショッピング画面へ遷移
98 30
                $Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey);
99
100 30
                if (is_null($Customer)) {
101
                    log_info('未ログインのためログイン画面にリダイレクト');
102 30
                    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 36
                $Customer = $app->user();
106
            }
107
108
            try {
109
                // 受注情報を作成
110 66
                $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 66
            $app['session']->remove($this->sessionOrderKey);
119 66
            $app['session']->remove($this->sessionMultipleKey);
120
        }
121
122
        // 受注関連情報を最新状態に更新
123 66
        $app['orm.em']->refresh($Order);
124
125
        // form作成
126 66
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
127
128 66
        $event = new EventArgs(
129
            array(
130 66
                'builder' => $builder,
131 66
                'Order' => $Order,
132
            ),
133
            $request
134
        );
135 66
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_INDEX_INITIALIZE, $event);
136
137 66
        $form = $builder->getForm();
138
139 66
        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 66
        if (!$app['session']->has($this->sessionMultipleKey)) {
150 66
            if (count($Order->getShippings()) > 1) {
151 5
                $app->addRequestError('shopping.multiple.delivery');
152
            }
153 66
            $app['session']->set($this->sessionMultipleKey, 'multiple');
154
        }
155
156 66
        return $app->render('Shopping/index.twig', array(
157 66
            'form' => $form->createView(),
158 66
            '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 4
    public function shippingEdit(Application $app, Request $request, $id)
689
    {
690
        // 配送先住所最大値判定
691 4
        $Customer = $app->user();
692 4 View Code Duplication
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
693 2
            $addressCurrNum = count($app->user()->getCustomerAddresses());
694 2
            $addressMax = $app['config']['deliv_addr_max'];
695 2
            if ($addressCurrNum >= $addressMax) {
696
                throw new NotFoundHttpException('配送先住所最大数エラー');
697
            }
698
        }
699
700
        // カートチェック
701 4
        if (!$app['eccube.service.cart']->isLocked()) {
702
            // カートが存在しない、カートがロックされていない時はエラー
703
            log_info('カートが存在しません');
704
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
705
        }
706
707 4
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
708 4
        if (!$Order) {
709
            log_info('購入処理中の受注情報がないため購入エラー');
710
            $app->addError('front.shopping.order.error');
711
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
712
        }
713
714 4
        $Shipping = $Order->findShipping($id);
715 4
        if (!$Shipping) {
716
            throw new NotFoundHttpException('設定されている配送先が存在しない');
717
        }
718 4
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
719 2
            $Shipping->clearCustomerAddress();
720
        }
721
722 4
        $CustomerAddress = new CustomerAddress();
723 4
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
724 2
            $CustomerAddress->setCustomer($Customer);
725
        } else {
726 2
            $CustomerAddress->setFromShipping($Shipping);
727
        }
728
729 4
        $builder = $app['form.factory']->createBuilder('shopping_shipping', $CustomerAddress);
730
731 4
        $event = new EventArgs(
732
            array(
733 4
                'builder' => $builder,
734 4
                'Order' => $Order,
735 4
                'Shipping' => $Shipping,
736 4
                'CustomerAddress' => $CustomerAddress,
737
            ),
738
            $request
739
        );
740 4
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_INITIALIZE, $event);
741
742 4
        $form = $builder->getForm();
743
744 4
        $form->handleRequest($request);
745
746 4
        if ($form->isSubmitted() && $form->isValid()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
747
748 3
            log_info('お届け先追加処理開始', array('id' => $Order->getId(), 'shipping' => $id));
749
750
            // 会員の場合、お届け先情報を新規登録
751 3
            $Shipping->setFromCustomerAddress($CustomerAddress);
752
753 3
            if ($Customer instanceof Customer) {
0 ignored issues
show
Bug introduced by
The class Eccube\Entity\Customer does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

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

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

2. Missing use statement

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

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

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

Loading history...
754 2
                $app['orm.em']->persist($CustomerAddress);
755 2
                log_info('新規お届け先登録', array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
756 2
                    'id' => $Order->getId(),
757 2
                    'shipping' => $id,
758 2
                    'customer address' => $CustomerAddress->getId()));
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 20.
Loading history...
759
            }
760
761
            // 配送料金の設定
762 3
            $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
763
764
            // 合計金額の再計算
765 3
            $app['eccube.service.shopping']->getAmount($Order);
766
767
            // 配送先を更新 
768 3
            $app['orm.em']->flush();
769
770 3
            $event = new EventArgs(
771
                array(
772 3
                    'form' => $form,
773 3
                    'Shipping' => $Shipping,
774 3
                    'CustomerAddress' => $CustomerAddress,
775
                ),
776
                $request
777
            );
778 3
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_EDIT_COMPLETE, $event);
779
780 3
            log_info('お届け先追加処理完了', array('id' => $Order->getId(), 'shipping' => $id));
781 3
            return $app->redirect($app->url('shopping'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
782
        }
783
784 3
        return $app->render('Shopping/shipping_edit.twig', array(
785 3
            'form' => $form->createView(),
786 3
            'shippingId' => $id,
787
        ));
788
    }
789
790
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
791
     * お客様情報の変更(非会員)
792
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
793
    public function customer(Application $app, Request $request)
794
    {
795
        if ($request->isXmlHttpRequest()) {
796
            try {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
797
798
                log_info('非会員お客様情報変更処理開始');
799
800
                $data = $request->request->all();
801
802
                // 入力チェック
803
                $errors = $this->customerValidation($app, $data);
804
805
                foreach ($errors as $error) {
806 View Code Duplication
                    if ($error->count() != 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
807
                        log_info('非会員お客様情報変更入力チェックエラー');
808
                        $response = new Response(json_encode('NG'), 400);
809
                        $response->headers->set('Content-Type', 'application/json');
810
                        return $response;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
811
                    }
812
                }
813
814
                $pref = $app['eccube.repository.master.pref']->findOneBy(array('name' => $data['customer_pref']));
815 View Code Duplication
                if (!$pref) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
816
                    log_info('非会員お客様情報変更入力チェックエラー');
817
                    $response = new Response(json_encode('NG'), 400);
818
                    $response->headers->set('Content-Type', 'application/json');
819
                    return $response;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
820
                }
821
822
                $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
823
                if (!$Order) {
824
                    log_info('カートが存在しません');
825
                    $app->addError('front.shopping.order.error');
826
                    return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
827
                }
828
829
                $Order
830
                    ->setName01($data['customer_name01'])
831
                    ->setName02($data['customer_name02'])
832
                    ->setCompanyName($data['customer_company_name'])
833
                    ->setTel01($data['customer_tel01'])
834
                    ->setTel02($data['customer_tel02'])
835
                    ->setTel03($data['customer_tel03'])
836
                    ->setZip01($data['customer_zip01'])
837
                    ->setZip02($data['customer_zip02'])
838
                    ->setZipCode($data['customer_zip01'].$data['customer_zip02'])
839
                    ->setPref($pref)
840
                    ->setAddr01($data['customer_addr01'])
841
                    ->setAddr02($data['customer_addr02'])
842
                    ->setEmail($data['customer_email']);
843
844
                // 配送先を更新
845
                $app['orm.em']->flush();
846
847
                // 受注関連情報を最新状態に更新
848
                $app['orm.em']->refresh($Order);
849
850
                $event = new EventArgs(
851
                    array(
852
                        'Order' => $Order,
853
                        'data' => $data,
854
                    ),
855
                    $request
856
                );
857
                $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_CUSTOMER_INITIALIZE, $event);
858
859
                log_info('非会員お客様情報変更処理完了', array($Order->getId()));
860
                $response = new Response(json_encode('OK'));
861
                $response->headers->set('Content-Type', 'application/json');
862
            } catch (\Exception $e) {
863
                log_error('予期しないエラー', array($e->getMessage()));
864
                $app['monolog']->error($e);
865
866
                $response = new Response(json_encode('NG'), 500);
867
                $response->headers->set('Content-Type', 'application/json');
868
            }
869
870
            return $response;
871
        }
872
    }
873
874
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
875
     * ログイン
876
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
877 4
    public function login(Application $app, Request $request)
878
    {
879 4
        if (!$app['eccube.service.cart']->isLocked()) {
880 3
            return $app->redirect($app->url('cart'));
881
        }
882
883 1
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
884
            return $app->redirect($app->url('shopping'));
885
        }
886
887
        /* @var $form \Symfony\Component\Form\FormInterface */
888 1
        $builder = $app['form.factory']->createNamedBuilder('', 'customer_login');
889
890 1 View Code Duplication
        if ($app->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
891
            $Customer = $app->user();
892
            if ($Customer) {
893
                $builder->get('login_email')->setData($Customer->getEmail());
894
            }
895
        }
896
897 1
        $event = new EventArgs(
898
            array(
899 1
                'builder' => $builder,
900
            ),
901
            $request
902
        );
903 1
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_LOGIN_INITIALIZE, $event);
904
905 1
        $form = $builder->getForm();
906
907 1
        return $app->render('Shopping/login.twig', array(
908 1
            'error' => $app['security.last_error']($request),
909 1
            'form' => $form->createView(),
910
        ));
911
    }
912
913
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
914
     * 非会員処理
915
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
916 35
    public function nonmember(Application $app, Request $request)
917
    {
918 35
        $cartService = $app['eccube.service.cart'];
919
920
        // カートチェック
921 35
        if (!$cartService->isLocked()) {
922
            // カートが存在しない、カートがロックされていない時はエラー
923 2
            log_info('カートが存在しません');
924 2
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
925
        }
926
927
        // ログイン済みの場合は, 購入画面へリダイレクト.
928 33
        if ($app->isGranted('ROLE_USER')) {
929 1
            return $app->redirect($app->url('shopping'));
930
        }
931
932
        // カートチェック
933 32 View Code Duplication
        if (count($cartService->getCart()->getCartItems()) <= 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
934
            // カートが存在しない時はエラー
935
            log_info('カートに商品が入っていないためショッピングカート画面にリダイレクト');
936
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
937
        }
938
939 32
        $builder = $app['form.factory']->createBuilder('nonmember');
940
941 32
        $event = new EventArgs(
942
            array(
943 32
                'builder' => $builder,
944
            ),
945
            $request
946
        );
947 32
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_NONMEMBER_INITIALIZE, $event);
948
949 32
        $form = $builder->getForm();
950
951 32
        $form->handleRequest($request);
952
953 32
        if ($form->isSubmitted() && $form->isValid()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
954
955 31
            log_info('非会員お客様情報登録開始');
956
957 31
            $data = $form->getData();
958 31
            $Customer = new Customer();
959
            $Customer
960 31
                ->setName01($data['name01'])
961 31
                ->setName02($data['name02'])
962 31
                ->setKana01($data['kana01'])
963 31
                ->setKana02($data['kana02'])
964 31
                ->setCompanyName($data['company_name'])
965 31
                ->setEmail($data['email'])
966 31
                ->setTel01($data['tel01'])
967 31
                ->setTel02($data['tel02'])
968 31
                ->setTel03($data['tel03'])
969 31
                ->setZip01($data['zip01'])
970 31
                ->setZip02($data['zip02'])
971 31
                ->setZipCode($data['zip01'].$data['zip02'])
972 31
                ->setPref($data['pref'])
973 31
                ->setAddr01($data['addr01'])
974 31
                ->setAddr02($data['addr02']);
975
976
            // 非会員複数配送用
977 31
            $CustomerAddress = new CustomerAddress();
978
            $CustomerAddress
979 31
                ->setCustomer($Customer)
980 31
                ->setName01($data['name01'])
981 31
                ->setName02($data['name02'])
982 31
                ->setKana01($data['kana01'])
983 31
                ->setKana02($data['kana02'])
984 31
                ->setCompanyName($data['company_name'])
985 31
                ->setTel01($data['tel01'])
986 31
                ->setTel02($data['tel02'])
987 31
                ->setTel03($data['tel03'])
988 31
                ->setZip01($data['zip01'])
989 31
                ->setZip02($data['zip02'])
990 31
                ->setZipCode($data['zip01'].$data['zip02'])
991 31
                ->setPref($data['pref'])
992 31
                ->setAddr01($data['addr01'])
993 31
                ->setAddr02($data['addr02'])
994 31
                ->setDelFlg(Constant::DISABLED);
995 31
            $Customer->addCustomerAddress($CustomerAddress);
996
997
            // 受注情報を取得
998 31
            $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
999
1000
            // 初回アクセス(受注データがない)の場合は, 受注情報を作成
1001 31
            if (is_null($Order)) {
1002
                // 受注情報を作成
1003
                try {
1004
                    // 受注情報を作成
1005 31
                    $Order = $app['eccube.service.shopping']->createOrder($Customer);
1006
                } catch (CartException $e) {
1007
                    $app->addRequestError($e->getMessage());
1008
                    return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1009
                }
1010
            }
1011
1012
            // 非会員用セッションを作成
1013 31
            $nonMember = array();
1014 31
            $nonMember['customer'] = $Customer;
1015 31
            $nonMember['pref'] = $Customer->getPref()->getId();
1016 31
            $app['session']->set($this->sessionKey, $nonMember);
1017
1018 31
            $customerAddresses = array();
1019 31
            $customerAddresses[] = $CustomerAddress;
1020 31
            $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses));
1021
1022 31
            $event = new EventArgs(
1023
                array(
1024 31
                    'form' => $form,
1025 31
                    'Order' => $Order,
1026
                ),
1027
                $request
1028
            );
1029 31
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_NONMEMBER_COMPLETE, $event);
1030
1031 31
            if ($event->getResponse() !== null) {
1032
                return $event->getResponse();
1033
            }
1034
1035 31
            log_info('非会員お客様情報登録完了', array($Order->getId()));
1036
1037 31
            return $app->redirect($app->url('shopping'));
1038
        }
1039
1040 1
        return $app->render('Shopping/nonmember.twig', array(
1041 1
            'form' => $form->createView(),
1042
        ));
1043
    }
1044
1045
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1046
     * 複数配送処理がクリックされた場合の処理
1047
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1048 View Code Duplication
    public function shippingMultipleChange(Application $app, Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
1049
    {
1050
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
1051
        if (!$Order) {
1052
            $app->addError('front.shopping.order.error');
1053
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1054
        }
1055
1056
        if ('POST' !== $request->getMethod()) {
1057
            return $app->redirect($app->url('shopping'));
1058
        }
1059
1060
        $builder = $app['eccube.service.shopping']->getShippingFormBuilder($Order);
1061
1062
        $event = new EventArgs(
1063
            array(
1064
                'builder' => $builder,
1065
                'Order' => $Order,
1066
            ),
1067
            $request
1068
        );
1069
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_CHANGE_INITIALIZE, $event);
1070
1071
        $form = $builder->getForm();
1072
1073
        $form->handleRequest($request);
1074
1075
        if ($form->isSubmitted() && $form->isValid()) {
1076
            $data = $form->getData();
1077
            $message = $data['message'];
1078
            $Order->setMessage($message);
1079
            // 受注情報を更新
1080
            $app['orm.em']->flush();
1081
1082
            // 複数配送設定へリダイレクト
1083
            return $app->redirect($app->url('shopping_shipping_multiple'));
1084
        }
1085
1086
        return $app->render('Shopping/index.twig', array(
1087
            'form' => $form->createView(),
1088
            'Order' => $Order,
1089
        ));
1090
    }
1091
1092
1093
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1094
     * 複数配送処理
1095
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1096 37
    public function shippingMultiple(Application $app, Request $request)
1097
    {
1098 37
        $cartService = $app['eccube.service.cart'];
1099
1100
        // カートチェック
1101 37
        if (!$cartService->isLocked()) {
1102
            // カートが存在しない、カートがロックされていない時はエラー
1103 4
            log_info('カートが存在しません');
1104 4
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1105
        }
1106
1107
        // カートチェック
1108 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...
1109
            // カートが存在しない時はエラー
1110
            log_info('カートに商品が入っていないためショッピングカート画面にリダイレクト');
1111
            return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1112
        }
1113
1114
        /** @var \Eccube\Entity\Order $Order */
1115 33
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
1116 33
        if (!$Order) {
1117
            log_info('購入処理中の受注情報がないため購入エラー');
1118
            $app->addError('front.shopping.order.error');
1119
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1120
        }
1121
1122
        // 処理しやすいようにすべてのShippingItemをまとめる
1123 33
        $ShipmentItems = array();
1124 33
        foreach ($Order->getShippings() as $Shipping) {
1125 33
            foreach ($Shipping->getShipmentItems() as $ShipmentItem) {
1126 33
                $ShipmentItems[] = $ShipmentItem;
1127
            }
1128
        }
1129
1130
        // Orderに含まれる商品ごとの数量を求める
1131 33
        $ItemQuantitiesByClassId = array();
1132 33
        foreach ($ShipmentItems as $item) {
1133 33
            $itemId = $item->getProductClass()->getId();
1134 33
            $quantity = $item->getQuantity();
1135 33
            if (array_key_exists($itemId, $ItemQuantitiesByClassId)) {
1136
                $ItemQuantitiesByClassId[$itemId] += $quantity;
1137
            } else {
1138 33
                $ItemQuantitiesByClassId[$itemId] = $quantity;
1139
            }
1140
        }
1141
1142
        // FormBuilder用に商品ごとにShippingItemをまとめる
1143 33
        $ShipmentItemsForFormBuilder = array();
1144 33
        $tmpAddedClassIds = array();
1145 33
        foreach ($ShipmentItems as $item) {
1146 33
            $itemId = $item->getProductClass()->getId();
1147 33
            if (!in_array($itemId, $tmpAddedClassIds)) {
1148 33
                $ShipmentItemsForFormBuilder[] = $item;
1149 33
                $tmpAddedClassIds[] = $itemId;
1150
            }
1151
        }
1152
1153
        // Form生成
1154 33
        $builder = $app->form();
1155
        $builder
1156 33
            ->add('shipping_multiple', 'collection', array(
1157 33
                'type' => 'shipping_multiple',
1158 33
                'data' => $ShipmentItemsForFormBuilder,
1159
                'allow_add' => true,
1160
                'allow_delete' => true,
1161
            ));
1162
        // Event
1163 33
        $event = new EventArgs(
1164
            array(
1165 33
                'builder' => $builder,
1166 33
                'Order' => $Order,
1167
            ),
1168
            $request
1169
        );
1170 33
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_INITIALIZE, $event);
1171
1172 33
        $form = $builder->getForm();
1173 33
        $form->handleRequest($request);
1174
1175 33
        $errors = array();
1176 33
        if ($form->isSubmitted() && $form->isValid()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
1177
1178 32
            log_info('複数配送設定処理開始', array($Order->getId()));
1179
1180 32
            $data = $form['shipping_multiple'];
1181
1182
            // フォームの入力から、送り先ごとに商品の数量を集計する
1183 32
            $arrShipmentItemTemp = array();
1184 32
            foreach ($data as $mulitples) {
1185 32
                $ShipmentItem = $mulitples->getData();
1186 32
                foreach ($mulitples as $items) {
1187 32
                    foreach ($items as $item) {
1188 32
                        $cusAddId = $this->getCustomerAddressId($item['customer_address']->getData());
1189 32
                        $itemId = $ShipmentItem->getProductClass()->getId();
1190 32
                        $quantity = $item['quantity']->getData();
1191
1192 32
                        if (isset($arrShipmentItemTemp[$cusAddId]) && array_key_exists($itemId, $arrShipmentItemTemp[$cusAddId])) {
1193 10
                            $arrShipmentItemTemp[$cusAddId][$itemId] = $arrShipmentItemTemp[$cusAddId][$itemId] + $quantity;
1194
                        } else {
1195 32
                            $arrShipmentItemTemp[$cusAddId][$itemId] = $quantity;
1196
                        }
1197
                    }
1198
                }
1199
            }
1200
1201
            // フォームの入力から、商品ごとの数量を集計する
1202 32
            $itemQuantities = array();
1203 32
            foreach ($arrShipmentItemTemp as $FormItemByAddress) {
1204 32
                foreach ($FormItemByAddress as $itemId => $quantity) {
1205 32
                    if (array_key_exists($itemId, $itemQuantities)) {
1206 17
                        $itemQuantities[$itemId] = $itemQuantities[$itemId] + $quantity;
1207
                    } else {
1208 32
                        $itemQuantities[$itemId] = $quantity;
1209
                    }
1210
                }
1211
            }
1212
1213
            // 「Orderに含まれる商品ごとの数量」と「フォームに入力された商品ごとの数量」が一致しているかの確認
1214
            // 数量が異なっているならエラーを表示する
1215 32
            foreach ($ItemQuantitiesByClassId as $key => $value) {
1216 32
                if (array_key_exists($key, $itemQuantities)) {
1217 32
                    if ($itemQuantities[$key] != $value) {
1218 2
                        $errors[] = array('message' => $app->trans('shopping.multiple.quantity.diff'));
1219
1220
                        // 対象がなければエラー
1221 2
                        log_info('複数配送設定入力チェックエラー', array($Order->getId()));
1222 2
                        return $app->render('Shopping/shipping_multiple.twig', array(
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1223 2
                            'form' => $form->createView(),
1224 2
                            'shipmentItems' => $ShipmentItemsForFormBuilder,
1225 2
                            'compItemQuantities' => $ItemQuantitiesByClassId,
1226 32
                            'errors' => $errors,
1227
                        ));
1228
                    }
1229
                }
1230
            }
1231
1232
            // -- ここから先がお届け先を再生成する処理 --
1233
1234
            // お届け先情報をすべて削除
1235 30
            foreach ($Order->getShippings() as $Shipping) {
1236 30
                $Order->removeShipping($Shipping);
1237 30
                $app['orm.em']->remove($Shipping);
1238
            }
1239
1240
            // お届け先のリストを作成する
1241 30
            $ShippingList = array();
1242 30
            foreach ($data as $mulitples) {
1243 30
                $ShipmentItem = $mulitples->getData();
1244 30
                $ProductClass = $ShipmentItem->getProductClass();
1245 30
                $Delivery = $ShipmentItem->getShipping()->getDelivery();
1246 30
                $productTypeId = $ProductClass->getProductType()->getId();
1247
1248 30
                foreach ($mulitples as $items) {
1249 30
                    foreach ($items as $item) {
1250 30
                        $CustomerAddress = $this->getCustomerAddress($app, $item['customer_address']->getData());
1251 30
                        $cusAddId = $this->getCustomerAddressId($item['customer_address']->getData());
1252
1253 30
                        $Shipping = new Shipping();
1254
                        $Shipping
1255 30
                            ->setFromCustomerAddress($CustomerAddress)
1256 30
                            ->setDelivery($Delivery)
1257 30
                            ->setDelFlg(Constant::DISABLED)
1258 30
                            ->setOrder($Order);
1259
1260 30
                        $ShippingList[$cusAddId][$productTypeId] = $Shipping;
1261
                    }
1262
                }
1263
            }
1264
            // お届け先のリストを保存
1265 30
            foreach ($ShippingList as $ShippingListByAddress) {
1266 30
                foreach ($ShippingListByAddress as $Shipping) {
1267 30
                    $app['orm.em']->persist($Shipping);
1268
                }
1269
            }
1270
1271
            // お届け先に、配送商品の情報(ShipmentItem)を関連付ける
1272 30
            foreach ($data as $mulitples) {
1273 30
                $ShipmentItem = $mulitples->getData();
1274 30
                $ProductClass = $ShipmentItem->getProductClass();
1275 30
                $Product = $ShipmentItem->getProduct();
1276 30
                $productTypeId = $ProductClass->getProductType()->getId();
1277 30
                $productClassId = $ProductClass->getId();
1278
1279 30
                foreach ($mulitples as $items) {
1280 30
                    foreach ($items as $item) {
1281 30
                        $cusAddId = $this->getCustomerAddressId($item['customer_address']->getData());
1282
1283
                        // お届け先から商品の数量を取得
1284 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...
1285 30
                        if (isset($arrShipmentItemTemp[$cusAddId]) && array_key_exists($productClassId, $arrShipmentItemTemp[$cusAddId])) {
1286 30
                            $quantity = $arrShipmentItemTemp[$cusAddId][$productClassId];
1287 30
                            unset($arrShipmentItemTemp[$cusAddId][$productClassId]);
1288
                        } else {
1289
                            // この配送先には送る商品がないのでスキップ(通常ありえない)
1290 10
                            continue;
1291
                        }
1292
1293
                        // 関連付けるお届け先のインスタンスを取得
1294 30
                        $Shipping = $ShippingList[$cusAddId][$productTypeId];
1295
1296
                        // インスタンスを生成して保存
1297 30
                        $ShipmentItem = new ShipmentItem();
1298 30
                        $ShipmentItem->setShipping($Shipping)
1299 30
                            ->setOrder($Order)
1300 30
                            ->setProductClass($ProductClass)
1301 30
                            ->setProduct($Product)
1302 30
                            ->setProductName($Product->getName())
1303 30
                            ->setProductCode($ProductClass->getCode())
1304 30
                            ->setPrice($ProductClass->getPrice02())
1305 30
                            ->setQuantity($quantity);
1306
1307 30
                        $ClassCategory1 = $ProductClass->getClassCategory1();
1308 30
                        if (!is_null($ClassCategory1)) {
1309 30
                            $ShipmentItem->setClasscategoryName1($ClassCategory1->getName());
1310 30
                            $ShipmentItem->setClassName1($ClassCategory1->getClassName()->getName());
1311
                        }
1312 30
                        $ClassCategory2 = $ProductClass->getClassCategory2();
1313 30
                        if (!is_null($ClassCategory2)) {
1314 25
                            $ShipmentItem->setClasscategoryName2($ClassCategory2->getName());
1315 25
                            $ShipmentItem->setClassName2($ClassCategory2->getClassName()->getName());
1316
                        }
1317 30
                        $Shipping->addShipmentItem($ShipmentItem);
1318 30
                        $app['orm.em']->persist($ShipmentItem);
1319
                    }
1320
                }
1321
            }
1322
1323
            // 送料を計算(お届け先ごと)
1324 30
            foreach ($ShippingList as $data) {
1325
                // data is product type => shipping
1326 30
                foreach ($data as $Shipping) {
1327
                    // 配送料金の設定
1328 30
                    $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
1329 30
                    $Order->addShipping($Shipping);
1330
                }
1331
            }
1332
1333
            // 合計金額の再計算
1334 30
            $Order = $app['eccube.service.shopping']->getAmount($Order);
1335
1336
            // 配送先を更新
1337 30
            $app['orm.em']->flush();
1338
1339 30
            $event = new EventArgs(
1340
                array(
1341 30
                    'form' => $form,
1342 30
                    'Order' => $Order,
1343
                ),
1344
                $request
1345
            );
1346 30
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_COMPLETE, $event);
1347
1348 30
            log_info('複数配送設定処理完了', array($Order->getId()));
1349 30
            return $app->redirect($app->url('shopping'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1350
        }
1351
1352 5
        return $app->render('Shopping/shipping_multiple.twig', array(
1353 5
            'form' => $form->createView(),
1354 5
            'shipmentItems' => $ShipmentItemsForFormBuilder,
1355 5
            'compItemQuantities' => $ItemQuantitiesByClassId,
1356 5
            'errors' => $errors,
1357
        ));
1358
    }
1359
1360
    /**
1361
     * フォームの情報からお届け先のインデックスを返す
1362
     *
1363
     * @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...
1364
     * @param mixed $CustomerAddressData
1365
     * @return int
1366
     */
1367 32
    private function getCustomerAddressId($CustomerAddressData)
1368
    {
1369 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...
1370 15
            return $CustomerAddressData->getId();
1371
        } else {
1372 17
            return $CustomerAddressData;
1373
        }
1374
    }
1375
1376
    /**
1377
     * フォームの情報からお届け先のインスタンスを返す
1378
     *
1379
     * @param Application $app
1380
     * @param mixed $CustomerAddressData
1381
     * @return CustomerAddress
1382
     */
1383 30
    private function getCustomerAddress(Application $app, $CustomerAddressData)
1384
    {
1385 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...
1386 14
            return $CustomerAddressData;
1387
        } else {
1388 16
            $cusAddId = $CustomerAddressData;
1389 16
            $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey);
1390 16
            $customerAddresses = unserialize($customerAddresses);
1391
1392 16
            $CustomerAddress = $customerAddresses[$cusAddId];
1393 16
            $pref = $app['eccube.repository.master.pref']->find($CustomerAddress->getPref()->getId());
1394 16
            $CustomerAddress->setPref($pref);
1395
1396 16
            return $CustomerAddress;
1397
        }
1398
    }
1399
1400
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1401
     * 非会員用複数配送設定時の新規お届け先の設定
1402
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1403 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...
1404
    {
1405
        // カートチェック
1406 10
        if (!$app['eccube.service.cart']->isLocked()) {
1407
            log_info('カートが存在しません');
1408
            // カートが存在しない、カートがロックされていない時はエラー
1409
            return $app->redirect($app->url('cart'));
1410
        }
1411
1412
        // 非会員用Customerを取得
1413 10
        $Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey);
1414 10
        $CustomerAddress = new CustomerAddress();
1415 10
        $CustomerAddress->setCustomer($Customer);
1416 10
        $Customer->addCustomerAddress($CustomerAddress);
1417
1418 10
        $builder = $app['form.factory']->createBuilder('shopping_shipping', $CustomerAddress);
1419
1420 10
        $event = new EventArgs(
1421
            array(
1422 10
                'builder' => $builder,
1423 10
                'Customer' => $Customer,
1424
            ),
1425
            $request
1426
        );
1427 10
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_EDIT_INITIALIZE, $event);
1428
1429 10
        $form = $builder->getForm();
1430
1431 10
        $form->handleRequest($request);
1432
1433 10
        if ($form->isSubmitted() && $form->isValid()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
1434
1435 10
            log_info('非会員お届け先追加処理開始');
1436
1437
            // 非会員用のセッションに追加
1438 10
            $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey);
1439 10
            $customerAddresses = unserialize($customerAddresses);
1440 10
            $customerAddresses[] = $CustomerAddress;
1441 10
            $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses));
1442
1443 10
            $event = new EventArgs(
1444
                array(
1445 10
                    'form' => $form,
1446 10
                    'CustomerAddresses' => $customerAddresses,
1447
                ),
1448
                $request
1449
            );
1450 10
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_MULTIPLE_EDIT_COMPLETE, $event);
1451
1452 10
            log_info('非会員お届け先追加処理完了');
1453
1454 10
            return $app->redirect($app->url('shopping_shipping_multiple'));
1455
        }
1456
1457 1
        return $app->render('Shopping/shipping_multiple_edit.twig', array(
1458 1
            'form' => $form->createView(),
1459
        ));
1460
    }
1461
1462
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1463
     * 購入エラー画面表示
1464
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1465 2
    public function shoppingError(Application $app, Request $request)
1466
    {
1467
1468 2
        $event = new EventArgs(
1469 2
            array(),
1470
            $request
1471
        );
1472 2
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_SHIPPING_ERROR_COMPLETE, $event);
1473
1474 2
        if ($event->getResponse() !== null) {
1475
            return $event->getResponse();
1476
        }
1477
1478 2
        return $app->render('Shopping/shopping_error.twig');
1479
    }
1480
1481
    /**
1482
     * 非会員でのお客様情報変更時の入力チェック
1483
     *
1484
     * @param Application $app
1485
     * @param array $data リクエストパラメータ
1486
     * @return array
1487
     */
1488
    private function customerValidation(Application $app, array $data)
1489
    {
1490
        // 入力チェック
1491
        $errors = array();
1492
1493
        $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...
1494
            new Assert\NotBlank(),
1495
            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...
1496
            new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace'))
1497
        ));
1498
1499
        $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...
1500
            new Assert\NotBlank(),
1501
            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...
1502
            new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace'))
1503
        ));
1504
1505
        $errors[] = $app['validator']->validateValue($data['customer_company_name'], array(
1506
            new Assert\Length(array('max' => $app['config']['stext_len'])),
1507
        ));
1508
1509
        $errors[] = $app['validator']->validateValue($data['customer_tel01'], array(
1510
            new Assert\NotBlank(),
1511
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1512
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1513
        ));
1514
1515
        $errors[] = $app['validator']->validateValue($data['customer_tel02'], array(
1516
            new Assert\NotBlank(),
1517
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1518
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1519
        ));
1520
1521
        $errors[] = $app['validator']->validateValue($data['customer_tel03'], array(
1522
            new Assert\NotBlank(),
1523
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1524
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1525
        ));
1526
1527
        $errors[] = $app['validator']->validateValue($data['customer_zip01'], array(
1528
            new Assert\NotBlank(),
1529
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1530
            new Assert\Length(array('min' => $app['config']['zip01_len'], 'max' => $app['config']['zip01_len'])),
1531
        ));
1532
1533
        $errors[] = $app['validator']->validateValue($data['customer_zip02'], array(
1534
            new Assert\NotBlank(),
1535
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1536
            new Assert\Length(array('min' => $app['config']['zip02_len'], 'max' => $app['config']['zip02_len'])),
1537
        ));
1538
1539
        $errors[] = $app['validator']->validateValue($data['customer_addr01'], array(
1540
            new Assert\NotBlank(),
1541
            new Assert\Length(array('max' => $app['config']['address1_len'])),
1542
        ));
1543
1544
        $errors[] = $app['validator']->validateValue($data['customer_addr02'], array(
1545
            new Assert\NotBlank(),
1546
            new Assert\Length(array('max' => $app['config']['address2_len'])),
1547
        ));
1548
1549
        $errors[] = $app['validator']->validateValue($data['customer_email'], array(
1550
            new Assert\NotBlank(),
1551
            new Assert\Email(array('strict' => true)),
1552
        ));
1553
1554
        return $errors;
1555
    }
1556
}
1557