nanasess /
ec-cube
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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\Application; |
||
| 27 | use Eccube\Common\Constant; |
||
| 28 | use Eccube\Controller\AbstractController; |
||
| 29 | use Eccube\Event\EccubeEvents; |
||
| 30 | use Eccube\Event\EventArgs; |
||
| 31 | use Symfony\Component\HttpFoundation\Request; |
||
| 32 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
||
| 33 | |||
| 34 | class CustomerEditController extends AbstractController |
||
| 35 | 2 | { |
|
| 36 | public function index(Application $app, Request $request, $id = null) |
||
| 37 | { |
||
| 38 | 2 | // 編集 |
|
| 39 | if ($id) { |
||
| 40 | $Customer = $app['orm.em'] |
||
| 41 | ->getRepository('Eccube\Entity\Customer') |
||
| 42 | ->find($id); |
||
| 43 | |||
| 44 | if (is_null($Customer)) { |
||
| 45 | throw new NotFoundHttpException(); |
||
| 46 | } |
||
| 47 | // 編集用にデフォルトパスワードをセット |
||
| 48 | $previous_password = $Customer->getPassword(); |
||
| 49 | $Customer->setPassword($app['config']['default_password']); |
||
| 50 | // 新規登録 |
||
| 51 | } else { |
||
| 52 | $Customer = $app['eccube.repository.customer']->newCustomer(); |
||
| 53 | $CustomerAddress = new \Eccube\Entity\CustomerAddress(); |
||
| 54 | $Customer->setBuyTimes(0); |
||
| 55 | 2 | $Customer->setBuyTotal(0); |
|
| 56 | } |
||
| 57 | |||
| 58 | // 会員登録フォーム |
||
| 59 | $builder = $app['form.factory'] |
||
| 60 | ->createBuilder('admin_customer', $Customer); |
||
| 61 | |||
| 62 | $event = new EventArgs( |
||
| 63 | array( |
||
| 64 | 'builder' => $builder, |
||
| 65 | 'Customer' => $Customer, |
||
| 66 | ), |
||
| 67 | $request |
||
| 68 | ); |
||
| 69 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CUSTOMER_EDIT_INDEX_INITIALIZE, $event); |
||
| 70 | |||
| 71 | $form = $builder->getForm(); |
||
| 72 | |||
| 73 | if ('POST' === $request->getMethod()) { |
||
| 74 | $form->handleRequest($request); |
||
| 75 | if ($form->isValid()) { |
||
| 76 | if ($Customer->getId() === null) { |
||
| 77 | $Customer->setSalt( |
||
| 78 | $app['eccube.repository.customer']->createSalt(5) |
||
| 79 | ); |
||
| 80 | $Customer->setSecretKey( |
||
| 81 | $app['eccube.repository.customer']->getUniqueSecretKey($app) |
||
| 82 | ); |
||
| 83 | |||
| 84 | $CustomerAddress->setName01($Customer->getName01()) |
||
| 85 | ->setName02($Customer->getName02()) |
||
| 86 | ->setKana01($Customer->getKana01()) |
||
| 87 | ->setKana02($Customer->getKana02()) |
||
| 88 | ->setCompanyName($Customer->getCompanyName()) |
||
| 89 | ->setZip01($Customer->getZip01()) |
||
| 90 | ->setZip02($Customer->getZip02()) |
||
| 91 | ->setZipcode($Customer->getZip01() . $Customer->getZip02()) |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 92 | ->setPref($Customer->getPref()) |
||
| 93 | ->setAddr01($Customer->getAddr01()) |
||
| 94 | ->setAddr02($Customer->getAddr02()) |
||
| 95 | ->setTel01($Customer->getTel01()) |
||
| 96 | ->setTel02($Customer->getTel02()) |
||
| 97 | ->setTel03($Customer->getTel03()) |
||
| 98 | ->setFax01($Customer->getFax01()) |
||
| 99 | ->setFax02($Customer->getFax02()) |
||
| 100 | ->setFax03($Customer->getFax03()) |
||
| 101 | ->setDelFlg(Constant::DISABLED) |
||
| 102 | ->setCustomer($Customer); |
||
| 103 | |||
| 104 | $app['orm.em']->persist($CustomerAddress); |
||
| 105 | } |
||
| 106 | |||
| 107 | if ($Customer->getPassword() === $app['config']['default_password']) { |
||
| 108 | 1 | $Customer->setPassword($previous_password); |
|
| 109 | 1 | } else { |
|
| 110 | $Customer->setPassword( |
||
| 111 | $app['eccube.repository.customer']->encryptPassword($app, $Customer) |
||
| 112 | ); |
||
| 113 | } |
||
| 114 | |||
| 115 | $app['orm.em']->persist($Customer); |
||
| 116 | 1 | ||
| 117 | 1 | $app['orm.em']->flush(); |
|
| 118 | |||
| 119 | $event = new EventArgs( |
||
| 120 | 2 | array( |
|
| 121 | 'form' => $form, |
||
| 122 | 'Customer' => $Customer, |
||
| 123 | ), |
||
| 124 | $request |
||
| 125 | ); |
||
| 126 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CUSTOMER_EDIT_INDEX_COMPLETE, $event); |
||
| 127 | |||
| 128 | $app->addSuccess('admin.customer.save.complete', 'admin'); |
||
| 129 | |||
| 130 | return $app->redirect($app->url('admin_customer_edit', array( |
||
| 131 | 'id' => $Customer->getId(), |
||
| 132 | ))); |
||
| 133 | } else { |
||
| 134 | $app->addError('admin.customer.save.failed', 'admin'); |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | return $app->render('Customer/edit.twig', array( |
||
| 139 | 'form' => $form->createView(), |
||
| 140 | 'Customer' => $Customer, |
||
| 141 | )); |
||
| 142 | } |
||
| 143 | } |
||
| 144 |