Skip to content

Commit

Permalink
Merge pull request #989 from clicktx/fix/sc_helper_mail
Browse files Browse the repository at this point in the history
登録メール送信時の警告を修正 #982
  • Loading branch information
nanasess authored Sep 9, 2024
2 parents 66445b3 + d989c3d commit 74eaa0a
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
 ご連絡いただければ幸いです。
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

<!--{$name01}--> <!--{$name02}-->
<!--{$arrCustomer.name01}--> <!--{$arrCustomer.name02}-->

<!--{$CONF.shop_name}-->でございます。

Expand All @@ -44,7 +44,7 @@
本会員登録を完了するには下記URLにアクセスしてください。
※入力されたお客様の情報はSSL暗号化通信により保護されます。

<!--{$smarty.const.HTTPS_URL}-->regist/<!--{$smarty.const.DIR_INDEX_PATH}-->?mode=regist&id=<!--{$uniqid}--><!--{$etc_value}-->
<!--{$smarty.const.HTTPS_URL}-->regist/<!--{$smarty.const.DIR_INDEX_PATH}-->?mode=regist&id=<!--{$arrCustomer.secret_key}--><!--{$etc_value}-->

上記URLにて本会員登録が完了いたしましたら改めてご登録内容ご確認
メールをお送り致します。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
 ご連絡いただければ幸いです。
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

<!--{$name01}--><!--{$name02}-->
<!--{$arrCustomer.name01}--><!--{$arrCustomer.name02}-->

<!--{$CONF.shop_name}-->でございます。

Expand Down
16 changes: 9 additions & 7 deletions data/class/helper/SC_Helper_Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public function sfCheckCustomerMailMaga($email)
/**
* 登録メールを送信する。
*
* @param string $secret_key 会員固有キー
* @param string $secret_key 会員固有キー。$customer_id に有効な数値が指定されると、無視される。
* @param integer $customer_id 会員ID
* @param boolean $is_mobile false(default):PCアドレスにメールを送る true:携帯アドレスにメールを送る
* @param $resend_flg true 仮登録メール再送
Expand All @@ -373,20 +373,22 @@ public function sfSendRegistMail($secret_key, $customer_id = '', $is_mobile = fa
$objMailText = new SC_SiteView_Ex();
$objMailText->setPage($this->getPage());
$objMailText->assign('CONF', $CONF);
$objMailText->assign('name01', $arrCustomerData['name01']);
$objMailText->assign('name02', $arrCustomerData['name02']);
$objMailText->assign('arrCustomer', $arrCustomerData);

// 旧テンプレート互換用 https://github.com/EC-CUBE/ec-cube2/issues/982
$objMailText->assignarray($arrCustomerData);
$objMailText->assign('uniqid', $arrCustomerData['secret_key']);
$objMailText->assignobj($arrCustomerData);

$objHelperMail = new SC_Helper_Mail_Ex();
// 仮会員が有効の場合
if (CUSTOMER_CONFIRM_MAIL == true and $arrCustomerData['status'] == 1 or $arrCustomerData['status'] == 1 and $resend_flg == true) {
// 仮会員が有効の場合 (FIXME: コメント不正確)
if ($arrCustomerData['status'] == 1
&& (CUSTOMER_CONFIRM_MAIL == true || $resend_flg == true)
) {
$subject = $objHelperMail->sfMakeSubject('会員登録のご確認', $objMailText);
$toCustomerMail = $objMailText->fetch('mail_templates/customer_mail.tpl');
} else {
$subject = $objHelperMail->sfMakeSubject('会員登録のご完了', $objMailText);
$toCustomerMail = $objMailText->fetch('mail_templates/customer_regist_mail.tpl');

}

$objMail = new SC_SendMail_Ex();
Expand Down
7 changes: 4 additions & 3 deletions data/class/pages/admin/customer/LC_Page_Admin_Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,13 @@ public function lfDoResendMail($customer_id)
//対象となるデータが見つからない、または削除済み
return false;
}
//仮登録メール再送
$resend_flg = true;
// 登録メール再送

// 仮登録メール送信
$objHelperMail = new SC_Helper_Mail_Ex();
$objHelperMail->setPage($this);
$resend_flg = true;
$objHelperMail->sfSendRegistMail($arrData['secret_key'], $customer_id, null, $resend_flg);

return true;
}

Expand Down
39 changes: 3 additions & 36 deletions data/class/pages/entry/LC_Page_Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,44 +222,11 @@ public function lfMakeSqlVal(&$objFormParam)
*/
public function lfSendMail($uniqid, $arrForm)
{
$CONF = SC_Helper_DB_Ex::sfGetBasisData();
$objHelperMail = new SC_Helper_Mail_Ex();

$objMailText = new SC_SiteView_Ex();
$objMailText->setPage($this);
$objMailText->assign('CONF', $CONF);
$objMailText->assign('name01', $arrForm['name01']);
$objMailText->assign('name02', $arrForm['name02']);
$objMailText->assign('uniqid', $uniqid);

$objHelperMail = new SC_Helper_Mail_Ex();
$objHelperMail->setPage($this);

// 仮会員が有効の場合
if (CUSTOMER_CONFIRM_MAIL == true) {
$subject = $objHelperMail->sfMakeSubject('会員登録のご確認');
$toCustomerMail = $objMailText->fetch('mail_templates/customer_mail.tpl');
} else {
$subject = $objHelperMail->sfMakeSubject('会員登録のご完了');
$toCustomerMail = $objMailText->fetch('mail_templates/customer_regist_mail.tpl');
}

$objMail = new SC_SendMail_Ex();
$objMail->setItem(
'', // 宛先
$subject, // サブジェクト
$toCustomerMail, // 本文
$CONF['email03'], // 配送元アドレス
$CONF['shop_name'], // 配送元 名前
$CONF['email03'], // reply_to
$CONF['email04'], // return_path
$CONF['email04'], // Errors_to
$CONF['email01'] // Bcc
);
// 宛先の設定
$objMail->setTo($arrForm['email'],
$arrForm['name01'] . $arrForm['name02'] .'');

$objMail->sendMail();
$resend_flg = true;
$objHelperMail->sfSendRegistMail($uniqid, '', false, $resend_flg);
}

