Failed Conditions
Push — master ( 3ed8ee...0f3867 )
by Kentaro
19:22
created

ShoppingController::shoppingError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

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