Skip to content

Commit

Permalink
Merge pull request EC-CUBE#26 from k-yamamura/feature-admin-order-mail
Browse files Browse the repository at this point in the history
メール通知で加算ポイントを表示するように修正
  • Loading branch information
chihiro-adachi committed May 10, 2016
2 parents 925fb68 + ee46ca6 commit e7b795a
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 33 deletions.
136 changes: 136 additions & 0 deletions Event/WorkPlace/AdminOrderMail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) 2000-2016 LOCKON CO.,LTD. All Rights Reserved.
* http://www.lockon.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Plugin\Point\Event\WorkPlace;

use Eccube\Event\EventArgs;
use Eccube\Event\TemplateEvent;
use Symfony\Component\Validator\Constraints as Assert;

/**
* フックポイント汎用処理具象クラス
* - 拡張元 : メール通知
* Class AdminOrderMail
* @package Plugin\Point\Event\WorkPlace
*/
class AdminOrderMail extends AbstractWorkPlace
{

/**
* 加算ポイント表示
*
* @param TemplateEvent $event
* @return bool
*/
public function createTwig(TemplateEvent $event)
{

$args = $event->getParameters();

$Order = $args['Order'];

$Customer = $Order->getCustomer();
if (empty($Customer)) {
return false;
}

$body = $args['body'];

// 計算ヘルパーの取得
$calculator = $this->app['eccube.plugin.point.calculate.helper.factory'];

// 計算に必要なエンティティの設定
$calculator->addEntity('Order', $Order);
$calculator->addEntity('Customer', $Customer);

// 計算値取得
$addPoint = $calculator->getAddPointByOrder();

$body = $this->getBody($body, $addPoint);

$args['body'] = $body;

$event->setParameters($args);

}


/**
* 加算ポイント表示
*
* @param EventArgs $event
* @return bool
*/
public function save(EventArgs $event)
{

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

$Order = $event->getArgument('Order');
$MailHistory = $event->getArgument('MailHistory');

$Customer = $Order->getCustomer();
if (empty($Customer)) {
return false;
}

$body = $MailHistory->getMailBody();

// 計算ヘルパーの取得
$calculator = $this->app['eccube.plugin.point.calculate.helper.factory'];

// 計算に必要なエンティティの設定
$calculator->addEntity('Order', $Order);
$calculator->addEntity('Customer', $Customer);

// 計算値取得
$addPoint = $calculator->getAddPointByOrder();

$body = $this->getBody($body, $addPoint);

// メッセージにメールボディをセット
$MailHistory->setMailBody($body);

$this->app['orm.em']->flush($MailHistory);


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


/**
* 本文を置換
*
* @param $body
* @param $addPoint
* @return mixed
*/
private function getBody($body, $addPoint)
{

// 情報置換用のキーを取得
$search = array();
preg_match_all('/合 計.*\\n/u', $body, $search);

// メール本文置換
$snippet = PHP_EOL;
$snippet .= PHP_EOL;
$snippet .= '***********************************************'.PHP_EOL;
$snippet .= ' ポイント情報 '.PHP_EOL;
$snippet .= '***********************************************'.PHP_EOL;
$snippet .= '加算ポイント:'.number_format($addPoint).PHP_EOL;
$snippet .= PHP_EOL;
$replace = $search[0][0].$snippet;
return preg_replace('/'.$search[0][0].'/u', $replace, $body);

}

}
36 changes: 10 additions & 26 deletions Event/WorkPlace/ServiceMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public function save(EventArgs $event)
// 基本情報の取得
$message = $event->getArgument('message');
$order = $event->getArgument('Order');
$mailTemplate = $event->getArgument('MailTemplate');


// 必要情報判定
if (empty($message) || empty($order)) {
Expand All @@ -63,45 +61,31 @@ public function save(EventArgs $event)

// 計算値取得
$addPoint = $calculator->getAddPointByOrder();
$point = $calculator->getPoint();

// ポイント配列作成
$pointMessage = array();
$pointMessage['add'] = $addPoint;
$pointMessage['point'] = $point;
$pointMessage['use'] = $usePoint;

$this->app['monolog.point']->addInfo('save add point', array(
'customer_id' => $order->getCustomer()->getId(),
'customer_id' => $customer->getId(),
'order_id' => $order->getId(),
'add point' => $addPoint,
'use point' => $usePoint,
)
);

// メールボディ取得
$body = $this->app->renderView(
$mailTemplate->getFileName(),
array(
'header' => $mailTemplate->getHeader(),
'footer' => $mailTemplate->getFooter(),
'Order' => $order,
)
);
$body = $message->getBody();

// 情報置換用のキーを取得
$search = array();
preg_match_all('/合 計.*\\n/u', $body, $search);

// メール本文置換
$snipet = PHP_EOL;
$snipet .= PHP_EOL;
$snipet .= '***********************************************'.PHP_EOL;
$snipet .= ' ポイント情報 '.PHP_EOL;
$snipet .= '***********************************************'.PHP_EOL;
$snipet .= '加算ポイント:'.number_format($pointMessage['add']).PHP_EOL;
$snipet .= PHP_EOL;
$replace = $search[0][0].$snipet;
$snippet = PHP_EOL;
$snippet .= PHP_EOL;
$snippet .= '***********************************************'.PHP_EOL;
$snippet .= ' ポイント情報 '.PHP_EOL;
$snippet .= '***********************************************'.PHP_EOL;
$snippet .= '加算ポイント:'.number_format($addPoint).PHP_EOL;
$snippet .= PHP_EOL;
$replace = $search[0][0].$snippet;
$body = preg_replace('/'.$search[0][0].'/u', $replace, $body);

// メッセージにメールボディをセット
Expand Down
1 change: 0 additions & 1 deletion Helper/PointHistoryHelper/PointHistoryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Plugin\Point\Entity\Point;
use Plugin\Point\Entity\PointSnapshot;
use Plugin\Point\Entity\PointStatus;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
* ポイント履歴ヘルパー
Expand Down
27 changes: 21 additions & 6 deletions PointEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Eccube\Event\TemplateEvent;
use Plugin\Point\Event\WorkPlace\AdminCustomer;
use Plugin\Point\Event\WorkPlace\AdminOrder;
use Plugin\Point\Event\WorkPlace\AdminOrderMail;
use Plugin\Point\Event\WorkPlace\AdminProduct;
use Plugin\Point\Event\WorkPlace\FrontCart;
use Plugin\Point\Event\WorkPlace\FrontDelivery;
Expand All @@ -35,12 +36,6 @@
*/
class PointEvent
{
/**
* ヘルパー呼び出し用
* サービス
*/
const HELPER_SERVICE_MAIL = 'ServiceMail';


/** @var \Eccube\Application $app */
protected $app;
Expand Down Expand Up @@ -136,6 +131,16 @@ public function onAdminOrderDeleteComplete(EventArgs $event)
$helper->delete($event);
}

/**
* メール通知
* @param EventArgs $event
*/
public function onAdminOrderMailIndexComplete(EventArgs $event)
{
$helper = new AdminOrderMail();
$helper->save($event);
}

/**
* 商品購入確認完了
* - 利用ポイント・保有ポイント・仮付与ポイント保存
Expand Down Expand Up @@ -251,6 +256,16 @@ public function onRenderMyPageIndex(TemplateEvent $event)
}
}

/**
* メール通知
* @param TemplateEvent $event
*/
public function onRenderAdminOrderMailConfirm(TemplateEvent $event)
{
$helper = new AdminOrderMail();
$helper->createTwig($event);
}

/**
* 商品購入完了メール
* - ポイントの表示
Expand Down
13 changes: 13 additions & 0 deletions event.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ admin.order.edit.index.complete:
admin.order.delete.complete:
- [onAdminOrderDeleteComplete, NORMAL]

## 管理画面 > メール通知
admin.order.mail.index.complete:
- [onAdminOrderMailIndexComplete, NORMAL]

# フロント画面
## フロント画面 > 商品購入確認完了(ポイント利用処理)
front.shopping.confirm.processing:
Expand Down Expand Up @@ -51,6 +55,11 @@ front.shopping.shipping.edit.complete:
## 管理画面 > 受注編集
Admin/Order/edit.twig:
- [onRenderAdminOrderEdit, NORMAL]

## 管理画面 > メール通知
Admin/Order/mail_confirm.twig:
- [onRenderAdminOrderMailConfirm, NORMAL]

## マイページ
Mypage/index.twig:
- [onRenderMyPageIndex, NORMAL]
Expand All @@ -75,3 +84,7 @@ Mypage/history.twig:
## 受注メール
mail.order:
- [onMailOrderComplete, NORMAL]

## メール通知
mail.admin.order:
- [onMailOrderComplete, NORMAL]

0 comments on commit e7b795a

Please sign in to comment.