Failed Conditions
Pull Request — 3.0.9-dev (#1439)
by k-yamamura
57:50 queued 28:34
created

ShoppingController::shippingEdit()   C

Complexity

Conditions 11
Paths 31

Size

Total Lines 65
Code Lines 36

Duplication

Lines 7
Ratio 10.77 %

Code Coverage

Tests 7
CRAP Score 11

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 7
loc 65
ccs 7
cts 7
cp 1
rs 5.9999
cc 11
eloc 36
nc 31
nop 3
crap 11

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
25
namespace Eccube\Controller;
26
27
use Eccube\Application;
28
use Eccube\Common\Constant;
29
use Eccube\Entity\Customer;
30
use Eccube\Entity\CustomerAddress;
31
use Eccube\Entity\MailHistory;
32
use Eccube\Entity\ShipmentItem;
33
use Eccube\Entity\Shipping;
34
use Eccube\Exception\CartException;
35
use Symfony\Component\HttpFoundation\Request;
36
use Symfony\Component\HttpFoundation\Response;
37
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
38
use Symfony\Component\Validator\Constraints as Assert;
39
40
class ShoppingController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
41
{
42
43
    /**
44
     * @var string 非会員用セッションキー
45
     */
46
    private $sessionKey = 'eccube.front.shopping.nonmember';
47
48
    /**
49
     * @var string 非会員用セッションキー
50
     */
51
    private $sessionCustomerAddressKey = 'eccube.front.shopping.nonmember.customeraddress';
52
53
    /**
54
     * @var string 複数配送警告メッセージ
55
     */
56
    private $sessionMultipleKey = 'eccube.front.shopping.multiple';
57
58
    /**
59
     * @var string 受注IDキー
60
     */
61
    private $sessionOrderKey = 'eccube.front.shopping.order.id';
62
63
    /**
64
     * 購入画面表示
65
     *
66
     * @param Application $app
67
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
68
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
69
     */
70 19
    public function index(Application $app, Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
71
    {
72
        $cartService = $app['eccube.service.cart'];
73
74
        // カートチェック
75
        if (!$cartService->isLocked()) {
76
            // カートが存在しない、カートがロックされていない時はエラー
77
            return $app->redirect($app->url('cart'));
78
        }
79
80
        // カートチェック
81
        if (count($cartService->getCart()->getCartItems()) <= 0) {
82
            // カートが存在しない時はエラー
83
            return $app->redirect($app->url('cart'));
84
        }
85
86
        // 登録済みの受注情報を取得
87
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
88
89
        // 初回アクセス(受注情報がない)の場合は, 受注情報を作成
90
        if (is_null($Order)) {
91
            // 未ログインの場合, ログイン画面へリダイレクト.
92
            if (!$app->isGranted('IS_AUTHENTICATED_FULLY')) {
93
                // 非会員でも一度会員登録されていればショッピング画面へ遷移
94
                $Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey);
95
96
                if (is_null($Customer)) {
97
                    return $app->redirect($app->url('shopping_login'));
98
                }
99
            } else {
100
                $Customer = $app->user();
101 7
            }
102
103
            try {
104
                // 受注情報を作成
105
                $Order = $app['eccube.service.shopping']->createOrder($Customer);
106
            } catch (CartException $e) {
107
                $app->addRequestError($e->getMessage());
108
                return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
109 7
            }
110
111
            // セッション情報を削除
112
            $app['session']->remove($this->sessionOrderKey);
113
            $app['session']->remove($this->sessionMultipleKey);
114
        } else {
115
            // 計算処理
116
            $Order = $app['eccube.service.shopping']->getAmount($Order);
117 7
        }
118
119
        // 受注関連情報を最新状態に更新
120
        $app['orm.em']->refresh($Order);
121
122
        // form作成
123
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
124
125
        // 複数配送の場合、エラーメッセージを一度だけ表示
126
        if (!$app['session']->has($this->sessionMultipleKey)) {
127
            if (count($Order->getShippings()) > 1) {
128
                $app->addRequestError('shopping.multiple.delivery');
129
            }
130
            $app['session']->set($this->sessionMultipleKey, 'multiple');
131
        }
132
133 7
        return $app->render('Shopping/index.twig', array(
134 7
            'form' => $form->createView(),
135
            'Order' => $Order,
136
        ));
137 19
    }
138
139
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
140
     * 購入処理
141
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
142 2
    public function confirm(Application $app, Request $request)
143
    {
144
        $cartService = $app['eccube.service.cart'];
145
146
        // カートチェック
147
        if (!$cartService->isLocked()) {
148
            // カートが存在しない、カートがロックされていない時はエラー
149
            return $app->redirect($app->url('cart'));
150
        }
151
152
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
153 2
        if (!$Order) {
154
            $app->addError('front.shopping.order.error');
155
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
156
        }
157
158
        if ('POST' !== $request->getMethod()) {
159
            return $app->redirect($app->url('cart'));
160
        }
161
162
        // form作成
163
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
164
        $form->handleRequest($request);
165
166
        if ($form->isSubmitted() && $form->isValid()) {
167
            $data = $form->getData();
168
169
            // トランザクション制御
170
            $em = $app['orm.em'];
171
            $em->getConnection()->beginTransaction();
172
            try {
173
                // 商品公開ステータスチェック、商品制限数チェック、在庫チェック
174
                $check = $app['eccube.service.shopping']->isOrderProduct($em, $Order);
175 2
                if (!$check) {
176
                    $em->getConnection()->rollback();
177
178
                    $app->addError('front.shopping.stock.error');
179
                    return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
180
                }
181
182
                // 受注情報、配送情報を更新
183
                $app['eccube.service.shopping']->setOrderUpdate($Order, $data);
184
                // 在庫情報を更新
185
                $app['eccube.service.shopping']->setStockUpdate($em, $Order);
186
187
                if ($app->isGranted('ROLE_USER')) {
188
                    // 会員の場合、購入金額を更新
189
                    $app['eccube.service.shopping']->setCustomerUpdate($Order, $app->user());
190
                }
191
192
                $em->flush();
193
                $em->getConnection()->commit();
194
195
            } catch (\Exception $e) {
196
                $em->getConnection()->rollback();
197
198
                $app->log($e);
199
200
                $app->addError('front.shopping.system.error');
201
                return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
202 2
            }
203
204
            // カート削除
205
            $app['eccube.service.cart']->clear()->save();
206
207
            // メール送信
208
            $app['eccube.service.mail']->sendOrderMail($Order);
209
210
            // 受注IDをセッションにセット
211
            $app['session']->set($this->sessionOrderKey, $Order->getId());
212
213
            // 送信履歴を保存.
214
            $MailTemplate = $app['eccube.repository.mail_template']->find(1);
215
216 2
            $body = $app->renderView($MailTemplate->getFileName(), array(
217 2
                'header' => $MailTemplate->getHeader(),
218 2
                'footer' => $MailTemplate->getFooter(),
219
                'Order' => $Order,
220
            ));
221
222
            $MailHistory = new MailHistory();
223
            $MailHistory
224
                ->setSubject('[' . $app['eccube.repository.base_info']->get()->getShopName() . '] ' . $MailTemplate->getSubject())
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
225 2
                ->setMailBody($body)
226 2
                ->setMailTemplate($MailTemplate)
227
                ->setSendDate(new \DateTime())
228
                ->setOrder($Order);
229
            $app['orm.em']->persist($MailHistory);
230
            $app['orm.em']->flush($MailHistory);
231
232
233
            // 完了画面表示
234
            return $app->redirect($app->url('shopping_complete'));
235
        }
236
237
        return $app->render('Shopping/index.twig', array(
238
            'form' => $form->createView(),
239
            'Order' => $Order,
240
        ));
241 2
    }
242
243
244
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
245
     * 購入完了画面表示
246
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
247 1
    public function complete(Application $app)
248
    {
249
        // 受注IDを取得
250
        $orderId = $app['session']->get($this->sessionOrderKey);
251
252
        // 受注IDセッションを削除
253
        $app['session']->remove($this->sessionOrderKey);
254
255 1
        return $app->render('Shopping/complete.twig', array(
256
            'orderId' => $orderId,
257
        ));
258 1
    }
259
260
261
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
262
     * 配送業者選択処理
263
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
264 3
    public function delivery(Application $app, Request $request)
265
    {
266
        // カートチェック
267
        if (!$app['eccube.service.cart']->isLocked()) {
268
            // カートが存在しない、カートがロックされていない時はエラー
269
            return $app->redirect($app->url('cart'));
270
        }
271
272
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
273 3
        if (!$Order) {
274
            $app->addError('front.shopping.order.error');
275
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
276
        }
277
278
        if ('POST' !== $request->getMethod()) {
279
            return $app->redirect($app->url('shopping'));
280
        }
281
282
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
283
        $form->handleRequest($request);
284
285
        if ($form->isSubmitted() && $form->isValid()) {
286
            $data = $form->getData();
287
288
            $shippings = $data['shippings'];
289
290
            $productDeliveryFeeTotal = 0;
291
            $BaseInfo = $app['eccube.repository.base_info']->get();
292
293
            foreach ($shippings as $Shipping) {
294
                $Delivery = $Shipping->getDelivery();
295
296
                if ($Delivery) {
297
                    $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...
298
                        'Delivery' => $Delivery,
299
                        'Pref' => $Shipping->getPref()
300
                    ));
301
302
                    // 商品ごとの配送料合計
303
                    if (!is_null($BaseInfo->getOptionProductDeliveryFee())) {
304
                        $productDeliveryFeeTotal += $app['eccube.service.shopping']->getProductDeliveryFee($Shipping);
305
                    }
306
307
                    $Shipping->setDeliveryFee($deliveryFee);
308
                    $Shipping->setShippingDeliveryFee($deliveryFee->getFee() + $productDeliveryFeeTotal);
309
                    $Shipping->setShippingDeliveryName($Delivery->getName());
310
                }
311
            }
312
313
            // 支払い情報をセット
314
            $payment = $data['payment'];
315
            $message = $data['message'];
316
317
            $Order->setPayment($payment);
318
            $Order->setPaymentMethod($payment->getMethod());
319
            $Order->setMessage($message);
320
            $Order->setCharge($payment->getCharge());
321
322
            $Order->setDeliveryFeeTotal($app['eccube.service.shopping']->getShippingDeliveryFeeTotal($shippings));
323
324
            $total = $Order->getSubTotal() + $Order->getCharge() + $Order->getDeliveryFeeTotal();
325
326
            $Order->setTotal($total);
327
            $Order->setPaymentTotal($total);
328
329
            // 受注関連情報を最新状態に更新
330
            $app['orm.em']->flush();
331
332
            return $app->redirect($app->url('shopping'));
333
        }
334
335
        return $app->render('Shopping/index.twig', array(
336
            'form' => $form->createView(),
337
            'Order' => $Order,
338
        ));
339 3
    }
