Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active September 12, 2017 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurozumi/380e3b2a3551e203f9aabd718c8518c4 to your computer and use it in GitHub Desktop.
Save kurozumi/380e3b2a3551e203f9aabd718c8518c4 to your computer and use it in GitHub Desktop.
【EC-CUBE3】会員情報の項目を追加する方法
<?php
/*
* This file is part of the Profile
*
* Copyright (C) 2016 会員プロフィール
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\Profile;
use Eccube\Application;
use Eccube\Event\EventArgs;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Plugin\Profile\Entity\Profile;
class ProfileEvent
{
/** @var \Eccube\Application $app */
private $app;
public function __construct(Application $app)
{
$this->app = $app;
}
public function onEntryIndexInitialize(EventArgs $event)
{
$Customer = $event->getArgument('Customer');
$Profile = $this->app['eccube.plugin.profile.repository.profile']->findOneBy(array('Customer' => $Customer));
if(!$Profile){
$Profile = new Profile();
}
$builder = $event->getArgument('builder');
$builder->add(
'plg_nickname',
'text',
array(
'required' => false,
'label' => 'ニックネーム',
'mapped' => false,
'data' => $Profile->getNickname()
)
);
}
public function onEntryIndexComplete(EventArgs $event)
{
$form = $event->getArgument('form');
$Customer = $event->getArgument('Customer');
$Profile = $this->app['eccube.plugin.profile.repository.profile']->findOneBy(array("Customer" => $Customer));
if (!$Profile) {
$Profile = new Profile();
}
// エンティティを更新
$Profile
->setCustomer($Customer)
->setNickname($form['plg_nickname']->getData());
// DB更新
$this->app['orm.em']->persist($Profile);
$this->app['orm.em']->flush($Profile);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment