Completed
Push — master ( c4ab7a...cf81a7 )
by Kentaro
14:34
created

ShoppingController::shippingMultipleChange()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 31
Code Lines 19

Duplication

Lines 31
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 31
loc 31
ccs 0
cts 0
cp 0
rs 8.5806
cc 4
eloc 19
nc 4
nop 2
crap 20
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 11
    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 7
            }
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 8
        }
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 8
        return $app->render('Shopping/index.twig', array(
133 8
            'form' => $form->createView(),
134
            'Order' => $Order,
135
        ));
136 11
    }
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 3
    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 3
        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 3
                    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 3
                }
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 3
                $body = $app->renderView($MailTemplate->getFileName(), array(
217 3
                    'header' => $MailTemplate->getHeader(),
218 3
                    '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 3
                    ->setMailBody($body)
226 3
                    ->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 3
    }
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 1
    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 1
        return $app->render('Shopping/complete.twig', array(
263
            'orderId' => $orderId,
264
        ));
265 1
    }
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
                        'error' => true,
457
                    )
458
                );
459
            }
460
461
            // 選択されたお届け先情報を取得
462
            $CustomerAddress = $app['eccube.repository.customer_address']->findOneBy(array(
463
                'Customer' => $app->user(),
464
                'id' => $address,
465
            ));
466
            if (is_null($CustomerAddress)) {
467
                throw new NotFoundHttpException();
468
            }
469
470
            $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
471
            if (!$Order) {
472
                $app->addError('front.shopping.order.error');
473
474
                return $app->redirect($app->url('shopping_error'));
475
            }
476
477
            $Shipping = $Order->findShipping($id);
478
            if (!$Shipping) {
479
                throw new NotFoundHttpException();
480
            }
481
482
            // お届け先情報を更新
483
            $Shipping
484
                ->setName01($CustomerAddress->getName01())
485
                ->setName02($CustomerAddress->getName02())
486
                ->setKana01($CustomerAddress->getKana01())
487
                ->setKana02($CustomerAddress->getKana02())
488
                ->setCompanyName($CustomerAddress->getCompanyName())
489
                ->setTel01($CustomerAddress->getTel01())
490
                ->setTel02($CustomerAddress->getTel02())
491
                ->setTel03($CustomerAddress->getTel03())
492
                ->setFax01($CustomerAddress->getFax01())
493
                ->setFax02($CustomerAddress->getFax02())
494
                ->setFax03($CustomerAddress->getFax03())
495
                ->setZip01($CustomerAddress->getZip01())
496
                ->setZip02($CustomerAddress->getZip02())
497
                ->setZipCode($CustomerAddress->getZip01() . $CustomerAddress->getZip02())
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
498
                ->setPref($CustomerAddress->getPref())
499
                ->setAddr01($CustomerAddress->getAddr01())
500
                ->setAddr02($CustomerAddress->getAddr02());
501
502
            // 配送料金の設定
503
            $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
504
505
            // 配送先を更新
506
            $app['orm.em']->flush();
507
508
            return $app->redirect($app->url('shopping'));
509
510
        }
511
512
        return $app->render(
513
            'Shopping/shipping.twig',
514
            array(
515
                'Customer' => $app->user(),
516
                'shippingId' => $id,
517
                'error' => false,
518
            )
519
        );
520
    }
