Completed
Push — admin_masterdata ( 2f999d )
by NOBU
18:14
created

src/Eccube/Controller/Mypage/MypageController.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * This program is free software; you can redistribute it and/or
11
 * modify it under the terms of the GNU General Public License
12
 * as published by the Free Software Foundation; either version 2
13
 * of the License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23
 */
24
25
namespace Eccube\Controller\Mypage;
26
27
use Eccube\Application;
28
use Eccube\Common\Constant;
29
use Eccube\Controller\AbstractController;
30
use Eccube\Exception\CartException;
31
use Symfony\Component\HttpFoundation\Request;
32
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
33
34
class MypageController extends AbstractController
35
{
36
    public function login(Application $app, Request $request)
37
    {
38
        if ($app->isGranted('IS_AUTHENTICATED_FULLY')) {
39
            return $app->redirect($app->url('mypage'));
40
        }
41
42
        /* @var $form \Symfony\Component\Form\FormInterface */
43
        $builder = $app['form.factory']
44
            ->createNamedBuilder('', 'customer_login');
45
46 View Code Duplication
        if ($app->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
47
            $Customer = $app->user();
48
            if ($Customer) {
49
                $builder->get('login_email')->setData($Customer->getEmail());
50
            }
51
        }
52
53
        $form = $builder->getForm();
54
55
        return $app->render('Mypage/login.twig', array(
56
            'error' => $app['security.last_error']($request),
57
            'form' => $form->createView(),
58
        ));
59
    }
60
61
    /**
62
     * @param Application $app
63
     * @param Request     $request
64
     *
65
     * @return string
66
     */
67
    public function index(Application $app, Request $request)
68
    {
69
        $Customer = $app['user'];
70
71
        $app['orm.em']
72
            ->getFilters()
73
            ->enable('incomplete_order_status_hidden');
74
75
        // paginator
76
        $qb = $app['eccube.repository.order']->getQueryBuilderByCustomer($Customer);
77
        $pagination = $app['paginator']()->paginate(
78
            $qb,
79
            $request->get('pageno', 1),
80
            $app['config']['search_pmax']
81
        );
82
83
        return $app->render('Mypage/index.twig', array(
84
            'pagination' => $pagination,
85
        ));
86
    }
87
88
    /**
89
     * @param Application $app
90
     * @param Request     $request
91
     *
92
     * @return string
93
     */
94
    public function history(Application $app, Request $request, $id)
95
    {
96
97
        /* @var $softDeleteFilter \Eccube\Doctrine\Filter\SoftDeleteFilter */
98
        $softDeleteFilter = $app['orm.em']->getFilters()->getFilter('soft_delete');
99
        $softDeleteFilter->setExcludes(array(
100
            'Eccube\Entity\ProductClass',
101
        ));
102
103
        $Order = $app['eccube.repository.order']->findOneBy(array(
104
            'id' => $id,
105
            'Customer' => $app->user(),
106
        ));
107
        if (!$Order) {
108
            throw new NotFoundHttpException();
109
        }
110
111
        return $app->render('Mypage/history.twig', array(
112
            'Order' => $Order,
113
        ));
114
    }
115
116
    /**
117
     * @param Application $app
118
     * @param Request     $request
119
     * @param id     $id
120
     *
121
     * @return string
122
     */
123 1
    public function order(Application $app, Request $request, $id)
124
    {
125
126
        $this->isTokenValid($app);
127
128
        $Customer = $app->user();
129
130
        /* @var $Order \Eccube\Entity\Order */
131
        $Order = $app['eccube.repository.order']->findOneBy(array(
132
            'id' => $id,
133
            'Customer' => $Customer,
134
        ));
135 1
        if (!$Order) {
136
            throw new NotFoundHttpException();
137
        }
138
139 1
        foreach ($Order->getOrderDetails() as $OrderDetail) {
140
            try {
141
                if ($OrderDetail->getProduct()) {
142
                    $app['eccube.service.cart']->addProduct($OrderDetail->getProductClass()->getId(), $OrderDetail->getQuantity())->save();
143
                } else {
144
                    $app->addRequestError('cart.product.delete');
145 1
                }
146
            } catch (CartException $e) {
147
                $app->addRequestError($e->getMessage());
148 1
            }
149
        }
150
151
        return $app->redirect($app->url('cart'));
152 1
    }
153
154
    /**
155
     * @param Application $app
156
     * @param Request     $request
157
     *
158
     * @return string
159
     */
160 1
    public function favorite(Application $app, Request $request)
161
    {
162
        $BaseInfo = $app['eccube.repository.base_info']->get();
163
164
        if ($BaseInfo->getOptionFavoriteProduct() == Constant::ENABLED) {
165
            $Customer = $app->user();
166
167
            // paginator
168
            $qb = $app['eccube.repository.product']->getFavoriteProductQueryBuilderByCustomer($Customer);
169
            $pagination = $app['paginator']()->paginate(
170
                $qb,
171 1
                $request->get('pageno', 1),
172 1
                $app['config']['search_pmax']
173
            );
174
175 1
            return $app->render('Mypage/favorite.twig', array(
176
                'pagination' => $pagination,
177
            ));
178
        } else {
179
            throw new NotFoundHttpException();
180
        }
181 1
    }
182
183
    /**
0 ignored issues
show
Doc comment for parameter "$id" missing
Loading history...
184
     * @param Application $app
185
     * @param Request     $request
186
     *
187
     * @return string
188
     */
189 1
    public function delete(Application $app, $id)
190
    {
191
        $this->isTokenValid($app);
192
193
        $Customer = $app->user();
194
195
        $Product = $app['eccube.repository.product']->find($id);
196 1
        if ($Product) {
197
            $app['eccube.repository.customer_favorite_product']->deleteFavorite($Customer, $Product);
198
        }
199
200
        return $app->redirect($app->url('mypage_favorite'));
201 1
    }
202
}
203