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
|
|
|
namespace Eccube\Controller\Admin\Customer; |
25
|
|
|
|
26
|
|
|
use Eccube\Controller\AbstractController; |
27
|
|
|
use Eccube\Entity\CustomerAddress; |
28
|
|
|
use Eccube\Event\EccubeEvents; |
29
|
|
|
use Eccube\Event\EventArgs; |
30
|
|
|
use Eccube\Form\Type\Admin\CustomerType; |
31
|
|
|
use Eccube\Repository\CustomerRepository; |
32
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
33
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
34
|
|
|
use Symfony\Component\HttpFoundation\Request; |
35
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
36
|
|
|
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @Route(service=CustomerEditController::class) |
40
|
|
|
*/ |
41
|
|
|
class CustomerEditController extends AbstractController |
42
|
|
|
{ |
43
|
|
|
/** |
44
|
|
|
* @var CustomerRepository |
45
|
|
|
*/ |
46
|
|
|
protected $customerRepository; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var EncoderFactoryInterface |
50
|
|
|
*/ |
51
|
|
|
protected $encoderFactory; |
52
|
|
|
|
53
|
6 |
|
public function __construct( |
54
|
|
|
CustomerRepository $customerRepository, |
55
|
|
|
EncoderFactoryInterface $encoderFactory |
56
|
|
|
) { |
57
|
6 |
|
$this->customerRepository = $customerRepository; |
58
|
6 |
|
$this->encoderFactory = $encoderFactory; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
|
|
|
|
62
|
|
|
* @Route("/%eccube_admin_route%/customer/new", name="admin_customer_new") |
63
|
|
|
* @Route("/%eccube_admin_route%/customer/{id}/edit", requirements={"id" = "\d+"}, name="admin_customer_edit") |
64
|
|
|
* @Template("@admin/Customer/edit.twig") |
65
|
|
|
*/ |
|
|
|
|
66
|
6 |
|
public function index(Request $request, $id = null) |
67
|
|
|
{ |
68
|
|
|
//$this->entityManager->getFilters()->enable('incomplete_order_status_hidden'); |
|
|
|
|
69
|
|
|
// 編集 |
70
|
6 |
|
if ($id) { |
71
|
4 |
|
$Customer = $this->customerRepository |
72
|
4 |
|
->find($id); |
73
|
|
|
|
74
|
4 |
|
if (is_null($Customer)) { |
75
|
|
|
throw new NotFoundHttpException(); |
76
|
|
|
} |
77
|
|
|
// 編集用にデフォルトパスワードをセット |
78
|
4 |
|
$previous_password = $Customer->getPassword(); |
79
|
4 |
|
$Customer->setPassword($this->eccubeConfig['eccube_default_password']); |
80
|
|
|
// 新規登録 |
81
|
|
|
} else { |
82
|
2 |
|
$Customer = $this->customerRepository->newCustomer(); |
83
|
2 |
|
$CustomerAddress = new CustomerAddress(); |
84
|
2 |
|
$Customer->setBuyTimes(0); |
85
|
2 |
|
$Customer->setBuyTotal(0); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
// 会員登録フォーム |
89
|
6 |
|
$builder = $this->formFactory |
90
|
6 |
|
->createBuilder(CustomerType::class, $Customer); |
91
|
|
|
|
92
|
6 |
|
$event = new EventArgs( |
93
|
|
|
[ |
94
|
6 |
|
'builder' => $builder, |
95
|
6 |
|
'Customer' => $Customer, |
96
|
|
|
], |
97
|
6 |
|
$request |
98
|
|
|
); |
99
|
6 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_CUSTOMER_EDIT_INDEX_INITIALIZE, $event); |
100
|
|
|
|
101
|
6 |
|
$form = $builder->getForm(); |
102
|
|
|
|
103
|
6 |
|
$form->handleRequest($request); |
104
|
|
|
|
105
|
6 |
|
if ($form->isSubmitted()) { |
106
|
2 |
|
if ($form->isValid()) { |
107
|
2 |
|
log_info('会員登録開始', [$Customer->getId()]); |
108
|
|
|
|
109
|
2 |
|
$encoder = $this->encoderFactory->getEncoder($Customer); |
110
|
|
|
|
111
|
2 |
|
if ($Customer->getId() === null) { |
112
|
1 |
|
$Customer->setSalt($encoder->createSalt()); |
113
|
1 |
|
$Customer->setSecretKey($this->customerRepository->getUniqueSecretKey()); |
114
|
|
|
|
115
|
1 |
|
$CustomerAddress->setName01($Customer->getName01()) |
|
|
|
|
116
|
1 |
|
->setName02($Customer->getName02()) |
117
|
1 |
|
->setKana01($Customer->getKana01()) |
118
|
1 |
|
->setKana02($Customer->getKana02()) |
119
|
1 |
|
->setCompanyName($Customer->getCompanyName()) |
120
|
1 |
|
->setZip01($Customer->getZip01()) |
121
|
1 |
|
->setZip02($Customer->getZip02()) |
122
|
1 |
|
->setZipcode($Customer->getZip01().$Customer->getZip02()) |
123
|
1 |
|
->setPref($Customer->getPref()) |
124
|
1 |
|
->setAddr01($Customer->getAddr01()) |
125
|
1 |
|
->setAddr02($Customer->getAddr02()) |
126
|
1 |
|
->setTel01($Customer->getTel01()) |
127
|
1 |
|
->setTel02($Customer->getTel02()) |
128
|
1 |
|
->setTel03($Customer->getTel03()) |
129
|
1 |
|
->setFax01($Customer->getFax01()) |
130
|
1 |
|
->setFax02($Customer->getFax02()) |
131
|
1 |
|
->setFax03($Customer->getFax03()) |
132
|
1 |
|
->setCustomer($Customer); |
133
|
|
|
|
134
|
1 |
|
$this->entityManager->persist($CustomerAddress); |
135
|
|
|
} |
136
|
|
|
|
137
|
2 |
View Code Duplication |
if ($Customer->getPassword() === $this->eccubeConfig['eccube_default_password']) { |
|
|
|
|
138
|
|
|
$Customer->setPassword($previous_password); |
|
|
|
|
139
|
|
|
} else { |
140
|
2 |
|
if ($Customer->getSalt() === null) { |
141
|
|
|
$Customer->setSalt($encoder->createSalt()); |
142
|
|
|
$Customer->setSecretKey($this->customerRepository->getUniqueSecretKey()); |
143
|
|
|
} |
144
|
2 |
|
$Customer->setPassword($encoder->encodePassword($Customer->getPassword(), $Customer->getSalt())); |
145
|
|
|
} |
146
|
|
|
|
147
|
2 |
|
$this->entityManager->persist($Customer); |
148
|
2 |
|
$this->entityManager->flush(); |
149
|
|
|
|
150
|
2 |
|
log_info('会員登録完了', [$Customer->getId()]); |
151
|
|
|
|
152
|
2 |
|
$event = new EventArgs( |
153
|
|
|
[ |
154
|
2 |
|
'form' => $form, |
155
|
2 |
|
'Customer' => $Customer, |
156
|
|
|
], |
157
|
2 |
|
$request |
158
|
|
|
); |
159
|
2 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_CUSTOMER_EDIT_INDEX_COMPLETE, $event); |
160
|
|
|
|
161
|
2 |
|
$this->addSuccess('admin.customer.save.complete', 'admin'); |
162
|
|
|
|
163
|
2 |
|
return $this->redirectToRoute('admin_customer_edit', [ |
164
|
2 |
|
'id' => $Customer->getId(), |
165
|
|
|
]); |
166
|
|
|
} else { |
167
|
|
|
$this->addError('admin.customer.save.failed', 'admin'); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
return [ |
172
|
4 |
|
'form' => $form->createView(), |
173
|
4 |
|
'Customer' => $Customer, |
174
|
|
|
]; |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|