521
522
    /**
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...
523
     * お届け先の設定(非会員)がクリックされた場合の処理
524
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
525 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...
526
    {
527
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
528 5
        if (!$Order) {
529
            $app->addError('front.shopping.order.error');
530
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
531
        }
532
533
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
534
535
        if ('POST' === $request->getMethod()) {
536
            $form->handleRequest($request);
537
538
            if ($form->isValid()) {
539
                $data = $form->getData();
540 3
                $message = $data['message'];
541
                $Order->setMessage($message);
542
                // 受注情報を更新
543
                $app['orm.em']->flush();
544
                // お届け先設定一覧へリダイレクト
545
                return $app->redirect($app->url('shopping_shipping_edit', array('id' => $id)));
546
            } else {
547 1
                return $app->render('Shopping/index.twig', array(
548 1
                    'form' => $form->createView(),
549
                    'Order' => $Order,
550
                ));
551
            }
552
        }
553
554
        return $app->redirect($app->url('shopping'));
555 5
    }
556
557
558
    /**
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...
559
     * お届け先の設定(非会員でも使用する)
560
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
561 2
    public function shippingEdit(Application $app, Request $request, $id)
562
    {
563
        // 配送先住所最大値判定
564
        $Customer = $app->user();
565 2 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...
566
            error_log("hoge");
567
            $addressCurrNum = count($app->user()->getCustomerAddresses());
568
            $addressMax = $app['config']['deliv_addr_max'];
569
            if ($addressCurrNum >= $addressMax) {
570
                throw new NotFoundHttpException();
571
            }
572
        }
573
574
        // カートチェック
575
        if (!$app['eccube.service.cart']->isLocked()) {
576
            // カートが存在しない、カートがロックされていない時はエラー
577
            return $app->redirect($app->url('cart'));
578
        }
579
580
581
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
582 2
        if (!$Order) {
583
            $app->addError('front.shopping.order.error');
584
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
585
        }
586
587
        $Shipping = $Order->findShipping($id);
588 2
        if (!$Shipping) {
589
            throw new NotFoundHttpException();
590
        }
591
592
        // 会員の場合、お届け先情報を新規登録
593
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
594
            $builder = $app['form.factory']->createBuilder('shopping_shipping');
595
        } else {
596
            // 非会員の場合、お届け先を追加
597
            $builder = $app['form.factory']->createBuilder('shopping_shipping', $Shipping);
598
        }
599
600
        $form = $builder->getForm();
601
602
        if ('POST' === $request->getMethod()) {
603
604
            $form->handleRequest($request);
605
606
            if ($form->isValid()) {
607
                $data = $form->getData();
608
609
                // 会員の場合、お届け先情報を新規登録
610
                if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
611
                    $CustomerAddress = new CustomerAddress();
612
                    $CustomerAddress
613
                        ->setCustomer($app->user())
614
                        ->setName01($data['name01'])
615
                        ->setName02($data['name02'])
616
                        ->setKana01($data['kana01'])
617
                        ->setKana02($data['kana02'])
618
                        ->setCompanyName($data['company_name'])
619
                        ->setTel01($data['tel01'])
620
                        ->setTel02($data['tel02'])
621
                        ->setTel03($data['tel03'])
622
                        ->setZip01($data['zip01'])
623
                        ->setZip02($data['zip02'])
624
                        ->setZipCode($data['zip01'] . $data['zip02'])
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
625
                        ->setPref($data['pref'])
626
                        ->setAddr01($data['addr01'])
627
                        ->setAddr02($data['addr02'])
628
                        ->setDelFlg(Constant::DISABLED);
629
630
                    $app['orm.em']->persist($CustomerAddress);
631
632
                }
633
634
                $Shipping
635
                    ->setName01($data['name01'])
636
                    ->setName02($data['name02'])
637
                    ->setKana01($data['kana01'])
638
                    ->setKana02($data['kana02'])
639
                    ->setCompanyName($data['company_name'])
640
                    ->setTel01($data['tel01'])
641
                    ->setTel02($data['tel02'])
642
                    ->setTel03($data['tel03'])
643
                    ->setZip01($data['zip01'])
644
                    ->setZip02($data['zip02'])
645
                    ->setZipCode($data['zip01'] . $data['zip02'])
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
646
                    ->setPref($data['pref'])
647
                    ->setAddr01($data['addr01'])
648
                    ->setAddr02($data['addr02']);
649
650
                // 配送料金の設定
651
                $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
652
653
                // 配送先を更新
654
                $app['orm.em']->flush();
655
656
                return $app->redirect($app->url('shopping'));
657
658
            }
659
        }
660
661 1
        return $app->render('Shopping/shipping_edit.twig', array(
662 1
            'form' => $form->createView(),
663
            'shippingId' => $id,
664
        ));
665
666 2
    }
667
668
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
669
     * お客様情報の変更(非会員)
670
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
671
    public function customer(Application $app, Request $request)
672
    {
673
674
        if ($request->isXmlHttpRequest()) {
675
            try {
676
                $data = $request->request->all();
677
678
                // 入力チェック
679
                $errors = $this->customerValidation($app, $data);
680
681
                foreach ($errors as $error) {
682 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...
683
                        $response = new Response(json_encode('NG'), 500);
684
                        $response->headers->set('Content-Type', 'application/json');
685
                        return $response;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
686
                    }
687
                }
688
689
                $pref = $app['eccube.repository.master.pref']->findOneBy(array('name' => $data['customer_pref']));
690 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...
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
                $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
697
                if (!$Order) {
698
                    $app->addError('front.shopping.order.error');
699
                    return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
700
                }
701
702
                $Order
703
                    ->setName01($data['customer_name01'])
704
                    ->setName02($data['customer_name02'])
705
                    ->setCompanyName($data['customer_company_name'])
706
                    ->setTel01($data['customer_tel01'])
707
                    ->setTel02($data['customer_tel02'])
708
                    ->setTel03($data['customer_tel03'])
709
                    ->setZip01($data['customer_zip01'])
710
                    ->setZip02($data['customer_zip02'])
711
                    ->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...
712
                    ->setPref($pref)
713
                    ->setAddr01($data['customer_addr01'])
714
                    ->setAddr02($data['customer_addr02'])
715
                    ->setEmail($data['customer_email']);
716
717
                // 配送先を更新
718
                $app['orm.em']->flush();
719
720
                // 受注関連情報を最新状態に更新
721
                $app['orm.em']->refresh($Order);
722
723
                $response = new Response(json_encode('OK'));
724
                $response->headers->set('Content-Type', 'application/json');
725
726
            } catch (\Exception $e) {
727
                $app->log($e);
728
729
                $response = new Response(json_encode('NG'), 500);
730
                $response->headers->set('Content-Type', 'application/json');
731
732
            }
733
734
            return $response;
735
736
        }
737
738
    }
739
740
741
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
742
     * ログイン
743
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
744 2
    public function login(Application $app, Request $request)
745
    {
746
747
        if (!$app['eccube.service.cart']->isLocked()) {
748
            return $app->redirect($app->url('cart'));
749
        }
750
751
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
752
            return $app->redirect($app->url('shopping'));
753
        }
754
755
        /* @var $form \Symfony\Component\Form\FormInterface */