/**
Expand Down
37 changes: 3 additions & 34 deletions data/class/pages/regist/LC_Page_Regist.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,40 +135,9 @@ public function lfCheckError($array)
*/
public function lfSendRegistMail($registSecretKey)
{
$objQuery = SC_Query_Ex::getSingletonInstance();
$objCustomer = new SC_Customer_Ex();
$objHelperMail = new SC_Helper_Mail_Ex();
$objHelperMail = new SC_Helper_Mail_Ex();

$objHelperMail->setPage($this);
$CONF = SC_Helper_DB_Ex::sfGetBasisData();

//-- 会員データを取得
$arrCustomer = $objQuery->select('*', 'dtb_customer', 'secret_key = ?', array($registSecretKey));
$data = $arrCustomer[0];
$objCustomer->setLogin($data['email']);

//-- メール送信
$objMailText = new SC_SiteView_Ex();
$objMailText->setPage($this);
$objMailText->assign('CONF', $CONF);
$objMailText->assign('name01', $data['name01']);
$objMailText->assign('name02', $data['name02']);
$toCustomerMail = $objMailText->fetch('mail_templates/customer_regist_mail.tpl');
$subject = $objHelperMail->sfMakesubject('会員登録が完了しました。');
$objMail = new SC_SendMail_Ex();

$objMail->setItem(
'', // 宛先
$subject, // サブジェクト
$toCustomerMail, // 本文
$CONF['email03'], // 配送元アドレス
$CONF['shop_name'], // 配送元 名前
$CONF['email03'], // reply_to
$CONF['email04'], // return_path
$CONF['email04'] // Errors_to
);
// 宛先の設定
$name = $data['name01'] . $data['name02'] .'';
$objMail->setTo($data['email'], $name);
$objMail->sendMail();
$objHelperMail->sfSendRegistMail($registSecretKey);
}
}
50 changes: 50 additions & 0 deletions tests/class/helper/SC_Helper_Mail/SC_Helper_Mail_TestBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

$HOME = realpath(dirname(__FILE__)) . "/../../../../";
require_once($HOME . "/tests/class/Common_TestCase.php");
/**
*
*/
class SC_Helper_Mail_TestBase extends Common_TestCase
{
/** @var int */
protected $customer_id;

/** @var Faker\Generator $faker */
protected $faker;

/** @var string */
protected $email;

/** @var array */
protected $arrCustomer;

/** @var SC_Customer_Ex */
protected $objCustomer;

/** @var SC_Helper_Mail_Ex */
protected $objHelperMail;


protected function setUp()
{
parent::setUp();
$this->checkMailCatcherStatus();
$this->objHelperMail = new SC_Helper_Mail_Ex();

$this->faker = Faker\Factory::create('ja_JP');
}

protected function tearDown()
{
parent::tearDown();
}

protected function setUpCustomer($properties = [])
{
$this->email = $this->faker->safeEmail;
$this->customer_id = $this->objGenerator->createCustomer($this->email, $properties);
$this->arrCustomer = $this->objQuery->getRow('*', 'dtb_customer', 'customer_id = ?', [$this->customer_id]);
$this->objCustomer = new SC_Customer_Ex();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

$HOME = realpath(dirname(__FILE__)) . "/../../../..";
require_once($HOME . "/tests/class/helper/SC_Helper_Mail/SC_Helper_Mail_TestBase.php");
/**
*
*/
class SC_Helper_Mail_sfSendRegistMailTest extends SC_Helper_Mail_TestBase
{
protected function setUp()
{
parent::setUp();
}

protected function tearDown()
{
parent::tearDown();
}

/////////////////////////////////////////

public function test会員登録メールの宛名が正しい()
{
# 本会員を作成
$this->setUpCustomer();

$this->resetEmails();
$this->objHelperMail->sfSendRegistMail($this->arrCustomer['secret_key']);

$message = $this->getLastMailCatcherMessage();
$this->assertContains($this->arrCustomer['name01'] . $this->arrCustomer['name02'] . '', $message['source']);
}

public function test会員登録依頼メールの宛名と登録リンクのidが正しい()
{
# 仮会員を作成
$this->setUpCustomer(['status' => 1]);

$this->resetEmails();
$this->objHelperMail->sfSendRegistMail($this->arrCustomer['secret_key'], '', false, true);

$message = $this->getLastMailCatcherMessage();
$this->assertContains($this->arrCustomer['name01'] . ' ' . $this->arrCustomer['name02'] . '', $message['source']);
$this->assertContains('&id=' . $this->arrCustomer['secret_key'], $message['source']);
}
}

0 comments on commit 74eaa0a

Please sign in to comment.