Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feature-admin-ord…
Browse files Browse the repository at this point in the history
…er-mail
  • Loading branch information
k-yamamura committed May 10, 2016
2 parents 6f024c1 + 925fb68 commit ee46ca6
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 479 deletions.
46 changes: 12 additions & 34 deletions Controller/AdminPointController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Plugin\Point\Controller;

use Eccube\Application;
use Plugin\Point\Entity\PointInfo;
use Plugin\Point\Form\Type;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception as HttpException;
Expand Down Expand Up @@ -43,53 +42,33 @@ public function __construct()
*/
public function index(Application $app, Request $request)
{
// 権限判定
if (!$this->app->isGranted('ROLE_ADMIN') && !$this->app->isGranted('ROLE_USER')) {
throw new HttpException\NotFoundHttpException();
}

$app['monolog.point.admin']->addInfo('index start');

// 最終保存のポイント設定情報取得
$PointInfo = $this->app['eccube.plugin.point.repository.pointinfo']->getLastInsertData();

// 既存データがない場合
if (!isset($PointInfo) || empty($PointInfo)) {
$PointInfo = new PointInfo();
}

//フォーム生成
$form = $app['form.factory']
->createBuilder('admin_point_info', $PointInfo)
->getForm();

// 保存処理
$form->handleRequest($request);
// 保存処理

if ($form->isSubmitted() && $form->isValid()) {
$saveData = $form->getData();
$status = $this->app['eccube.plugin.point.repository.pointinfo']->save($saveData);
if ($status) {
$app->addSuccess('admin.point.save.complete', 'admin');
$PointInfo = $form->getData();
$this->app['eccube.plugin.point.repository.pointinfo']->save($PointInfo);

$app['monolog.point.admin']->addInfo('index status', array(
'status' => $status,
'saveData' => $app['serializer']->serialize($saveData, 'json'),
)
);
$app->addSuccess('admin.point.save.complete', 'admin');

$app['monolog.point.admin']->addInfo('index end');
$app['monolog.point.admin']->addInfo(
'index save',
array(
'saveData' => $app['serializer']->serialize($PointInfo, 'json'),
)
);

return $app->redirect($app->url('point_info'));
} else {
$app->addError('admin.point.save.error', 'admin');
}
}
$app['monolog.point.admin']->addInfo('index end');

// フォーム項目名称描画用文字配列
$orderStatus = array();
foreach ($this->app['eccube.repository.order_status']->findAllArray() as $id => $node) {
$orderStatus[$id] = $node['name'];
return $app->redirect($app->url('point_info'));
}

$app['monolog.point.admin']->addInfo('index end');
Expand All @@ -99,7 +78,6 @@ public function index(Application $app, Request $request)
array(
'form' => $form->createView(),
'Point' => $PointInfo,
'orderStatus' => $orderStatus,
)
);
}
Expand Down
48 changes: 0 additions & 48 deletions Entity/PointUse.php

This file was deleted.

6 changes: 3 additions & 3 deletions Event/WorkPlace/AbstractWorkPlace.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public function __construct()