756
        $builder = $app['form.factory']->createNamedBuilder('', 'customer_login');
757
758 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...
759
            $Customer = $app->user();
760
            if ($Customer) {
761
                $builder->get('login_email')->setData($Customer->getEmail());
762
            }
763
        }
764
765
        $form = $builder->getForm();
766
767
        return $app->render('Shopping/login.twig', array(
768
            'error' => $app['security.last_error']($request),
769
            'form' => $form->createView(),
770
        ));
771 2
    }
772
773
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
774
     * 非会員処理
775
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
776 11
    public function nonmember(Application $app, Request $request)
777
    {
778
779
        $cartService = $app['eccube.service.cart'];
780
781
        // カートチェック
782
        if (!$cartService->isLocked()) {
783
            // カートが存在しない、カートがロックされていない時はエラー
784
            return $app->redirect($app->url('cart'));
785
        }
786
787
        // ログイン済みの場合は, 購入画面へリダイレクト.
788
        if ($app->isGranted('ROLE_USER')) {
789
            return $app->redirect($app->url('shopping'));
790
        }
791
792
        // カートチェック
793
        if (count($cartService->getCart()->getCartItems()) <= 0) {
794
            // カートが存在しない時はエラー
795
            return $app->redirect($app->url('cart'));
796
        }
797
798
        $form = $app['form.factory']->createBuilder('nonmember')->getForm();
799
800
        if ('POST' === $request->getMethod()) {
801
            $form->handleRequest($request);
802
            if ($form->isValid()) {
803
                $data = $form->getData();
804
                $Customer = new Customer();
805
                $Customer
806 8
                    ->setName01($data['name01'])
807 8
                    ->setName02($data['name02'])
808 8
                    ->setKana01($data['kana01'])
809 8
                    ->setKana02($data['kana02'])
810 8
                    ->setCompanyName($data['company_name'])
811 8
                    ->setEmail($data['email'])
812 8
                    ->setTel01($data['tel01'])
813 8
                    ->setTel02($data['tel02'])
814 8
                    ->setTel03($data['tel03'])
815 8
                    ->setZip01($data['zip01'])
816 8
                    ->setZip02($data['zip02'])
817 8
                    ->setZipCode($data['zip01'] . $data['zip02'])
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
818 8
                    ->setPref($data['pref'])
819 8
                    ->setAddr01($data['addr01'])
820
                    ->setAddr02($data['addr02']);
821
822
                // 非会員複数配送用
823
                $CustomerAddress = new CustomerAddress();
824
                $CustomerAddress
825 8
                    ->setCustomer($Customer)
826 8
                    ->setName01($data['name01'])
827 8
                    ->setName02($data['name02'])
828 8
                    ->setKana01($data['kana01'])
829 8
                    ->setKana02($data['kana02'])
830 8
                    ->setCompanyName($data['company_name'])
831 8
                    ->setTel01($data['tel01'])
832 8
                    ->setTel02($data['tel02'])
833 8
                    ->setTel03($data['tel03'])
834 8
                    ->setZip01($data['zip01'])
835 8
                    ->setZip02($data['zip02'])
836 8
                    ->setZipCode($data['zip01'] . $data['zip02'])
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
837 8
                    ->setPref($data['pref'])
838 8
                    ->setAddr01($data['addr01'])
839 8
                    ->setAddr02($data['addr02'])
840
                    ->setDelFlg(Constant::DISABLED);
841
                $Customer->addCustomerAddress($CustomerAddress);
842
843
                // 受注情報を取得
844
                $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
845
846
                // 初回アクセス(受注データがない)の場合は, 受注情報を作成
847
                if (is_null($Order)) {
848
                    // 受注情報を作成
849
                    $app['eccube.service.shopping']->createOrder($Customer);
850
                }
851
852
                // 非会員用セッションを作成
853 8
                $nonMember = array();
854 8
                $nonMember['customer'] = $Customer;
855
                $nonMember['pref'] = $Customer->getPref()->getId();
856
                $app['session']->set($this->sessionKey, $nonMember);
857
858 8
                $customerAddresses = array();
859 8
                $customerAddresses[] = $CustomerAddress;
860
                $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses));
861
862
                return $app->redirect($app->url('shopping'));
863
864
            }
865
        }
866
867 1
        return $app->render('Shopping/nonmember.twig', array(
868 1
            'form' => $form->createView(),
869
        ));
870 11
    }
871
872
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
873
     * 複数配送処理がクリックされた場合の処理
874
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
875 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...
876
    {
877
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
878
        if (!$Order) {
879
            $app->addError('front.shopping.order.error');
880
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
881
        }
882
883
        $form = $app['eccube.service.shopping']->getShippingForm($Order);
884
885
        if ('POST' === $request->getMethod()) {
886
            $form->handleRequest($request);
887
888
            if ($form->isValid()) {
889
                $data = $form->getData();
890
                $message = $data['message'];
891
                $Order->setMessage($message);
892
                // 受注情報を更新
893
                $app['orm.em']->flush();
894
                // 複数配送設定へリダイレクト
895
                return $app->redirect($app->url('shopping_shipping_multiple'));
896
            } else {
897
                return $app->render('Shopping/index.twig', array(
898
                    'form' => $form->createView(),
899
                    'Order' => $Order,
900
                ));
901
            }
902
        }
903
904
        return $app->redirect($app->url('shopping'));
905
    }
906
907
908
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
909
     * 複数配送処理
910
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
911
    public function shippingMultiple(Application $app, Request $request)
912
    {
913
914
        $cartService = $app['eccube.service.cart'];
915
916
        // カートチェック
917
        if (!$cartService->isLocked()) {
918
            // カートが存在しない、カートがロックされていない時はエラー
919
            return $app->redirect($app->url('cart'));
920
        }
921
922
        // カートチェック
923
        if (count($cartService->getCart()->getCartItems()) <= 0) {
924
            // カートが存在しない時はエラー
925
            return $app->redirect($app->url('cart'));
926
        }
927
        $Order = $app['eccube.service.shopping']->getOrder($app['config']['order_processing']);
928
        if (!$Order) {
929
            $app->addError('front.shopping.order.error');
930
            return $app->redirect($app->url('shopping_error'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
931
        }
932
933
        // 複数配送時は商品毎でお届け先を設定する為、商品をまとめた数量を設定
934
        $compItemQuantities = array();
935 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...
936
            foreach ($Shipping->getShipmentItems() as $ShipmentItem) {
937
                $itemId = $ShipmentItem->getProductClass()->getId();
938
                $quantity = $ShipmentItem->getQuantity();
939
                if (array_key_exists($itemId, $compItemQuantities)) {
940
                    $compItemQuantities[$itemId] = $compItemQuantities[$itemId] + $quantity;
941
                } else {
942
                    $compItemQuantities[$itemId] = $quantity;
943
                }
944
            }
945
        }
946
947
        // 商品に紐づく商品情報を取得
948
        $shipmentItems = array();
949
        $productClassIds = array();
950
        foreach ($Order->getShippings() as $Shipping) {
951
            foreach ($Shipping->getShipmentItems() as $ShipmentItem) {
952
                if (!in_array($ShipmentItem->getProductClass()->getId(), $productClassIds)) {
953
                    $shipmentItems[] = $ShipmentItem;
954
                }
955
                $productClassIds[] = $ShipmentItem->getProductClass()->getId();
956
            }
957
        }
958
959
        $form = $app->form()->getForm();
960
        $form
961
            ->add('shipping_multiple', 'collection', array(
962
                'type' => 'shipping_multiple',
963
                'data' => $shipmentItems,
964
                'allow_add' => true,
965
                'allow_delete' => true,
966
            ));
967
968
        $errors = array();
969
970
        if ('POST' === $request->getMethod()) {
971
            $form->handleRequest($request);
972
            if ($form->isValid()) {
973
                $data = $form['shipping_multiple'];
974
975
                // 数量が超えていないか、同一でないとエラー
976
                $itemQuantities = array();
977
                foreach ($data as $mulitples) {
978
                    /** @var \Eccube\Entity\ShipmentItem $multipleItem */
979
                    $multipleItem = $mulitples->getData();
980 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...
981
                        foreach ($items as $item) {
982
                            $quantity = $item['quantity']->getData();
983
                            $itemId = $multipleItem->getProductClass()->getId();
984
                            if (array_key_exists($itemId, $itemQuantities)) {
985
                                $itemQuantities[$itemId] = $itemQuantities[$itemId] + $quantity;
986
                            } else {
987
                                $itemQuantities[$itemId] = $quantity;
988
                            }
989
                        }
990
                    }
991
                }
992
993
                foreach ($compItemQuantities as $key => $value) {
994
                    if (array_key_exists($key, $itemQuantities)) {
995
                        if ($itemQuantities[$key] != $value) {
996
997
                            $errors[] = array('message' => '数量の数が異なっています。');
998
999
                            // 対象がなければエラー
1000
                            return $app->render('Shopping/shipping_multiple.twig', array(
1001
                                'form' => $form->createView(),
1002
                                'shipmentItems' => $shipmentItems,
1003
                                'compItemQuantities' => $compItemQuantities,
1004
                                'errors' => $errors,
1005
                            ));
1006
1007
                        }
1008
                    }
1009
                }
1010
1011
                // お届け先情報をdelete/insert
1012
1013
                $shippings = $Order->getShippings();
1014
                foreach ($shippings as $Shipping) {
1015
                    $Order->removeShipping($Shipping);
1016
                    $app['orm.em']->remove($Shipping);
1017
                }
1018
1019
                foreach ($data as $mulitples) {
1020
1021
                    /** @var \Eccube\Entity\ShipmentItem $multipleItem */
1022
                    $multipleItem = $mulitples->getData();
1023
1024
                    foreach ($mulitples as $items) {
1025
                        foreach ($items as $item) {
1026
1027
                            // 追加された配送先情報を作成
1028
                            $Delivery = $multipleItem->getShipping()->getDelivery();
1029
1030
                            // 選択された情報を取得
1031
                            $data = $item['customer_address']->getData();
1032
                            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...
1033
                                // 会員の場合、CustomerAddressオブジェクトを取得
1034
                                $CustomerAddress = $data;
1035
                            } else {
1036
                                // 非会員の場合、選択されたindexが取得される
1037
                                $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey);
1038
                                $customerAddresses = unserialize($customerAddresses);
1039
                                $CustomerAddress = $customerAddresses[$data];
1040
                                $pref = $app['eccube.repository.master.pref']->find($CustomerAddress->getPref()->getId());
1041
                                $CustomerAddress->setPref($pref);
1042
                            }
1043
1044
                            $Shipping = new Shipping();
1045
1046
                            $Shipping
1047
                                ->setName01($CustomerAddress->getName01())
1048
                                ->setName02($CustomerAddress->getName02())
1049
                                ->setKana01($CustomerAddress->getKana01())
1050
                                ->setKana02($CustomerAddress->getKana02())
1051
                                ->setCompanyName($CustomerAddress->getCompanyName())
1052
                                ->setTel01($CustomerAddress->getTel01())
1053
                                ->setTel02($CustomerAddress->getTel02())
1054
                                ->setTel03($CustomerAddress->getTel03())
1055
                                ->setFax01($CustomerAddress->getFax01())
1056
                                ->setFax02($CustomerAddress->getFax02())
1057
                                ->setFax03($CustomerAddress->getFax03())
1058
                                ->setZip01($CustomerAddress->getZip01())
1059
                                ->setZip02($CustomerAddress->getZip02())
1060
                                ->setZipCode($CustomerAddress->getZip01() . $CustomerAddress->getZip02())
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
1061
                                ->setPref($CustomerAddress->getPref())
1062
                                ->setAddr01($CustomerAddress->getAddr01())
1063
                                ->setAddr02($CustomerAddress->getAddr02())
1064
                                ->setDelivery($Delivery)
1065
                                ->setDelFlg(Constant::DISABLED)
1066
                                ->setOrder($Order);
1067
1068
                            $app['orm.em']->persist($Shipping);
1069
1070
1071
                            $ShipmentItem = new ShipmentItem();
1072
1073
                            $ProductClass = $multipleItem->getProductClass();
1074
                            $Product = $multipleItem->getProduct();
1075
1076
1077
                            $quantity = $item['quantity']->getData();
1078
1079
                            $ShipmentItem->setShipping($Shipping)
1080
                                ->setOrder($Order)
1081
                                ->setProductClass($ProductClass)
1082
                                ->setProduct($Product)
1083
                                ->setProductName($Product->getName())
1084
                                ->setProductCode($ProductClass->getCode())
1085
                                ->setPrice($ProductClass->getPrice02())
1086
                                ->setQuantity($quantity);
1087
1088
                            $ClassCategory1 = $ProductClass->getClassCategory1();
1089
                            if (!is_null($ClassCategory1)) {
1090
                                $ShipmentItem->setClasscategoryName1($ClassCategory1->getName());
1091
                                $ShipmentItem->setClassName1($ClassCategory1->getClassName()->getName());
1092
                            }
1093
                            $ClassCategory2 = $ProductClass->getClassCategory2();
1094
                            if (!is_null($ClassCategory2)) {
1095
                                $ShipmentItem->setClasscategoryName2($ClassCategory2->getName());
1096
                                $ShipmentItem->setClassName2($ClassCategory2->getClassName()->getName());
1097
                            }
1098
                            $Shipping->addShipmentItem($ShipmentItem);
1099
                            $app['orm.em']->persist($ShipmentItem);
1100
1101
                            // 配送料金の設定
1102
                            $app['eccube.service.shopping']->setShippingDeliveryFee($Shipping);
1103
1104
                        }
1105
                    }
1106
                }
1107
                // 配送先を更新
1108
                $app['orm.em']->flush();
1109
                return $app->redirect($app->url('shopping'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
1110
            }
1111
        }
1112
1113
        return $app->render('Shopping/shipping_multiple.twig', array(
1114
            'form' => $form->createView(),
1115
            'shipmentItems' => $shipmentItems,
1116
            'compItemQuantities' => $compItemQuantities,
1117
            'errors' => $errors,
1118
        ));
1119
    }
