Completed
Pull Request — master (#1261)
by Kentaro
33:04 queued 10s
created

ShoppingController::confirm()   C

Complexity

Conditions 8
Paths 20

Size

Total Lines 107
Code Lines 58

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 107
ccs 10
cts 10
cp 1
rs 5.2676
cc 8
eloc 58
nc 20
nop 2
crap 8

How to fix   Long Method   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
25
namespace Eccube\Controller;
26
27
use Eccube\Application;
28
use Eccube\Common\Constant;
29
use Eccube\Entity\Customer;
30
use Eccube\Entity\CustomerAddress;
31
use Eccube\Entity\ShipmentItem;
32
use Eccube\Entity\Shipping;
33
use Eccube\Entity\MailHistory;
34
use Symfony\Component\HttpFoundation\Request;
35
use Symfony\Component\HttpFoundation\Response;
36
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
37
use Symfony\Component\Validator\Constraints as Assert;
38
39
class ShoppingController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
40
{
41
42
    /**
43
     * @var string 非会員用セッションキー
44
     */
45
    private $sessionKey = 'eccube.front.shopping.nonmember';
46
47
    /**
48
     * @var string 非会員用セッションキー
49
     */
50
    private $sessionCustomerAddressKey = 'eccube.front.shopping.nonmember.customeraddress';
51
52
    /**
53
     * @var string 複数配送警告メッセージ
54
     */
55
    private $sessionMultipleKey = 'eccube.front.shopping.multiple';
56
57
    /**
58
     * @var string 受注IDキー
59
     */
60
    private $sessionOrderKey = 'eccube.front.shopping.order.id';
61
62
    /**
63
     * 購入画面表示
64
     *
65
     * @param Application $app
66
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
67
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
68
     */
69 5
    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...
70
    {
71
        $cartService = $app['eccube.service.cart'];
72
73
        // カートチェック
74
        if (!$cartService->isLocked()) {
75
            // カートが存在しない、カートがロックされていない時はエラー
76
            return $app->redirect($app->url('cart'));
77
        }
78
79
        // カートチェック
80
        if (count($cartService->getCart()->getCartItems()) <= 0) {
81
            // カートが存在しない時はエラー
82
            return $app->redirect($app->url('cart'));
83
        }
84
85
        // 登録済みの受注情報を取得
86
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
87
88
        // 初回アクセス(受注情報がない)の場合は, 受注情報を作成
89
        if (is_null($Order)) {
90
91
            // 未ログインの場合, ログイン画面へリダイレクト.
92
            if (!$app->isGranted('IS_AUTHENTICATED_FULLY')) {
93
94
                // 非会員でも一度会員登録されていればショッピング画面へ遷移
95
                $Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey);
96
97
                if (is_null($Customer)) {
98
                    return $app->redirect($app->url('shopping_login'));
99
                }
100
101
            } else {
102
                $Customer = $app->user();
103 2
            }
104
105
            // 受注情報を作成
106
            $Order = $app['eccube.service.shopping']->createOrder($Customer);
107
108
            // セッション情報を削除
109
            $app['session']->remove($this->sessionOrderKey);
110
            $app['session']->remove($this->sessionMultipleKey);
111
112
        } else {
113
            // 計算処理
114
            $Order = $app['eccube.service.shopping']->getAmount($Order);
115 2
        }
116
117
        // 受注関連情報を最新状態に更新
118
        $app['orm.em']->refresh($Order);
119
120
        // form作成
121
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
122
123
        // 複数配送の場合、エラーメッセージを一度だけ表示
124
        if (!$app['session']->has($this->sessionMultipleKey)) {
125
            if (count($Order->getShippings()) > 1) {
126
                $app->addRequestError('shopping.multiple.delivery');
127
            }
128
            $app['session']->set($this->sessionMultipleKey, 'multiple');
129
        }
130
131
132 2
        return $app->render('Shopping/index.twig', array(
133 2
            'form' => $form->createView(),
134
            'Order' => $Order,
135
        ));
136 5
    }
137
138
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
139
     * 購入処理
140
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
141 1
    public function confirm(Application $app, Request $request)
142
    {
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 1
        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
        // form作成
159
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
160
161
        if ('POST' === $request->getMethod()) {
162
            $form->handleRequest($request);
163
164
            if ($form->isValid()) {
165
                $data = $form->getData();
166
167
                // トランザクション制御
168
                $em = $app['orm.em'];
169
                $em->getConnection()->beginTransaction();
170
                try {
171
                    // 商品公開ステータスチェック、商品制限数チェック、在庫チェック
172
                    $check = $app['eccube.service.shopping']->isOrderProduct($em, $Order);
173 1
                    if (!$check) {
174
                        $em->getConnection()->rollback();
175
                        $em->close();
176
177
                        $app->addError('front.shopping.stock.error');
178
                        return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
179
                    }
180
181
                    // 受注情報、配送情報を更新
182
                    $app['eccube.service.shopping']->setOrderUpdate($Order, $data);
183
                    // 在庫情報を更新
184
                    $app['eccube.service.shopping']->setStockUpdate($em, $Order);
185
186
                    if ($app->isGranted('ROLE_USER')) {
187
                        // 会員の場合、購入金額を更新
188
                        $app['eccube.service.shopping']->setCustomerUpdate($Order, $app->user());
189
                    }
190
191
                    $em->getConnection()->commit();
192
                    $em->flush();
193
194
                } catch (\Exception $e) {
195
                    $em->getConnection()->rollback();
196
                    $em->close();
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 1
                }
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 1
                $body = $app->renderView($MailTemplate->getFileName(), array(
217 1
                    'header' => $MailTemplate->getHeader(),
218 1
                    '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 1
                    ->setMailBody($body)
226 1
                    ->setMailTemplate($MailTemplate)
227
                    ->setSendDate(new \DateTime())
228
                    ->setOrder($Order);
229
                $app['orm.em']->persist($MailHistory);
230
                $app['orm.em']->flush($MailHistory);
231
232
                $em->close();
233
234
                // 完了画面表示
235
                return $app->redirect($app->url('shopping_complete'));
236
237
            } else {
238
                return $app->render('Shopping/index.twig', array(
239
                    'form' => $form->createView(),
240
                    'Order' => $Order,
241
                ));
242
            }
243
        }
244
245
        return $app->redirect($app->url('cart'));
246
247 1
    }
248
249
250
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
251
     * 購入完了画面表示
252
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
253
    public function complete(Application $app)
254
    {
255
256
        // 受注IDを取得
257
        $orderId = $app['session']->get($this->sessionOrderKey);
258
259
        // 受注IDセッションを削除
260
        $app['session']->remove($this->sessionOrderKey);
261
262
        return $app->render('Shopping/complete.twig', array(
263
            'orderId' => $orderId,
264
        ));
265
    }
266
267
268
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
269
     * 配送業者選択処理
270
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
271
    public function delivery(Application $app, Request $request)
272
    {
273
274
        // カートチェック
275
        if (!$app['eccube.service.cart']->isLocked()) {
276
            // カートが存在しない、カートがロックされていない時はエラー
277
            return $app->redirect($app->url('cart'));
278
        }
279
280
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
281
        if (!$Order) {
282
            $app->addError('front.shopping.order.error');
283
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
284
        }
285
286
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
287
288
        if ('POST' === $request->getMethod()) {
289
290
            $form->handleRequest($request);
291
292
            if ($form->isValid()) {
293
294
                $data = $form->getData();
295
296
                $shippings = $data['shippings'];
297
298
                $productDeliveryFeeTotal = 0;
299
                $BaseInfo = $app['eccube.repository.base_info']->get();
300
301
                foreach ($shippings as $Shipping) {
302
303
                    $Delivery = $Shipping->getDelivery();
304
305
                    $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...
306
                        'Delivery' => $Delivery,
307
                        'Pref' => $Shipping->getPref()
308
                        ));
309
310
                    // 商品ごとの配送料合計
311
                    if (!is_null($BaseInfo->getOptionProductDeliveryFee())) {
312
                        $productDeliveryFeeTotal += $app['eccube.service.shopping']->getProductDeliveryFee($Shipping);
313
                    }
314
315
                    $Shipping->setDeliveryFee($deliveryFee);
316
                    $Shipping->setShippingDeliveryFee($deliveryFee->getFee() + $productDeliveryFeeTotal);
317
                    $Shipping->setShippingDeliveryName($Delivery->getName());
318
                }
319
320
                // 支払い情報をセット
321
                $payment = $data['payment'];
322
                $message = $data['message'];
323
324
                $Order->setPayment($payment);
325
                $Order->setPaymentMethod($payment->getMethod());
326
                $Order->setMessage($message);
327
                $Order->setCharge($payment->getCharge());
328
329
                $Order->setDeliveryFeeTotal($app['eccube.service.shopping']->getShippingDeliveryFeeTotal($shippings));
330
331
                $total = $Order->getSubTotal() + $Order->getCharge() + $Order->getDeliveryFeeTotal();
332
333
                $Order->setTotal($total);
334
                $Order->setPaymentTotal($total);
335
336
                // 受注関連情報を最新状態に更新
337
                $app['orm.em']->flush();
338
            } else {
339
                return $app->render('Shopping/index.twig', array(
340
                    'form' => $form->createView(),
341
                    'Order' => $Order,
342
                ));
343
            }
344
345
        }
346
347
        return $app->redirect($app->url('shopping'));
348
349
    }
350
351
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
352
     * 支払い方法選択処理
353
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
354
    public function payment(Application $app, Request $request)
355
    {
356
357
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
358
        if (!$Order) {
359
            $app->addError('front.shopping.order.error');
360
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
361
        }
362
363
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
364
365
        if ('POST' === $request->getMethod()) {
366
367
            $form->handleRequest($request);
368
369
            if ($form->isValid()) {
370
                $data = $form->getData();
371
                $payment = $data['payment'];
372
                $message = $data['message'];
373
374
                $Order->setPayment($payment);
375
                $Order->setPaymentMethod($payment->getMethod());
376
                $Order->setMessage($message);
377
                $Order->setCharge($payment->getCharge());
378
379
                $total = $Order->getSubTotal() + $Order->getCharge() + $Order->getDeliveryFeeTotal();
380
381
                $Order->setTotal($total);
382
                $Order->setPaymentTotal($total);
383
384
                // 受注関連情報を最新状態に更新
385
                $app['orm.em']->flush();
386
            } else {
387
                return $app->render('Shopping/index.twig', array(
388
                    'form' => $form->createView(),
389
                    'Order' => $Order,
390
                ));
391
            }
392
393
        }
394
395
        return $app->redirect($app->url('shopping'));
396
397
    }
398
399
    /**
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...
400
     * お届け先変更がクリックされた場合の処理
401
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
402 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...
403
    {
404
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
405
        if (!$Order) {
406
            $app->addError('front.shopping.order.error');
407
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
408
        }
409
410
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
411
412
        if ('POST' === $request->getMethod()) {
413
            $form->handleRequest($request);
414
415
            if ($form->isValid()) {
416
                $data = $form->getData();
417
                $message = $data['message'];
418
                $Order->setMessage($message);
419
                // 受注情報を更新
420
                $app['orm.em']->flush();
421
                // お届け先設定一覧へリダイレクト
422
                return $app->redirect($app->url('shopping_shipping', array('id' => $id)));
423
            } else {
424
                return $app->render('Shopping/index.twig', array(
425
                    'form' => $form->createView(),
426
                    'Order' => $Order,
427
                ));
428
            }
429
        }
430
431
        return $app->redirect($app->url('shopping'));
432
    }
433
434
    /**
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...
435
     * お届け先の設定一覧からの選択
436
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
437
    public function shipping(Application $app, Request $request, $id)
438
    {
439
440
        // カートチェック
441
        if (!$app['eccube.service.cart']->isLocked()) {
442
            // カートが存在しない、カートがロックされていない時はエラー
443
            return $app->redirect($app->url('cart'));
444
        }
445
446
        if ('POST' === $request->getMethod()) {
447
            $address = $request->get('address');
448
449
            if (is_null($address)) {
450
                // 選択されていなければエラー
451
                return $app->render(
452
                    'Shopping/shipping.twig',
453
                    array(
454
                        'Customer' => $app->user(),
455
                        'shippingId' => $id,
456
                    )
457
                );
458
            }
459
460
            // 選択されたお届け先情報を取得
461
            $CustomerAddress = $app['eccube.repository.customer_address']->findOneBy(array(
462
                'Customer' => $app->user(),
463
                'id' => $address,
464
            ));
465
            if (is_null($CustomerAddress)) {
466
                throw new NotFoundHttpException();
467
            }
468
469
            $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
470
            if (!$Order) {
471
                $app->addError('front.shopping.order.error');
472
473
                return $app->redirect($app->url('shopping_error'));
474
            }
475
476
            $Shipping = $Order->findShipping($id);
477
            if (!$Shipping) {
478
                throw new NotFoundHttpException();
479
            }
480
481
            // お届け先情報を更新
482
            $Shipping
483
                ->setName01($CustomerAddress->getName01())
484
                ->setName02($CustomerAddress->getName02())
485
                ->setKana01($CustomerAddress->getKana01())
486
                ->setKana02($CustomerAddress->getKana02())
487
                ->setCompanyName($CustomerAddress->getCompanyName())
488
                ->setTel01($CustomerAddress->getTel01())
489
                ->setTel02($CustomerAddress->getTel02())
490
                ->setTel03($CustomerAddress->getTel03())
491
                ->setFax01($CustomerAddress->getFax01())
492
                ->setFax02($CustomerAddress->getFax02())
493
                ->setFax03($CustomerAddress->getFax03())
494
                ->setZip01($CustomerAddress->getZip01())
495
                ->setZip02($CustomerAddress->getZip02())
496
                ->setZipCode($CustomerAddress->getZip01() . $CustomerAddress->getZip02())
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
497
                ->setPref($CustomerAddress->getPref())
498
                ->setAddr01($CustomerAddress->getAddr01())
499
                ->setAddr02($CustomerAddress->getAddr02());
500
501
            // 配送料金の設定
502
            $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
503
504
            // 配送先を更新
505
            $app['orm.em']->flush();
506
507
            return $app->redirect($app->url('shopping'));
508
509
        }
510
511
        return $app->render(
512
            'Shopping/shipping.twig',
513
            array(
514
                'Customer' => $app->user(),
515
                'shippingId' => $id,
516
            )
517
        );
518
    }
519
520
    /**
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...
521
     * お届け先の設定(非会員)がクリックされた場合の処理
522
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
523 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...
524
    {
525
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
526
        if (!$Order) {
527
            $app->addError('front.shopping.order.error');
528
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
529
        }
530
531
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
532
533
        if ('POST' === $request->getMethod()) {
534
            $form->handleRequest($request);
535
536
            if ($form->isValid()) {
537
                $data = $form->getData();
538
                $message = $data['message'];
539
                $Order->setMessage($message);
540
                // 受注情報を更新
541
                $app['orm.em']->flush();
542
                // お届け先設定一覧へリダイレクト
543
                return $app->redirect($app->url('shopping_shipping_edit', array('id' => $id)));
544
            } else {
545
                return $app->render('Shopping/index.twig', array(
546
                    'form' => $form->createView(),
547
                    'Order' => $Order,
548
                ));
549
            }
550
        }
551
552
        return $app->redirect($app->url('shopping'));
553
    }
554
555
556
    /**
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...
557
     * お届け先の設定(非会員でも使用する)
558
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
559
    public function shippingEdit(Application $app, Request $request, $id)
560
    {
561
        // 配送先住所最大値判定
562
        $Customer = $app->user();
563 View Code Duplication
        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...
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...
564
            error_log("hoge");
565
            $addressCurrNum = count($app->user()->getCustomerAddresses());
566
            $addressMax = $app['config']['deliv_addr_max'];
567
            if ($addressCurrNum >= $addressMax) {
568
                throw new NotFoundHttpException();
569
            }
570
        }
571
572
        // カートチェック
573
        if (!$app['eccube.service.cart']->isLocked()) {
574
            // カートが存在しない、カートがロックされていない時はエラー
575
            return $app->redirect($app->url('cart'));
576
        }
577
578
579
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
580
        if (!$Order) {
581
            $app->addError('front.shopping.order.error');
582
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
583
        }
584
585
        $Shipping = $Order->findShipping($id);
586
        if (!$Shipping) {
587
            throw new NotFoundHttpException();
588
        }
589
590
        // 会員の場合、お届け先情報を新規登録
591
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
592
            $builder = $app['form.factory']->createBuilder('shopping_shipping');
593
        } else {
594
            // 非会員の場合、お届け先を追加
595
            $builder = $app['form.factory']->createBuilder('shopping_shipping', $Shipping);
596
        }
597
598
        $form = $builder->getForm();
599
600
        if ('POST' === $request->getMethod()) {
601
602
            $form->handleRequest($request);
603
604
            if ($form->isValid()) {
605
                $data = $form->getData();
606
607
                // 会員の場合、お届け先情報を新規登録
608
                if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
609
                    $CustomerAddress = new CustomerAddress();
610
                    $CustomerAddress
611
                        ->setCustomer($app->user())
612
                        ->setName01($data['name01'])
613
                        ->setName02($data['name02'])
614
                        ->setKana01($data['kana01'])
615
                        ->setKana02($data['kana02'])
616
                        ->setCompanyName($data['company_name'])
617
                        ->setTel01($data['tel01'])
618
                        ->setTel02($data['tel02'])
619
                        ->setTel03($data['tel03'])
620
                        ->setZip01($data['zip01'])
621
                        ->setZip02($data['zip02'])
622
                        ->setZipCode($data['zip01'] . $data['zip02'])
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
623
                        ->setPref($data['pref'])
624
                        ->setAddr01($data['addr01'])
625
                        ->setAddr02($data['addr02'])
626
                        ->setDelFlg(Constant::DISABLED);
627
628
                    $app['orm.em']->persist($CustomerAddress);
629
630
                }
631
632
                $Shipping
633
                    ->setName01($data['name01'])
634
                    ->setName02($data['name02'])
635
                    ->setKana01($data['kana01'])
636
                    ->setKana02($data['kana02'])
637
                    ->setCompanyName($data['company_name'])
638
                    ->setTel01($data['tel01'])
639
                    ->setTel02($data['tel02'])
640
                    ->setTel03($data['tel03'])
641
                    ->setZip01($data['zip01'])
642
                    ->setZip02($data['zip02'])
643
                    ->setZipCode($data['zip01'] . $data['zip02'])
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
644
                    ->setPref($data['pref'])
645
                    ->setAddr01($data['addr01'])
646
                    ->setAddr02($data['addr02']);
647
648
                // 配送料金の設定
649
                $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
650
651
                // 配送先を更新
652
                $app['orm.em']->flush();
653
654
                return $app->redirect($app->url('shopping'));
655
656
            }
657
        }
658
659
        return $app->render('Shopping/shipping_edit.twig', array(
660
            'form' => $form->createView(),
661
            'shippingId' => $id,
662
        ));
663
664
    }
665
666
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
667
     * お客様情報の変更(非会員)
668
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
669
    public function customer(Application $app, Request $request)
670
    {
671
672
        if ($request->isXmlHttpRequest()) {
673
            try {
674
                $data = $request->request->all();
675
676
                // 入力チェック
677
                $errors = $this->customerValidation($app, $data);
678
679
                foreach ($errors as $error) {
680 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...
681
                        $response = new Response(json_encode('NG'), 500);
682
                        $response->headers->set('Content-Type', 'application/json');
683
                        return $response;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
684
                    }
685
                }
686
687
                $pref = $app['eccube.repository.master.pref']->findOneBy(array('name' => $data['customer_pref']));
688 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...
689
                    $response = new Response(json_encode('NG'), 500);
690
                    $response->headers->set('Content-Type', 'application/json');
691
                    return $response;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
692
                }
693
694
                $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
695
                if (!$Order) {
696
                    $app->addError('front.shopping.order.error');
697
                    return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
698
                }
699
700
                $Order
701
                    ->setName01($data['customer_name01'])
702
                    ->setName02($data['customer_name02'])
703
                    ->setCompanyName($data['customer_company_name'])
704
                    ->setTel01($data['customer_tel01'])
705
                    ->setTel02($data['customer_tel02'])
706
                    ->setTel03($data['customer_tel03'])
707
                    ->setZip01($data['customer_zip01'])
708
                    ->setZip02($data['customer_zip02'])
709
                    ->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...
710
                    ->setPref($pref)
711
                    ->setAddr01($data['customer_addr01'])
712
                    ->setAddr02($data['customer_addr02'])
713
                    ->setEmail($data['customer_email']);
714
715
                // 配送先を更新
716
                $app['orm.em']->flush();
717
718
                // 受注関連情報を最新状態に更新
719
                $app['orm.em']->refresh($Order);
720
721
                $response = new Response(json_encode('OK'));
722
                $response->headers->set('Content-Type', 'application/json');
723
724
            } catch (\Exception $e) {
725
                $app->log($e);
726
727
                $response = new Response(json_encode('NG'), 500);
728
                $response->headers->set('Content-Type', 'application/json');
729
730
            }
731
732
            return $response;
733
734
        }
735
736
    }
737
738
739
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
740
     * ログイン
741
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
742 2
    public function login(Application $app, Request $request)
743
    {
744
745
        if (!$app['eccube.service.cart']->isLocked()) {
746
            return $app->redirect($app->url('cart'));
747
        }
748
749
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
750
            return $app->redirect($app->url('shopping'));
751
        }
752
753
        /* @var $form \Symfony\Component\Form\FormInterface */
754
        $builder = $app['form.factory']->createNamedBuilder('', 'customer_login');
755
756 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...
757
            $Customer = $app->user();
758
            if ($Customer) {
759
                $builder->get('login_email')->setData($Customer->getEmail());
760
            }
761
        }