340
341
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
342
     * 支払い方法選択処理
343
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
344 2
    public function payment(Application $app, Request $request)
345
    {
346
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
347 2
        if (!$Order) {
348
            $app->addError('front.shopping.order.error');
349
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
350
        }
351
352
        if ('POST' !== $request->getMethod()) {
353
            return $app->redirect($app->url('shopping'));
354
        }
355
356
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
357
        $form->handleRequest($request);
358
359
        if ($form->isSubmitted() && $form->isValid()) {
360
            $data = $form->getData();
361
            $payment = $data['payment'];
362
            $message = $data['message'];
363
364
            $Order->setPayment($payment);
365
            $Order->setPaymentMethod($payment->getMethod());
366
            $Order->setMessage($message);
367
            $Order->setCharge($payment->getCharge());
368
369
            $total = $Order->getSubTotal() + $Order->getCharge() + $Order->getDeliveryFeeTotal();
370
371
            $Order->setTotal($total);
372
            $Order->setPaymentTotal($total);
373
374
            // 受注関連情報を最新状態に更新
375
            $app['orm.em']->flush();
376
377
            return $app->redirect($app->url('shopping'));
378
        }
379
380
        return $app->render('Shopping/index.twig', array(
381
            'form' => $form->createView(),
382
            'Order' => $Order,
383
        ));
384 2
    }
385
386
    /**
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...
387
     * お届け先変更がクリックされた場合の処理
388
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
389 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...
390
    {
391
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
392
        if (!$Order) {
393
            $app->addError('front.shopping.order.error');
394
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
395
        }
396
397
        if ('POST' !== $request->getMethod()) {
398
            return $app->redirect($app->url('shopping'));
399
        }
400
401
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
402
        $form->handleRequest($request);
403
404
        if ($form->isSubmitted() && $form->isValid()) {
405
            $data = $form->getData();
406
            $message = $data['message'];
407
            $Order->setMessage($message);
408
            // 受注情報を更新
409
            $app['orm.em']->flush();
410
411
            // お届け先設定一覧へリダイレクト
412
            return $app->redirect($app->url('shopping_shipping', array('id' => $id)));
413
        }
414
415
        return $app->render('Shopping/index.twig', array(
416
            'form' => $form->createView(),
417
            'Order' => $Order,
418
        ));
419
    }
420
421
    /**
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...
422
     * お届け先の設定一覧からの選択
423
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
424
    public function shipping(Application $app, Request $request, $id)
425
    {
426
        // カートチェック
427
        if (!$app['eccube.service.cart']->isLocked()) {
428
            // カートが存在しない、カートがロックされていない時はエラー
429
            return $app->redirect($app->url('cart'));
430
        }
431
432
        if ('POST' === $request->getMethod()) {
433
            $address = $request->get('address');
434
435
            if (is_null($address)) {
436
                // 選択されていなければエラー
437
                return $app->render(
438
                    'Shopping/shipping.twig',
439
                    array(
440
                        'Customer' => $app->user(),
441
                        'shippingId' => $id,
442
                        'error' => true,
443
                    )
444
                );
445
            }
446
447
            // 選択されたお届け先情報を取得
448
            $CustomerAddress = $app['eccube.repository.customer_address']->findOneBy(array(
449
                'Customer' => $app->user(),
450
                'id' => $address,
451
            ));
452
            if (is_null($CustomerAddress)) {
453
                throw new NotFoundHttpException();
454
            }
455
456
            $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
457
            if (!$Order) {
458
                $app->addError('front.shopping.order.error');
459
460
                return $app->redirect($app->url('shopping_error'));
461
            }
462
463
            $Shipping = $Order->findShipping($id);
464
            if (!$Shipping) {
465
                throw new NotFoundHttpException();
466
            }
467
468
            // お届け先情報を更新
469
            $Shipping
470
                ->setFromCustomerAddress($CustomerAddress);
471
472
            // 配送料金の設定
473
            $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
474
475
            // 配送先を更新
476
            $app['orm.em']->flush();
477
478
            return $app->redirect($app->url('shopping'));
479
        }
480
481
        return $app->render(
482
            'Shopping/shipping.twig',
483
            array(
484
                'Customer' => $app->user(),
485
                'shippingId' => $id,
486
                'error' => false,
487
            )
488
        );
489
    }
490
491
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
introduced by
Doc comment for parameter "$id" missing
Loading history...
492
     * お届け先の設定(非会員)がクリックされた場合の処理
493
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
494 5 View Code Duplication
    public function shippingEditChange(Application $app, Request $request, $id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
495
    {
496
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
497 5
        if (!$Order) {
498
            $app->addError('front.shopping.order.error');
499
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
500
        }
501
502
        if ('POST' !== $request->getMethod()) {
503
            return $app->redirect($app->url('shopping'));
504
        }
505
506
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
507
        $form->handleRequest($request);
508
509
        if ($form->isSubmitted() && $form->isValid()) {
510
            $data = $form->getData();
511 3
            $message = $data['message'];
512
            $Order->setMessage($message);
513
            // 受注情報を更新
514
            $app['orm.em']->flush();
515
516
            // お届け先設定一覧へリダイレクト
517
            return $app->redirect($app->url('shopping_shipping_edit', array('id' => $id)));
518
        }
519
520 1
        return $app->render('Shopping/index.twig', array(
521 1
            'form' => $form->createView(),
522
            'Order' => $Order,
523
        ));
524 5
    }
525
526
    /**
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...
527
     * お届け先の設定(非会員でも使用する)
528
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
529 2
    public function shippingEdit(Application $app, Request $request, $id)
530
    {
531
        // 配送先住所最大値判定
532
        $Customer = $app->user();
533 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...
534
            $addressCurrNum = count($app->user()->getCustomerAddresses());
535
            $addressMax = $app['config']['deliv_addr_max'];
536
            if ($addressCurrNum >= $addressMax) {
537
                throw new NotFoundHttpException();
538
            }
539
        }
540
541
        // カートチェック
542
        if (!$app['eccube.service.cart']->isLocked()) {
543
            // カートが存在しない、カートがロックされていない時はエラー
544
            return $app->redirect($app->url('cart'));
545
        }
546
547
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
548 2
        if (!$Order) {
549
            $app->addError('front.shopping.order.error');
550
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
551
        }
552
553
        $Shipping = $Order->findShipping($id);
554 2
        if (!$Shipping) {
555
            throw new NotFoundHttpException();
556
        }
557
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
558
            $Shipping->clearCustomerAddress();
559
        }
560
561
        $CustomerAddress = new CustomerAddress();
562
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
563
            $CustomerAddress->setCustomer($Customer);
564
        } else {
565
            $CustomerAddress->setFromShipping($Shipping);
566
        }
567
568
        $builder = $app['form.factory']->createBuilder('shopping_shipping', $CustomerAddress);
569
        $form = $builder->getForm();
570
        $form->handleRequest($request);
571
572
        if ($form->isSubmitted() && $form->isValid()) {
573
            // 会員の場合、お届け先情報を新規登録
574
            $Shipping->setFromCustomerAddress($CustomerAddress);
575
576 1
            if ($Customer instanceof Customer) {
0 ignored issues
show
Bug introduced by
The class Eccube\Entity\Customer does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

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

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

2. Missing use statement

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

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

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

Loading history...
577
                $app['orm.em']->persist($CustomerAddress);
578
            }
579
580
            // 配送料金の設定
581
            $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
582
583
            // 配送先を更新 
584
            $app['orm.em']->flush();
585
586
            return $app->redirect($app->url('shopping'));
587
        }
588
589 1
        return $app->render('Shopping/shipping_edit.twig', array(
590 1
            'form' => $form->createView(),
591
            'shippingId' => $id,
592
        ));
593 2
    }
594
595
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
596
     * お客様情報の変更(非会員)
597
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
598
    public function customer(Application $app, Request $request)
599
    {
600
        if ($request->isXmlHttpRequest()) {
601
            try {
602
                $data = $request->request->all();
603
604
                // 入力チェック
605
                $errors = $this->customerValidation($app, $data);
606
607
                foreach ($errors as $error) {
608 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...
609
                        $response = new Response(json_encode('NG'), 400);
610
                        $response->headers->set('Content-Type', 'application/json');
611
                        return $response;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
612
                    }
613
                }
614
615
                $pref = $app['eccube.repository.master.pref']->findOneBy(array('name' => $data['customer_pref']));
616 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...
617
                    $response = new Response(json_encode('NG'), 400);
618
                    $response->headers->set('Content-Type', 'application/json');
619
                    return $response;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
620
                }
621
622
                $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
623
                if (!$Order) {
624
                    $app->addError('front.shopping.order.error');
625
                    return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
626
                }
627
628
                $Order
629
                    ->setName01($data['customer_name01'])
630
                    ->setName02($data['customer_name02'])
631
                    ->setCompanyName($data['customer_company_name'])
632
                    ->setTel01($data['customer_tel01'])
633
                    ->setTel02($data['customer_tel02'])
634
                    ->setTel03($data['customer_tel03'])
635
                    ->setZip01($data['customer_zip01'])
636
                    ->setZip02($data['customer_zip02'])
637
                    ->setZipCode($data['customer_zip01'] . $data['customer_zip02'])
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
638
                    ->setPref($pref)
639
                    ->setAddr01($data['customer_addr01'])
640
                    ->setAddr02($data['customer_addr02'])
641
                    ->setEmail($data['customer_email']);
642
643
                // 配送先を更新
644
                $app['orm.em']->flush();
645
646
                // 受注関連情報を最新状態に更新
647
                $app['orm.em']->refresh($Order);
648
649
                $response = new Response(json_encode('OK'));
650
                $response->headers->set('Content-Type', 'application/json');
651
            } catch (\Exception $e) {
652
                $app['monolog']->error($e);
653
654
                $response = new Response(json_encode('NG'), 500);
655
                $response->headers->set('Content-Type', 'application/json');
656
            }
657
658
            return $response;
659
        }
660
    }
661
662
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
663
     * ログイン
664
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
665 2
    public function login(Application $app, Request $request)
666
    {
667
        if (!$app['eccube.service.cart']->isLocked()) {
668
            return $app->redirect($app->url('cart'));
669
        }
670
671
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
672
            return $app->redirect($app->url('shopping'));
673
        }
674
675
        /* @var $form \Symfony\Component\Form\FormInterface */
676
        $builder = $app['form.factory']->createNamedBuilder('', 'customer_login');
677
678 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...
679
            $Customer = $app->user();
680
            if ($Customer) {
681
                $builder->get('login_email')->setData($Customer->getEmail());
682
            }
683
        }
684
685
        $form = $builder->getForm();
686
687
        return $app->render('Shopping/login.twig', array(
688
            'error' => $app['security.last_error']($request),
689
            'form' => $form->createView(),
690
        ));
691 2
    }
692
693
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
694
     * 非会員処理
695
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
696 11
    public function nonmember(Application $app, Request $request)
697
    {
698
        $cartService = $app['eccube.service.cart'];
699
700
        // カートチェック
701
        if (!$cartService->isLocked()) {
702
            // カートが存在しない、カートがロックされていない時はエラー
703
            return $app->redirect($app->url('cart'));
704
        }
705
706
        // ログイン済みの場合は, 購入画面へリダイレクト.
707
        if ($app->isGranted('ROLE_USER')) {
708
            return $app->redirect($app->url('shopping'));
709
        }
710
711
        // カートチェック
712
        if (count($cartService->getCart()->getCartItems()) <= 0) {
713
            // カートが存在しない時はエラー
714
            return $app->redirect($app->url('cart'));
715
        }
716
717
        $form = $app['form.factory']->createBuilder('nonmember')->getForm();
718
        $form->handleRequest($request);
719
720
        if ($form->isSubmitted() && $form->isValid()) {
721
            $data = $form->getData();
722
            $Customer = new Customer();
723
            $Customer
724 8
                ->setName01($data['name01'])
725 8
                ->setName02($data['name02'])
726 8
                ->setKana01($data['kana01'])
727 8
                ->setKana02($data['kana02'])
728 8
                ->setCompanyName($data['company_name'])
729 8
                ->setEmail($data['email'])
730 8
                ->setTel01($data['tel01'])
731 8
                ->setTel02($data['tel02'])
732 8
                ->setTel03($data['tel03'])
733 8
                ->setZip01($data['zip01'])
734 8
                ->setZip02($data['zip02'])
735 8
                ->setZipCode($data['zip01'] . $data['zip02'])
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
736 8
                ->setPref($data['pref'])
737 8
                ->setAddr01($data['addr01'])
738
                ->setAddr02($data['addr02']);
739
740
            // 非会員複数配送用
741
            $CustomerAddress = new CustomerAddress();
742
            $CustomerAddress
743 8
                ->setCustomer($Customer)
744 8
                ->setName01($data['name01'])
745 8
                ->setName02($data['name02'])
746 8
                ->setKana01($data['kana01'])
747 8
                ->setKana02($data['kana02'])
748 8
                ->setCompanyName($data['company_name'])
749 8
                ->setTel01($data['tel01'])
750 8
                ->setTel02($data['tel02'])
751 8
                ->setTel03($data['tel03'])
752 8
                ->setZip01($data['zip01'])
753 8
                ->setZip02($data['zip02'])
754 8
                ->setZipCode($data['zip01'] . $data['zip02'])
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
755 8
                ->setPref($data['pref'])
756 8
                ->setAddr01($data['addr01'])
757 8
                ->setAddr02($data['addr02'])
758
                ->setDelFlg(Constant::DISABLED);
759
            $Customer->addCustomerAddress($CustomerAddress);
760
761
            // 受注情報を取得
762
            $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
763
764
            // 初回アクセス(受注データがない)の場合は, 受注情報を作成
765
            if (is_null($Order)) {
766
                // 受注情報を作成
767
                try {
768
                    // 受注情報を作成
769
                    $app['eccube.service.shopping']->createOrder($Customer);
770
                } catch (CartException $e) {
771
                    $app->addRequestError($e->getMessage());
772
                    return $app->redirect($app->url('cart'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
773 8
                }
774
            }
775
776
            // 非会員用セッションを作成
777 8
            $nonMember = array();
778 8
            $nonMember['customer'] = $Customer;
779
            $nonMember['pref'] = $Customer->getPref()->getId();
780
            $app['session']->set($this->sessionKey, $nonMember);
781
782 8
            $customerAddresses = array();
783 8
            $customerAddresses[] = $CustomerAddress;
784
            $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses));
785
786
            return $app->redirect($app->url('shopping'));
787
        }
788
789 2
        return $app->render('Shopping/nonmember.twig', array(
790 2
            'form' => $form->createView(),
791
        ));
792 11
    }