1120
1121
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$request" missing
Loading history...
1122
     * 非会員用複数配送設定時の新規お届け先の設定
1123
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1124
    public function shippingMultipleEdit(Application $app, Request $request)
1125
    {
1126
1127
        // カートチェック
1128
        if (!$app['eccube.service.cart']->isLocked()) {
1129
            // カートが存在しない、カートがロックされていない時はエラー
1130
            return $app->redirect($app->url('cart'));
1131
        }
1132
1133
        $form = $app['form.factory']->createBuilder('shopping_shipping')->getForm();
1134
1135
        if ('POST' === $request->getMethod()) {
1136
1137
            $form->handleRequest($request);
1138
1139
            if ($form->isValid()) {
1140
                $data = $form->getData();
1141
1142
                // 非会員用Customerを取得
1143
                $Customer = $app['eccube.service.shopping']->getNonMember($this->sessionKey);
1144
1145
                $CustomerAddress = new CustomerAddress();
1146
                $CustomerAddress
1147
                    ->setCustomer($Customer)
1148
                    ->setName01($data['name01'])
1149
                    ->setName02($data['name02'])
1150
                    ->setKana01($data['kana01'])
1151
                    ->setKana02($data['kana02'])
1152
                    ->setCompanyName($data['company_name'])
1153
                    ->setTel01($data['tel01'])
1154
                    ->setTel02($data['tel02'])
1155
                    ->setTel03($data['tel03'])
1156
                    ->setZip01($data['zip01'])
1157
                    ->setZip02($data['zip02'])
1158
                    ->setZipCode($data['zip01'] . $data['zip02'])
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
1159
                    ->setPref($data['pref'])
1160
                    ->setAddr01($data['addr01'])
1161
                    ->setAddr02($data['addr02'])
1162
                    ->setDelFlg(Constant::DISABLED);
1163
                $Customer->addCustomerAddress($CustomerAddress);
1164
1165
1166
                // 非会員用のセッションに追加
1167
                $customerAddresses = $app['session']->get($this->sessionCustomerAddressKey);
1168
                $customerAddresses = unserialize($customerAddresses);
1169
                $customerAddresses[] = $CustomerAddress;
1170
                $app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses));
1171
1172
                return $app->redirect($app->url('shopping_shipping_multiple'));
1173
1174
            }
1175
        }
1176
1177
        return $app->render('Shopping/shipping_multiple_edit.twig', array(
1178
            'form' => $form->createView(),
1179
        ));
1180
1181
    }
1182
1183
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
1184
     * 購入エラー画面表示
1185
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
1186 1
    public function shoppingError(Application $app)
1187
    {
1188
        return $app->render('Shopping/shopping_error.twig');
1189 1
    }
1190
1191
    /**
1192
     * 非会員でのお客様情報変更時の入力チェック
1193
     */
1194
    private function customerValidation($app, $data) {
1195
1196
        // 入力チェック
1197
        $errors = array();
1198
1199
        $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...
1200
            new Assert\NotBlank(),
1201
            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...
1202
            new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace'))
1203
        ));
1204
1205
        $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...
1206
            new Assert\NotBlank(),
1207
            new Assert\Length(array('max' => $app['config']['name_len'], )),
1208
            new Assert\Regex(array('pattern' => '/^[^\s ]+$/u', 'message' => 'form.type.name.firstname.nothasspace'))
1209
        ));
1210
1211
        $errors[] = $app['validator']->validateValue($data['customer_company_name'], array(
1212
            new Assert\Length(array('max' => $app['config']['stext_len'])),
1213
        ));
1214
1215
        $errors[] = $app['validator']->validateValue($data['customer_tel01'], array(
1216
            new Assert\NotBlank(),
1217
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1218
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1219
        ));