762
763
        $form = $builder->getForm();
764
765
        return $app->render('Shopping/login.twig', array(
766
            'error' => $app['security.last_error']($request),
767
            'form' => $form->createView(),
768
        ));
769 2
    }
770
771
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
772
     * 非会員処理
773
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
774 6
    public function nonmember(Application $app, Request $request)
775
    {
776
777
        $cartService = $app['eccube.service.cart'];
778
779
        // カートチェック
780
        if (!$cartService->isLocked()) {
781
            // カートが存在しない、カートがロックされていない時はエラー
782
            return $app->redirect($app->url('cart'));
783
        }
784
785
        // ログイン済みの場合は, 購入画面へリダイレクト.
786
        if ($app->isGranted('ROLE_USER')) {
787
            return $app->redirect($app->url('shopping'));
788
        }
789
790
        // カートチェック
791
        if (count($cartService->getCart()->getCartItems()) <= 0) {
792
            // カートが存在しない時はエラー
793
            return $app->redirect($app->url('cart'));
794
        }
795
796
        $form = $app['form.factory']->createBuilder('nonmember')->getForm();
797
798
        if ('POST' === $request->getMethod()) {
799
            $form->handleRequest($request);
800
            if ($form->isValid()) {
801
                $data = $form->getData();
802
                $Customer = new Customer();
803
                $Customer
804 3
                    ->setName01($data['name01'])
805 3
                    ->setName02($data['name02'])
806 3
                    ->setKana01($data['kana01'])
807 3
                    ->setKana02($data['kana02'])
808 3
                    ->setCompanyName($data['company_name'])
809 3
                    ->setEmail($data['email'])
810 3
                    ->setTel01($data['tel01'])
811 3
                    ->setTel02($data['tel02'])
812 3
                    ->setTel03($data['tel03'])
813 3
                    ->setZip01($data['zip01'])
814 3
                    ->setZip02($data['zip02'])
815 3
                    ->setZipCode($data['zip01'] . $data['zip02'])
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
816 3
                    ->setPref($data['pref'])
817 3
                    ->setAddr01($data['addr01'])
818
                    ->setAddr02($data['addr02']);
819
820
                // 非会員複数配送用
821
                $CustomerAddress = new CustomerAddress();
822
                $CustomerAddress
823 3
                    ->setCustomer($Customer)
824 3
                    ->setName01($data['name01'])
825 3
                    ->setName02($data['name02'])
826 3
                    ->setKana01($data['kana01'])
827 3
                    ->setKana02($data['kana02'])
828 3
                    ->setCompanyName($data['company_name'])
829 3
                    ->setTel01($data['tel01'])
830 3
                    ->setTel02($data['tel02'])
831 3
                    ->setTel03($data['tel03'])
832 3
                    ->setZip01($data['zip01'])
833 3
                    ->setZip02($data['zip02'])
834 3
                    ->setZipCode($data['zip01'] . $data['zip02'])
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
835 3
                    ->setPref($data['pref'])
836 3
                    ->setAddr01($data['addr01'])
837 3
                    ->setAddr02($data['addr02'])
838
                    ->setDelFlg(Constant::DISABLED);
839
                $Customer->addCustomerAddress($CustomerAddress);
840
841
                // 受注情報を取得
842
                $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
843
844
                // 初回アクセス(受注データがない)の場合は, 受注情報を作成
845
                if (is_null($Order)) {
846
                    // 受注情報を作成
847
                    $app['eccube.service.shopping']->createOrder($Customer);
848
                }
849
850
                // 非会員用セッションを作成
851 3
                $nonMember = array();
852 3
                $nonMember['customer'] = $Customer;
853
                $nonMember['pref'] = $Customer->getPref()->getId();
854
                $app['session']->set($this->sessionKey, $nonMember);
855
856 3
                $customerAddresses = array();
857 3
                $customerAddresses[] = $CustomerAddress;
858
                $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses));
859
860
                return $app->redirect($app->url('shopping'));
861
862
            }