793
794
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
795
     * 複数配送処理がクリックされた場合の処理
796
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
797 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...
798
    {
799
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
800
        if (!$Order) {
801
            $app->addError('front.shopping.order.error');
802
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
803
        }
804
805
        if ('POST' !== $request->getMethod()) {
806
            return $app->redirect($app->url('shopping'));
807
        }
808
809
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
810
        $form->handleRequest($request);
811
812
        if ($form->isSubmitted() && $form->isValid()) {
813
            $data = $form->getData();
814
            $message = $data['message'];
815
            $Order->setMessage($message);
816
            // 受注情報を更新
817
            $app['orm.em']->flush();
818
819
            // 複数配送設定へリダイレクト
820
            return $app->redirect($app->url('shopping_shipping_multiple'));
821
        }
822
823
        return $app->render('Shopping/index.twig', array(
824
            'form' => $form->createView(),
825
            'Order' => $Order,
826
        ));
827
    }
828
829
830
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
831
     * 複数配送処理
832
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
833
    public function shippingMultiple(Application $app, Request $request)
834
    {
835
        $cartService = $app['eccube.service.cart'];
836
837
        // カートチェック
838
        if (!$cartService->isLocked()) {
839
            // カートが存在しない、カートがロックされていない時はエラー
840
            return $app->redirect($app->url('cart'));
841
        }
842
843
        // カートチェック
844
        if (count($cartService->getCart()->getCartItems()) <= 0) {
845
            // カートが存在しない時はエラー
846
            return $app->redirect($app->url('cart'));
847
        }
848
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
849
        if (!$Order) {
850
            $app->addError('front.shopping.order.error');
851
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
852
        }
853
854
        // 複数配送時は商品毎でお届け先を設定する為、商品をまとめた数量を設定
855
        $compItemQuantities = array();
856 View Code Duplication
        foreach ($Order->getShippings() as $Shipping) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
857
            foreach ($Shipping->getShipmentItems() as $ShipmentItem) {
858
                $itemId = $ShipmentItem->getProductClass()->getId();
859
                $quantity = $ShipmentItem->getQuantity();
860
                if (array_key_exists($itemId, $compItemQuantities)) {
861
                    $compItemQuantities[$itemId] = $compItemQuantities[$itemId] + $quantity;
862
                } else {
863
                    $compItemQuantities[$itemId] = $quantity;
864
                }
865
            }
866
        }
867
868
        // 商品に紐づく商品情報を取得
869
        $shipmentItems = array();
870
        $productClassIds = array();
871
        foreach ($Order->getShippings() as $Shipping) {
872
            foreach ($Shipping->getShipmentItems() as $ShipmentItem) {
873
                if (!in_array($ShipmentItem->getProductClass()->getId(), $productClassIds)) {
874
                    $shipmentItems[] = $ShipmentItem;
875
                }
876
                $productClassIds[] = $ShipmentItem->getProductClass()->getId();
877
            }
878
        }
879
880
        $form = $app->form()->getForm();
881
        $form
882
            ->add('shipping_multiple', 'collection', array(
883
                'type' => 'shipping_multiple',
884
                'data' => $shipmentItems,
885
                'allow_add' => true,
886
                'allow_delete' => true,
887
            ));
888
        $form->handleRequest($request);
889
890
        $errors = array();
891
        if ($form->isSubmitted() && $form->isValid()) {
892
            $data = $form['shipping_multiple'];
893
894
            // 数量が超えていないか、同一でないとエラー
895
            $itemQuantities = array();
896
            foreach ($data as $mulitples) {
897
                /** @var \Eccube\Entity\ShipmentItem $multipleItem */
898
                $multipleItem = $mulitples->getData();
899 View Code Duplication
                foreach ($mulitples as $items) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
900
                    foreach ($items as $item) {
901
                        $quantity = $item['quantity']->getData();
902
                        $itemId = $multipleItem->getProductClass()->getId();
903
                        if (array_key_exists($itemId, $itemQuantities)) {
904
                            $itemQuantities[$itemId] = $itemQuantities[$itemId] + $quantity;
905
                        } else {
906
                            $itemQuantities[$itemId] = $quantity;
907
                        }
908
                    }
909
                }
910
            }
911
912
            foreach ($compItemQuantities as $key => $value) {
913
                if (array_key_exists($key, $itemQuantities)) {
914
                    if ($itemQuantities[$key] != $value) {
915
                        $errors[] = array('message' => '数量の数が異なっています。');
916
917
                        // 対象がなければエラー
918
                        return $app->render('Shopping/shipping_multiple.twig', array(
919
                            'form' => $form->createView(),
920
                            'shipmentItems' => $shipmentItems,
921
                            'compItemQuantities' => $compItemQuantities,
922
                            'errors' => $errors,
923
                        ));
924
                    }
925
                }
926
            }
927
928
            // お届け先情報をdelete/insert
929
            $shippings = $Order->getShippings();
930
            foreach ($shippings as $Shipping) {
931
                $Order->removeShipping($Shipping);
932
                $app['orm.em']->remove($Shipping);
933
            }
934
935
            foreach ($data as $mulitples) {
936
                /** @var \Eccube\Entity\ShipmentItem $multipleItem */
937
                $multipleItem = $mulitples->getData();
938
939
                foreach ($mulitples as $items) {
940
                    foreach ($items as $item) {
941
                        // 追加された配送先情報を作成
942
                        $Delivery = $multipleItem->getShipping()->getDelivery();
943
944
                        // 選択された情報を取得
945
                        $data = $item['customer_address']->getData();
946
                        if ($data instanceof CustomerAddress) {
0 ignored issues
show
Bug introduced by
The class Eccube\Entity\CustomerAddress does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

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

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

2. Missing use statement

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

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

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

Loading history...
947
                            // 会員の場合、CustomerAddressオブジェクトを取得
948
                            $CustomerAddress = $data;
949
                        } else {
950
                            // 非会員の場合、選択されたindexが取得される
951
                            $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey);
952
                            $customerAddresses = unserialize($customerAddresses);
953
                            $CustomerAddress = $customerAddresses[$data];
954
                            $pref = $app['eccube.repository.master.pref']->find($CustomerAddress->getPref()->getId());
955
                            $CustomerAddress->setPref($pref);
956
                        }
957
958
                        $Shipping = new Shipping();
959
                        $Shipping
960
                            ->setFromCustomerAddress($CustomerAddress)
961
                            ->setDelivery($Delivery)
962
                            ->setDelFlg(Constant::DISABLED)
963
                            ->setOrder($Order);
964
                        $app['orm.em']->persist($Shipping);
965
966
                        $ProductClass = $multipleItem->getProductClass();
967
                        $Product = $multipleItem->getProduct();
968
                        $quantity = $item['quantity']->getData();
969
970
                        $ShipmentItem = new ShipmentItem();
971
                        $ShipmentItem->setShipping($Shipping)
972
                            ->setOrder($Order)
973
                            ->setProductClass($ProductClass)
974
                            ->setProduct($Product)
975
                            ->setProductName($Product->getName())
976
                            ->setProductCode($ProductClass->getCode())
977
                            ->setPrice($ProductClass->getPrice02())
978
                            ->setQuantity($quantity);
979
980
                        $ClassCategory1 = $ProductClass->getClassCategory1();
981
                        if (!is_null($ClassCategory1)) {
982
                            $ShipmentItem->setClasscategoryName1($ClassCategory1->getName());
983
                            $ShipmentItem->setClassName1($ClassCategory1->getClassName()->getName());
984
                        }
985
                        $ClassCategory2 = $ProductClass->getClassCategory2();
986
                        if (!is_null($ClassCategory2)) {
987
                            $ShipmentItem->setClasscategoryName2($ClassCategory2->getName());
988
                            $ShipmentItem->setClassName2($ClassCategory2->getClassName()->getName());
989
                        }
990
                        $Shipping->addShipmentItem($ShipmentItem);
991
                        $app['orm.em']->persist($ShipmentItem);
992
993
                        // 配送料金の設定
994
                        $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
995
                    }
996
                }
997
            }
998
            // 配送先を更新
999
            $app['orm.em']->flush();
1000
1001
            return $app->redirect($app->url('shopping'));
1002
        }
1003
1004
        return $app->render('Shopping/shipping_multiple.twig', array(
1005
            'form' => $form->createView(),
1006
            'shipmentItems' => $shipmentItems,
1007
            'compItemQuantities' => $compItemQuantities,
1008
            'errors' => $errors,
1009
        ));
1010
    }
1011
1012
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1013
     * 非会員用複数配送設定時の新規お届け先の設定
1014
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1015
    public function shippingMultipleEdit(Application $app, Request $request)
1016
    {
1017
        // カートチェック
1018
        if (!$app['eccube.service.cart']->isLocked()) {
1019
            // カートが存在しない、カートがロックされていない時はエラー
1020
            return $app->redirect($app->url('cart'));
1021
        }
1022
1023
        // 非会員用Customerを取得
1024
        $Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey);
1025
        $CustomerAddress = new CustomerAddress();
1026
        $CustomerAddress->setCustomer($Customer);
1027
        $Customer->addCustomerAddress($CustomerAddress);
1028
1029
        $form = $app['form.factory']->createBuilder('shopping_shipping', $CustomerAddress)->getForm();
1030
        $form->handleRequest($request);
1031
1032
        if ($form->isSubmitted() && $form->isValid()) {
1033
            // 非会員用のセッションに追加
1034
            $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey);
1035
            $customerAddresses = unserialize($customerAddresses);
1036
            $customerAddresses[] = $CustomerAddress;
1037
            $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses));
1038
1039
            return $app->redirect($app->url('shopping_shipping_multiple'));
1040
        }
1041
1042
        return $app->render('Shopping/shipping_multiple_edit.twig', array(
1043
            'form' => $form->createView(),
1044
        ));
1045
    }
1046
1047
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
1048
     * 購入エラー画面表示
1049
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1050 1
    public function shoppingError(Application $app)
1051
    {
1052
        return $app->render('Shopping/shopping_error.twig');
1053 1
    }
1054
1055
    /**
1056
     * 非会員でのお客様情報変更時の入力チェック
1057
     * @param $data リクエストパラメータ
1058
     */
1059
    private function customerValidation($app, $data)
1060
    {
1061
        // 入力チェック
1062
        $errors = array();
1063
1064
        $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...
1065
            new Assert\NotBlank(),
1066
            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...
1067
            new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace'))
1068
        ));
1069
1070
        $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...
1071
            new Assert\NotBlank(),
1072
            new Assert\Length(array('max' => $app['config']['name_len'], )),
1073
            new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace'))
1074
        ));
1075
1076
        $errors[] = $app['validator']->validateValue($data['customer_company_name'], array(
1077
            new Assert\Length(array('max' => $app['config']['stext_len'])),
1078
        ));
1079
1080
        $errors[] = $app['validator']->validateValue($data['customer_tel01'], array(
1081
            new Assert\NotBlank(),
1082
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1083
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1084
        ));
1085
1086
        $errors[] = $app['validator']->validateValue($data['customer_tel02'], array(
1087
            new Assert\NotBlank(),
1088
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1089
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1090
        ));
1091
1092
        $errors[] = $app['validator']->validateValue($data['customer_tel03'], array(
1093
            new Assert\NotBlank(),
1094
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1095
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1096
        ));
1097
1098
        $errors[] = $app['validator']->validateValue($data['customer_zip01'], array(
1099
            new Assert\NotBlank(),
1100
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1101
            new Assert\Length(array('min' => $app['config']['zip01_len'], 'max' => $app['config']['zip01_len'])),
1102
        ));
1103
1104
        $errors[] = $app['validator']->validateValue($data['customer_zip02'], array(
1105
            new Assert\NotBlank(),
1106
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1107
            new Assert\Length(array('min' => $app['config']['zip02_len'], 'max' => $app['config']['zip02_len'])),
1108
        ));
1109
1110
        $errors[] = $app['validator']->validateValue($data['customer_addr01'], array(
1111
            new Assert\NotBlank(),
1112
            new Assert\Length(array('max' => $app['config']['address1_len'])),
1113
        ));
1114
1115
        $errors[] = $app['validator']->validateValue($data['customer_addr02'], array(
1116
            new Assert\NotBlank(),
1117
            new Assert\Length(array('max' => $app['config']['address2_len'])),
1118
        ));
1119
1120
        $errors[] = $app['validator']->validateValue($data['customer_email'], array(
1121
            new Assert\NotBlank(),
1122
            new Assert\Email(),
1123
        ));
1124
1125
        return $errors;
1126
    }
1127
}
1128