Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
【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 onCustomerEditIndexInitialize(EventArgs $event)
{
$Customer = $event->getArgument('Customer');
$id = $Customer->getId();
$Profile = $this->app['eccube.plugin.profile.repository.profile']->findOneBy(array('customer_id' => $Customer->getId()));
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 onCustomerEditIndexComplete(EventArgs $event)
{
$form = $event->getArgument('form');
$Customer = $event->getArgument('Customer');
$id = $Customer->getId();
$Profile = $this->app['eccube.plugin.profile.repository.profile']->findOneBy(array("customer_id" => $id));
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