863
        }
864
865 1
        return $app->render('Shopping/nonmember.twig', array(
866 1
            'form' => $form->createView(),
867
        ));
868 6
    }
869
870
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
871
     * 複数配送処理がクリックされた場合の処理
872
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
873 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...
874
    {
875
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
876
        if (!$Order) {
877
            $app->addError('front.shopping.order.error');
878
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
879
        }
880
881
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
882
883
        if ('POST' === $request->getMethod()) {
884
            $form->handleRequest($request);
885
886
            if ($form->isValid()) {
887
                $data = $form->getData();
888
                $message = $data['message'];
889
                $Order->setMessage($message);
890
                // 受注情報を更新
891
                $app['orm.em']->flush();
892
                // 複数配送設定へリダイレクト
893
                return $app->redirect($app->url('shopping_shipping_multiple'));
894
            } else {
895
                return $app->render('Shopping/index.twig', array(
896
                    'form' => $form->createView(),
897
                    'Order' => $Order,
898
                ));
899
            }
900
        }
901
902
        return $app->redirect($app->url('shopping'));
903
    }
904
905
906
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
907
     * 複数配送処理
908
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
909
    public function shippingMultiple(Application $app, Request $request)
910
    {
911
912
        $cartService = $app['eccube.service.cart'];
913
914
        // カートチェック
915
        if (!$cartService->isLocked()) {
916
            // カートが存在しない、カートがロックされていない時はエラー
917
            return $app->redirect($app->url('cart'));
918
        }
919
920
        // カートチェック
921
        if (count($cartService->getCart()->getCartItems()) <= 0) {
922
            // カートが存在しない時はエラー
923
            return $app->redirect($app->url('cart'));
924
        }
925
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
926
        if (!$Order) {
927
            $app->addError('front.shopping.order.error');
928
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
929
        }
930
931
        // 複数配送時は商品毎でお届け先を設定する為、商品をまとめた数量を設定
932
        $compItemQuantities = array();
933 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...
934
            foreach ($Shipping->getShipmentItems() as $ShipmentItem) {
935
                $itemId = $ShipmentItem->getProductClass()->getId();
936
                $quantity = $ShipmentItem->getQuantity();
937
                if (array_key_exists($itemId, $compItemQuantities)) {
938
                    $compItemQuantities[$itemId] = $compItemQuantities[$itemId] + $quantity;
939
                } else {
940
                    $compItemQuantities[$itemId] = $quantity;
941
                }
942
            }
943
        }
944
945
        // 商品に紐づく商品情報を取得
946
        $shipmentItems = array();
947
        $productClassIds = array();
948
        foreach ($Order->getShippings() as $Shipping) {
949
            foreach ($Shipping->getShipmentItems() as $ShipmentItem) {
950
                if (!in_array($ShipmentItem->getProductClass()->getId(), $productClassIds)) {
951
                    $shipmentItems[] = $ShipmentItem;
952
                }
953
                $productClassIds[] = $ShipmentItem->getProductClass()->getId();
954
            }
955
        }
956
957
        $form = $app->form()->getForm();
958
        $form
959
            ->add('shipping_multiple', 'collection', array(
960
                'type' => 'shipping_multiple',
961
                'data' => $shipmentItems,
962
                'allow_add' => true,
963
                'allow_delete' => true,
964
            ));
965
966
        $errors = array();
967
968
        if ('POST' === $request->getMethod()) {
969
            $form->handleRequest($request);
970
            if ($form->isValid()) {
971
                $data = $form['shipping_multiple'];
972
973
                // 数量が超えていないか、同一でないとエラー
974
                $itemQuantities = array();
975
                foreach ($data as $mulitples) {
976
                    /** @var \Eccube\Entity\ShipmentItem $multipleItem */
977
                    $multipleItem = $mulitples->getData();
978 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...
979
                        foreach ($items as $item) {
980
                            $quantity = $item['quantity']->getData();
981
                            $itemId = $multipleItem->getProductClass()->getId();
982
                            if (array_key_exists($itemId, $itemQuantities)) {
983
                                $itemQuantities[$itemId] = $itemQuantities[$itemId] + $quantity;
984
                            } else {
985
                                $itemQuantities[$itemId] = $quantity;
986
                            }
987
                        }
988
                    }
989
                }
990
991
                foreach ($compItemQuantities as $key => $value) {
992
                    if (array_key_exists($key, $itemQuantities)) {
993
                        if ($itemQuantities[$key] != $value) {
994
995
                            $errors[] = array('message' => '数量の数が異なっています。');
996
997
                            // 対象がなければエラー
998
                            return $app->render('Shopping/shipping_multiple.twig', array(
999
                                'form' => $form->createView(),
1000
                                'shipmentItems' => $shipmentItems,
1001
                                'compItemQuantities' => $compItemQuantities,
1002
                                'errors' => $errors,
1003
                            ));
1004
1005
                        }
1006
                    }
1007
                }
1008
1009
                // お届け先情報をdelete/insert
1010
1011
                $shippings = $Order->getShippings();
1012
                foreach ($shippings as $Shipping) {
1013
                    $Order->removeShipping($Shipping);
1014
                    $app['orm.em']->remove($Shipping);
1015
                }
1016
1017
                foreach ($data as $mulitples) {
1018
1019
                    /** @var \Eccube\Entity\ShipmentItem $multipleItem */
1020
                    $multipleItem = $mulitples->getData();
1021
1022
                    foreach ($mulitples as $items) {
1023
                        foreach ($items as $item) {
1024
1025
                            // 追加された配送先情報を作成
1026
                            $Delivery = $multipleItem->getShipping()->getDelivery();
1027
1028
                            // 選択された情報を取得
1029
                            $data = $item['customer_address']->getData();
1030
                            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...
1031
                                // 会員の場合、CustomerAddressオブジェクトを取得
1032
                                $CustomerAddress = $data;
1033
                            } else {
1034
                                // 非会員の場合、選択されたindexが取得される
1035
                                $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey);
1036
                                $customerAddresses = unserialize($customerAddresses);
1037
                                $CustomerAddress = $customerAddresses[$data];
1038
                                $pref = $app['eccube.repository.master.pref']->find($CustomerAddress->getPref()->getId());
1039
                                $CustomerAddress->setPref($pref);
1040
                            }
1041
1042
                            $Shipping = new Shipping();
1043
1044
                            $Shipping
1045
                                ->setName01($CustomerAddress->getName01())
1046
                                ->setName02($CustomerAddress->getName02())
1047
                                ->setKana01($CustomerAddress->getKana01())
1048
                                ->setKana02($CustomerAddress->getKana02())
1049
                                ->setCompanyName($CustomerAddress->getCompanyName())
1050
                                ->setTel01($CustomerAddress->getTel01())
1051
                                ->setTel02($CustomerAddress->getTel02())
1052
                                ->setTel03($CustomerAddress->getTel03())
1053
                                ->setFax01($CustomerAddress->getFax01())
1054
                                ->setFax02($CustomerAddress->getFax02())
1055
                                ->setFax03($CustomerAddress->getFax03())
1056
                                ->setZip01($CustomerAddress->getZip01())
1057
                                ->setZip02($CustomerAddress->getZip02())
1058
                                ->setZipCode($CustomerAddress->getZip01() . $CustomerAddress->getZip02())
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
1059
                                ->setPref($CustomerAddress->getPref())
1060
                                ->setAddr01($CustomerAddress->getAddr01())
1061
                                ->setAddr02($CustomerAddress->getAddr02())
1062
                                ->setDelivery($Delivery)
1063
                                ->setDelFlg(Constant::DISABLED)
1064
                                ->setOrder($Order);
1065
1066
                            $app['orm.em']->persist($Shipping);
1067
1068
1069
                            $ShipmentItem = new ShipmentItem();
1070
1071
                            $ProductClass = $multipleItem->getProductClass();
1072
                            $Product = $multipleItem->getProduct();
1073
1074
1075
                            $quantity = $item['quantity']->getData();
1076
1077
                            $ShipmentItem->setShipping($Shipping)
1078
                                ->setOrder($Order)
1079
                                ->setProductClass($ProductClass)
1080
                                ->setProduct($Product)
1081
                                ->setProductName($Product->getName())
1082
                                ->setProductCode($ProductClass->getCode())
1083
                                ->setPrice($ProductClass->getPrice02())
1084
                                ->setQuantity($quantity);
1085
1086
                            $ClassCategory1 = $ProductClass->getClassCategory1();
1087
                            if (!is_null($ClassCategory1)) {
1088
                                $ShipmentItem->setClasscategoryName1($ClassCategory1->getName());
1089
                                $ShipmentItem->setClassName1($ClassCategory1->getClassName()->getName());
1090
                            }
1091
                            $ClassCategory2 = $ProductClass->getClassCategory2();
1092
                            if (!is_null($ClassCategory2)) {
1093
                                $ShipmentItem->setClasscategoryName2($ClassCategory2->getName());
1094
                                $ShipmentItem->setClassName2($ClassCategory2->getClassName()->getName());
1095
                            }
1096
                            $Shipping->addShipmentItem($ShipmentItem);
1097
                            $app['orm.em']->persist($ShipmentItem);
1098
1099
                            // 配送料金の設定
1100
                            $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
1101
1102
                        }
1103
                    }
1104
                }
1105
                // 配送先を更新
1106
                $app['orm.em']->flush();
1107
                return $app->redirect($app->url('shopping'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1108
            }
1109
        }
1110
1111
        return $app->render('Shopping/shipping_multiple.twig', array(
1112
            'form' => $form->createView(),
1113
            'shipmentItems' => $shipmentItems,
1114
            'compItemQuantities' => $compItemQuantities,
1115
            'errors' => $errors,
1116
        ));
1117
    }
1118
1119
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1120
     * 非会員用複数配送設定時の新規お届け先の設定
1121
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1122
    public function shippingMultipleEdit(Application $app, Request $request)
1123
    {
1124
1125
        // カートチェック
1126
        if (!$app['eccube.service.cart']->isLocked()) {
1127
            // カートが存在しない、カートがロックされていない時はエラー
1128
            return $app->redirect($app->url('cart'));
1129
        }
1130
1131
        $form = $app['form.factory']->createBuilder('shopping_shipping')->getForm();
1132
1133
        if ('POST' === $request->getMethod()) {
1134
1135
            $form->handleRequest($request);
1136
1137
            if ($form->isValid()) {
1138
                $data = $form->getData();
1139
1140
                // 非会員用Customerを取得
1141
                $Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey);
1142
1143
                $CustomerAddress = new CustomerAddress();
1144
                $CustomerAddress
1145
                    ->setCustomer($Customer)
1146
                    ->setName01($data['name01'])
1147
                    ->setName02($data['name02'])
1148
                    ->setKana01($data['kana01'])
1149
                    ->setKana02($data['kana02'])
1150
                    ->setCompanyName($data['company_name'])
1151
                    ->setTel01($data['tel01'])
1152
                    ->setTel02($data['tel02'])
1153
                    ->setTel03($data['tel03'])
1154
                    ->setZip01($data['zip01'])
1155
                    ->setZip02($data['zip02'])
1156
                    ->setZipCode($data['zip01'] . $data['zip02'])
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
1157
                    ->setPref($data['pref'])
1158
                    ->setAddr01($data['addr01'])
1159
                    ->setAddr02($data['addr02'])
1160
                    ->setDelFlg(Constant::DISABLED);
1161
                $Customer->addCustomerAddress($CustomerAddress);
1162
1163
1164
                // 非会員用のセッションに追加
1165
                $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey);
1166
                $customerAddresses = unserialize($customerAddresses);
1167
                $customerAddresses[] = $CustomerAddress;
1168
                $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses));
1169
1170
                return $app->redirect($app->url('shopping_shipping_multiple'));
1171
1172
            }
1173
        }
1174
1175
        return $app->render('Shopping/shipping_multiple_edit.twig', array(
1176
            'form' => $form->createView(),
1177
        ));
1178
1179
    }
1180
1181
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
1182
     * 購入エラー画面表示
1183
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1184
    public function shoppingError(Application $app)
1185
    {
1186
        return $app->render('Shopping/shopping_error.twig');
1187
    }
1188
1189
    /**
1190
     * 非会員でのお客様情報変更時の入力チェック
1191
     */
1192
    private function customerValidation($app, $data) {
1193
1194
        // 入力チェック
1195
        $errors = array();
1196
1197
        $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...
1198
            new Assert\NotBlank(),
1199
            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...
1200
            new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace'))
1201
        ));
1202
1203
        $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...
1204
            new Assert\NotBlank(),
1205
            new Assert\Length(array('max' => $app['config']['name_len'], )),
1206
            new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace'))
1207
        ));
1208
1209
        $errors[] = $app['validator']->validateValue($data['customer_company_name'], array(
1210
            new Assert\Length(array('max' => $app['config']['stext_len'])),
1211
        ));
1212
1213
        $errors[] = $app['validator']->validateValue($data['customer_tel01'], array(
1214
            new Assert\NotBlank(),
1215
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1216
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1217
        ));