1220
1221
        $errors[] = $app['validator']->validateValue($data['customer_tel02'], array(
1222
            new Assert\NotBlank(),
1223
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1224
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1225
        ));
1226
1227
        $errors[] = $app['validator']->validateValue($data['customer_tel03'], array(
1228
            new Assert\NotBlank(),
1229
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1230
            new Assert\Length(array('max' => $app['config']['tel_len'], 'min' => $app['config']['tel_len_min'])),
1231
        ));
1232
1233
        $errors[] = $app['validator']->validateValue($data['customer_zip01'], array(
1234
            new Assert\NotBlank(),
1235
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1236
            new Assert\Length(array('min' => $app['config']['zip01_len'], 'max' => $app['config']['zip01_len'])),
1237
        ));
1238
1239
        $errors[] = $app['validator']->validateValue($data['customer_zip02'], array(
1240
            new Assert\NotBlank(),
1241
            new Assert\Type(array('type' => 'numeric', 'message' => 'form.type.numeric.invalid')),
1242
            new Assert\Length(array('min' => $app['config']['zip02_len'], 'max' => $app['config']['zip02_len'])),
1243
        ));
1244
1245
        $errors[] = $app['validator']->validateValue($data['customer_addr01'], array(
1246
            new Assert\NotBlank(),
1247
            new Assert\Length(array('max' => $app['config']['address1_len'])),
1248
        ));
1249
1250
        $errors[] = $app['validator']->validateValue($data['customer_addr02'], array(
1251
            new Assert\NotBlank(),
1252
            new Assert\Length(array('max' => $app['config']['address2_len'])),
1253
        ));
1254
1255
        $errors[] = $app['validator']->validateValue($data['customer_email'], array(
1256
            new Assert\NotBlank(),
1257
            new Assert\Email(),
1258
        ));
1259
1260
        return $errors;
1261
1262
    }
1263
1264
}
1265