/**
* フォーム拡張処理
* @param FormBuilder $builder
*
* @param EventArgs $event
* @param Request $request
* @return mixed
*/
public function createForm(FormBuilder $builder, Request $request, EventArgs $event = null){
public function createForm(EventArgs $event, Request $request){
throw new MethodNotAllowedException();
}

Expand Down
12 changes: 7 additions & 5 deletions Event/WorkPlace/AdminCustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ class AdminCustomer extends AbstractWorkPlace
{
/**
* 会員保有ポイント追加
* @param FormBuilder $builder
*
* @param EventArgs $event
* @param Request $request
*/
public function createForm(FormBuilder $builder, Request $request)
public function createForm(EventArgs $event, Request $request)
{
$customerId = $builder->getForm()->getData()->getId();
$builder = $event->getArgument('builder');
$Customer = $event->getArgument('Customer');

// 登録済み情報取得処理
$lastPoint = null;
if (!is_null($customerId)) {
$lastPoint = $this->app['eccube.plugin.point.repository.pointcustomer']->getLastPointById($customerId);
if (!is_null($Customer->getId())) {
$lastPoint = $this->app['eccube.plugin.point.repository.pointcustomer']->getLastPointById($Customer->getId());
}

$data = is_null($lastPoint) ? '' : $lastPoint;
Expand Down
5 changes: 2 additions & 3 deletions Event/WorkPlace/AdminOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ public function __construct()
/**
* 受注登録・編集
*
* @param FormBuilder $builder
* @param EventArgs $event
* @param Request $request
* @param EventArgs|null $event
*/
public function createForm(FormBuilder $builder, Request $request, EventArgs $event = null)
public function createForm(EventArgs $event, Request $request)
{
$builder = $this->buildForm($event->getArgument('builder'));
$Order = $event->getArgument('TargetOrder');
Expand Down
39 changes: 11 additions & 28 deletions Event/WorkPlace/AdminProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,20 @@ class AdminProduct extends AbstractWorkPlace
{
/**
* 商品フォームポイント付与率項目追加
* @param FormBuilder $builder
*
* @param EventArgs $event
* @param Request $request
*/
public function createForm(FormBuilder $builder, Request $request)
public function createForm(EventArgs $event, Request $request)
{
$productId = $builder->getForm()->getData()->getId();
$builder = $event->getArgument('builder');
$Product = $event->getArgument('Product');

// 登録済み情報取得処理
$lastPointProduct = null;
if (!is_null($productId)) {
if (!is_null($Product->getId())) {
$lastPointProduct = $this->app['eccube.plugin.point.repository.pointproductrate']->getLastPointProductRateById(
$productId
$Product->getId()
);
}

Expand All @@ -52,9 +54,6 @@ public function createForm(FormBuilder $builder, Request $request)
'required' => false,
'mapped' => false,
'data' => $lastPointProduct,
'attr' => array(
'placeholder' => '設定されていると本商品のみ設定値をもとにポイントを計算します。',
),
'constraints' => array(
new Assert\Regex(
array(
Expand All @@ -80,31 +79,22 @@ public function createForm(FormBuilder $builder, Request $request)
*/
public function save(EventArgs $event)
{

$this->app['monolog.point.admin']->addInfo('save start');

// フォーム情報取得処理
$form = $event->getArgument('form');

if (empty($form)) {
return false;
}

// ポイント付与率取得
$pointRate = $form->get('plg_point_product_rate')->getData();

// 商品ID取得
$productId = $form->getData()->getId();
if(empty($productId)){
$productId = 0;
}
$Product = $event->getArgument('Product');

// 前回入力値と比較
$status = $this->app['eccube.plugin.point.repository.pointproductrate']
->isSamePoint($pointRate, $productId);
->isSamePoint($pointRate, $Product->getId());

$this->app['monolog.point.admin']->addInfo('save add product point', array(
'product_id' => $productId,
'product_id' => $Product->getId(),
'status' => $status,
'add point' => $pointRate,
)
Expand All @@ -115,15 +105,8 @@ public function save(EventArgs $event)
return true;
}

// プロダクトエンティティを取得
$product = $event->getArgument('Product');

if (empty($product)) {
return false;
}

// ポイント付与保存処理
$this->app['eccube.plugin.point.repository.pointproductrate']->savePointProductRate($pointRate, $product);
$this->app['eccube.plugin.point.repository.pointproductrate']->savePointProductRate($pointRate, $Product);

$this->app['monolog.point.admin']->addInfo('save end');
}
Expand Down
36 changes: 9 additions & 27 deletions Event/WorkPlace/FrontMyPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,18 @@ class FrontMyPage extends AbstractWorkPlace
*/
public function createTwig(TemplateEvent $event)
{
$pointInfo = $this->app['eccube.plugin.point.repository.pointinfo']->getLastInsertData();
$PointInfo = $this->app['eccube.plugin.point.repository.pointinfo']->getLastInsertData();

$point_rate = 0;
if (!empty($pointInfo)) {
$point_rate = (integer)$pointInfo->getPlgPointConversionRate();
}
$pointRate = $PointInfo->getPlgPointConversionRate();

// ポイント計算ヘルパーを取得
$calculator = null;
$calculator = $this->app['eccube.plugin.point.calculate.helper.factory'];

// ヘルパーの取得判定
if (empty($calculator)) {
return false;
}

// カスタマー情報を取得
$customer = $this->app['security']->getToken()->getUser();

if (empty($customer)) {
return false;
}

if (empty($pointInfo)) {
return false;
}
$Customer = $this->app->user();

// 計算に必要なエンティティを登録
$calculator->addEntity('Customer', $customer);
$calculator->addEntity('Customer', $Customer);

// 会員保有ポイントを取得
$currentPoint = $calculator->getPoint();
Expand All @@ -69,19 +52,18 @@ public function createTwig(TemplateEvent $event)
}

// 仮ポイント取得
$previsionAddPoint = $calculator->getProvisionalAddPoint();

$provisionalAddPoint = $calculator->getProvisionalAddPoint();

// 仮ポイント取得判定
if (empty($previsionAddPoint)) {
$previsionAddPoint = 0;
if (empty($provisionalAddPoint)) {
$provisionalAddPoint = 0;
}

// ポイント表示用変数作成
$point = array();
$point['current'] = $currentPoint;
$point['pre'] = $previsionAddPoint;
$point['rate'] = $point_rate;
$point['pre'] = $provisionalAddPoint;
$point['rate'] = $pointRate;

// 使用ポイントボタン付与
// twigコードにポイント表示欄を追加
Expand Down
2 changes: 0 additions & 2 deletions Event/WorkPlace/FrontShopping.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Plugin\Point\Event\WorkPlace;

use Eccube\Event\TemplateEvent;
use Plugin\Point\Entity\PointUse;
use Symfony\Component\Validator\Constraints as Assert;

/**
Expand Down Expand Up @@ -56,7 +55,6 @@ public function createTwig(TemplateEvent $event)
}

// 利用ポイントの確認
$pointUse = new PointUse();
$usePoint = -($this->app['eccube.plugin.point.repository.point']->getLatestPreUsePoint($order));

// 計算に必要なエンティティを登録
Expand Down
Loading

0 comments on commit ee46ca6

Please sign in to comment.