1218
1219
        $errors[] = $app['validator']->validateValue($data['customer_tel02'], array(
1220
            new Assert\NotBlank(),
1221
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1222
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1223
        ));
1224
1225
        $errors[] = $app['validator']->validateValue($data['customer_tel03'], array(
1226
            new Assert\NotBlank(),
1227
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1228
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1229
        ));
1230
1231
        $errors[] = $app['validator']->validateValue($data['customer_zip01'], array(
1232
            new Assert\NotBlank(),
1233
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1234
            new Assert\Length(array('min' => $app['config']['zip01_len'], 'max' => $app['config']['zip01_len'])),
1235
        ));
1236
1237
        $errors[] = $app['validator']->validateValue($data['customer_zip02'], array(
1238
            new Assert\NotBlank(),
1239
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1240
            new Assert\Length(array('min' => $app['config']['zip02_len'], 'max' => $app['config']['zip02_len'])),
1241
        ));
1242
1243
        $errors[] = $app['validator']->validateValue($data['customer_addr01'], array(
1244
            new Assert\NotBlank(),
1245
            new Assert\Length(array('max' => $app['config']['address1_len'])),
1246
        ));
1247
1248
        $errors[] = $app['validator']->validateValue($data['customer_addr02'], array(
1249
            new Assert\NotBlank(),
1250
            new Assert\Length(array('max' => $app['config']['address2_len'])),
1251
        ));
1252
1253
        $errors[] = $app['validator']->validateValue($data['customer_email'], array(
1254
            new Assert\NotBlank(),
1255
            new Assert\Email(),
1256
        ));
1257
1258
        return $errors;
1259
1260
    }
1261
1262
}
1263