Failed Conditions
Pull Request — master (#1454)
by Kentaro
27:10
created

CartController::index()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 39
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5
Metric Value
dl 0
loc 39
ccs 7
cts 7
cp 1
rs 8.439
cc 5
eloc 23
nc 9
nop 1
crap 5
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\Exception\CartException;
29
use Symfony\Component\HttpFoundation\Request;
30
31
class CartController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
32
{
33 1
    public function index(Application $app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
34
    {
35
        $Cart = $app['eccube.service.cart']->getCart();
36
37
        /* @var $BaseInfo \Eccube\Entity\BaseInfo */
38
        /* @var $Cart \Eccube\Entity\Cart */
39
        $BaseInfo = $app['eccube.repository.base_info']->get();
40
41 1
        $isDeliveryFree = false;
42 1
        $least = 0;
43 1
        $quantity = 0;
44
        if ($BaseInfo->getDeliveryFreeAmount()) {
45
            if ($BaseInfo->getDeliveryFreeAmount() <= $Cart->getTotalPrice()) {
46
                // 送料無料(金額)を超えている
47
                $isDeliveryFree = true;
48
            } else {
49
                $least = $BaseInfo->getDeliveryFreeAmount() - $Cart->getTotalPrice();
50
            }
51
        }
52
53
        if ($BaseInfo->getDeliveryFreeQuantity()) {
54
            if ($BaseInfo->getDeliveryFreeQuantity() <= $Cart->getTotalQuantity()) {
55
                // 送料無料(個数)を超えている
56
                $isDeliveryFree = true;
57
            } else {
58
                $quantity = $BaseInfo->getDeliveryFreeQuantity() - $Cart->getTotalQuantity();
59
            }
60
        }
61
62
        return $app->render(
63 1
            'Cart/index.twig',
64
            array(
65
                'Cart' => $Cart,
66
                'least' => $least,
67
                'quantity' => $quantity,
68
                'is_delivery_free' => $isDeliveryFree,
69 1
            )
70
        );
71 1
    }
72
73 21
    public function add(Application $app, Request $request)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
74
    {
75
        $productClassId = $request->get('product_class_id');
76
        $quantity = $request->request->has('quantity') ? $request->get('quantity') : 1;
77
        try {
78
            $app['eccube.service.cart']->addProduct($productClassId, $quantity)->save();
79
        } catch (CartException $e) {
80
            $app->addRequestError($e->getMessage());
81 21
        }
82
83
        return $app->redirect($app->url('cart'));
84 21
    }
85
86 1 View Code Duplication
    public function up(Application $app, $productClassId)
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...
introduced by
Missing function doc comment
Loading history...
87
    {
88
        $this->isTokenValid($app);
89
90
        try {
91
            $app['eccube.service.cart']->upProductQuantity($productClassId)->save();
92
        } catch (CartException $e) {
93
            $app->addRequestError($e->getMessage());
94 1
        }
95
96
        return $app->redirect($app->url('cart'));
97 1
    }
98
99 1 View Code Duplication
    public function down(Application $app, $productClassId)
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...
introduced by
Missing function doc comment
Loading history...
100
    {
101
        $this->isTokenValid($app);
102
103
        try {
104
            $app['eccube.service.cart']->downProductQuantity($productClassId)->save();
105
        } catch (CartException $e) {
106
            $app->addRequestError($e->getMessage());
107 1
        }
108
109
        return $app->redirect($app->url('cart'));
110 1
    }
111
112 1
    public function remove(Application $app, $productClassId)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
113
    {
114
        $this->isTokenValid($app);
115
116
        $app['eccube.service.cart']->removeProduct($productClassId)->save();
117
118
        return $app->redirect($app->url('cart'));
119 1
    }
120
121 1
    public function setQuantity(Application $app, $productClassId, $quantity)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
122
    {
123
        $this->isTokenValid($app);
124
125
        $app['eccube.service.cart']->setProductQuantity($productClassId, $quantity)->save();
126
127
        return $app->redirect($app->url('cart'));
128 1
    }
129
130
    public function buystep(Application $app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
131
    {
132
        $app['eccube.service.cart']->lock();
133
        $app['eccube.service.cart']->save();
134
135
        return $app->redirect($app->url('shopping'));
136
    }
137
}
138