Skip to content

Commit

Permalink
Merge pull request EC-CUBE#5989 from dotani1111/features/feat_custome…
Browse files Browse the repository at this point in the history
…r_mail_notifier

feat:会員による重要操作時のメール通知機能
  • Loading branch information
ji-eunsoo authored Jun 5, 2023
2 parents 0bf8995 + 0a80189 commit b809b34
Show file tree
Hide file tree
Showing 22 changed files with 508 additions and 27 deletions.
40 changes: 40 additions & 0 deletions app/DoctrineMigrations/Version20230515023836.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20230515023836 extends AbstractMigration
{
public function up(Schema $schema): void
{
$exists = $this->connection->fetchOne("SELECT count(*) FROM dtb_mail_template WHERE file_name = 'Mail/customer_change_notify.twig'");
if ($exists == 0) {
$this->addSql("
INSERT INTO dtb_mail_template (creator_id, name, file_name, mail_subject, create_date, update_date, discriminator_type)
VALUES (null, '会員情報変更通知メール', 'Mail/customer_change_notify.twig', '会員情報変更のお知らせ', '2017-03-07 10:14:52', '2017-03-07 10:14:52', 'mailtemplate');");
}
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
}
}
6 changes: 3 additions & 3 deletions codeception/acceptance/EF03OrderCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ public function order_ログインユーザ購入複数配送(AcceptanceTester $
// メール確認
$message = $I->lastMessage();
$I->assertCount(2, $message->getRecipients(), 'Bcc で管理者にも送信するので宛先アドレスは2つ');
$I->seeEmailCount(1);
$I->seeEmailCount(2);
foreach ([$customer->getEmail(), $BaseInfo->getEmail01()] as $email) {
$I->seeInLastEmailSubjectTo($email, 'ご注文ありがとうございます');
$I->seeInLastEmailTo($email, $customer->getName01().' '.$customer->getName02().'');
Expand Down Expand Up @@ -744,7 +744,7 @@ public function order_購入確認画面からカートに戻る(AcceptanceTeste
// メール確認
$message = $I->lastMessage();
$I->assertCount(2, $message->getRecipients(), 'Bcc で管理者にも送信するので宛先アドレスは2つ');
$I->seeEmailCount(1);
$I->seeEmailCount(2);
foreach ([$customer->getEmail(), $BaseInfo->getEmail01()] as $email) {
$I->seeInLastEmailSubjectTo($email, 'ご注文ありがとうございます');
$I->seeInLastEmailTo($email, $customer->getName01().' '.$customer->getName02().'');
Expand Down Expand Up @@ -906,7 +906,7 @@ public function order_購入確認画面からカートに戻るWithお届け先
// メール確認
$message = $I->lastMessage();
$I->assertCount(2, $message->getRecipients(), 'Bcc で管理者にも送信するので宛先アドレスは2つ');
$I->seeEmailCount(1);
$I->seeEmailCount(2);
foreach ([$customer->getEmail(), $BaseInfo->getEmail01()] as $email) {
$I->seeInLastEmailSubjectTo($email, 'ご注文ありがとうございます');
$I->seeInLastEmailTo($email, $customer->getName01().' '.$customer->getName02().'');
Expand Down
1 change: 1 addition & 0 deletions src/Eccube/Command/LoadDataFixturesEccubeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'email04' => $admin_mail,
'update_date' => new \DateTime(),
'discriminator_type' => 'baseinfo',
'option_mail_notifier' => true,
], [
'update_date' => \Doctrine\DBAL\Types\Types::DATETIMETZ_MUTABLE,
]);
Expand Down
1 change: 1 addition & 0 deletions src/Eccube/Controller/Install/InstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ protected function insert(Connection $conn, array $data)
'email04' => $data['email'],
'update_date' => new \DateTime(),
'discriminator_type' => 'baseinfo',
'option_mail_notifier' => true,
], [
'update_date' => Types::DATETIMETZ_MUTABLE,
]);
Expand Down
37 changes: 36 additions & 1 deletion src/Eccube/Controller/Mypage/ChangeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Eccube\Form\Type\Front\EntryType;
use Eccube\Repository\BaseInfoRepository;
use Eccube\Repository\CustomerRepository;
use Eccube\Service\MailService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
Expand All @@ -43,14 +45,30 @@ class ChangeController extends AbstractController
*/
protected $encoderFactory;

/**
* @var MailService
*/
protected $mailService;

/**
* @var baseInfoRepository
*/
protected $baseInfoRepository;

private const SESSION_KEY_PRE_EMAIL = 'eccube.front.mypage.change.preEmail';

public function __construct(
CustomerRepository $customerRepository,
EncoderFactoryInterface $encoderFactory,
TokenStorageInterface $tokenStorage
TokenStorageInterface $tokenStorage,
BaseInfoRepository $baseInfoRepository,
MailService $mailService
) {
$this->customerRepository = $customerRepository;
$this->encoderFactory = $encoderFactory;
$this->tokenStorage = $tokenStorage;
$this->baseInfoRepository = $baseInfoRepository;
$this->mailService = $mailService;
}

/**
Expand Down Expand Up @@ -93,6 +111,20 @@ public function index(Request $request)
$encoder->encodePassword($Customer->getPlainPassword(), $Customer->getSalt())
);
}

// 会員情報変更時にメールを送信
if ($this->baseInfoRepository->get()->isOptionMailNotifier()) {
// 情報のセット
$userData['userAgent'] = $request->headers->get('User-Agent');
$userData['preEmail'] = $request->getSession()->get(self::SESSION_KEY_PRE_EMAIL);
$userData['ipAddress'] = $request->getClientIp();

// メール送信
$this->mailService->sendCustomerChangeNotifyMail($Customer, $userData, trans('front.mypage.customer.notify_title'));
}

$this->session->remove(self::SESSION_KEY_PRE_EMAIL);

$this->entityManager->flush();

log_info('会員編集完了');
Expand All @@ -109,6 +141,9 @@ public function index(Request $request)
return $this->redirect($this->generateUrl('mypage_change_complete'));
}

$preEmail = $form->get('email')->getData();
$this->session->set(self::SESSION_KEY_PRE_EMAIL, $preEmail);

return [
'form' => $form->createView(),
];
Expand Down
31 changes: 30 additions & 1 deletion src/Eccube/Controller/Mypage/DeliveryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Eccube\Form\Type\Front\CustomerAddressType;
use Eccube\Repository\BaseInfoRepository;
use Eccube\Repository\CustomerAddressRepository;
use Eccube\Service\MailService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
Expand All @@ -39,10 +40,20 @@ class DeliveryController extends AbstractController
*/
protected $customerAddressRepository;

public function __construct(BaseInfoRepository $baseInfoRepository, CustomerAddressRepository $customerAddressRepository)
/**
* @var MailService
*/
protected $mailService;

public function __construct(
BaseInfoRepository $baseInfoRepository,
CustomerAddressRepository $customerAddressRepository,
MailService $mailService
)
{
$this->BaseInfo = $baseInfoRepository->get();
$this->customerAddressRepository = $customerAddressRepository;
$this->mailService = $mailService;
}

/**
Expand Down Expand Up @@ -129,6 +140,15 @@ public function edit(Request $request, $id = null)
$this->entityManager->persist($CustomerAddress);
$this->entityManager->flush();

// 会員情報変更時にメールを送信
if($this->BaseInfo->isOptionMailNotifier()) {
// 情報のセット
$userData['userAgent'] = $request->headers->get('User-Agent');
$userData['ipAddress'] = $request->getClientIp();

$this->mailService->sendCustomerChangeNotifyMail($Customer, $userData, trans('front.mypage.delivery.notify_title'));
}

log_info('お届け先登録完了', [$id]);

$event = new EventArgs(
Expand Down Expand Up @@ -178,6 +198,15 @@ public function delete(Request $request, CustomerAddress $CustomerAddress)
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_MYPAGE_DELIVERY_DELETE_COMPLETE);

// 会員情報変更時にメールを送信
if($this->BaseInfo->isOptionMailNotifier()) {
// 情報のセット
$userData['userAgent'] = $request->headers->get('User-Agent');
$userData['ipAddress'] = $request->getClientIp();

$this->mailService->sendCustomerChangeNotifyMail($Customer, $userData, trans('front.mypage.delivery.notify_title'));
}

log_info('お届け先削除完了', [$CustomerAddress->getId()]);

return $this->redirect($this->generateUrl('mypage_delivery'));
Expand Down
27 changes: 26 additions & 1 deletion src/Eccube/Controller/ShippingMultipleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
use Eccube\Event\EventArgs;
use Eccube\Form\Type\Front\ShoppingShippingType;
use Eccube\Form\Type\ShippingMultipleType;
use Eccube\Repository\BaseInfoRepository;
use Eccube\Repository\Master\OrderItemTypeRepository;
use Eccube\Repository\Master\PrefRepository;
use Eccube\Repository\OrderRepository;
use Eccube\Service\CartService;
use Eccube\Service\MailService;
use Eccube\Service\OrderHelper;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Eccube\Service\PurchaseFlow\PurchaseFlow;
Expand Down Expand Up @@ -66,6 +68,16 @@ class ShippingMultipleController extends AbstractShoppingController
*/
protected $orderRepository;

/**
* @var MailService
*/
protected $mailService;

/**
* @var baseInfoRepository
*/
protected $baseInfoRepository;

/**
* ShippingMultipleController constructor.
*
Expand All @@ -82,14 +94,18 @@ public function __construct(
OrderItemTypeRepository $orderItemTypeRepository,
OrderHelper $orderHelper,
CartService $cartService,
PurchaseFlow $cartPurchaseFlow
PurchaseFlow $cartPurchaseFlow,
BaseInfoRepository $baseInfoRepository,
MailService $mailService
) {
$this->prefRepository = $prefRepository;
$this->orderRepository = $orderRepository;
$this->orderItemTypeRepository = $orderItemTypeRepository;
$this->orderHelper = $orderHelper;
$this->cartService = $cartService;
$this->cartPurchaseFlow = $cartPurchaseFlow;
$this->baseInfoRepository = $baseInfoRepository;
$this->mailService = $mailService;
}

/**
Expand Down Expand Up @@ -418,6 +434,15 @@ public function shippingMultipleEdit(Request $request)
];
}

// 会員情報変更時にメールを送信
if ($this->baseInfoRepository->get()->isOptionMailNotifier()) {
// 情報のセット
$userData['userAgent'] = $request->headers->get('User-Agent');
$userData['ipAddress'] = $request->getClientIp();

$this->mailService->sendCustomerChangeNotifyMail($Customer, $userData, trans('front.mypage.delivery.notify_title'));
}

$CustomerAddress->setCustomer($Customer);
$this->entityManager->persist($CustomerAddress);
$this->entityManager->flush();
Expand Down
22 changes: 21 additions & 1 deletion src/Eccube/Controller/ShoppingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Eccube\Form\Type\Front\ShoppingShippingType;
use Eccube\Form\Type\Shopping\CustomerAddressType;
use Eccube\Form\Type\Shopping\OrderType;
use Eccube\Repository\BaseInfoRepository;
use Eccube\Repository\OrderRepository;
use Eccube\Repository\TradeLawRepository;
use Eccube\Service\CartService;
Expand Down Expand Up @@ -71,6 +72,11 @@ class ShoppingController extends AbstractShoppingController
*/
protected $serviceContainer;

/**
* @var baseInfoRepository
*/
protected $baseInfoRepository;

/**
* @var TradeLawRepository
*/
Expand All @@ -94,7 +100,8 @@ public function __construct(
RateLimiterFactory $shoppingConfirmIpLimiter,
RateLimiterFactory $shoppingConfirmCustomerLimiter,
RateLimiterFactory $shoppingCheckoutIpLimiter,
RateLimiterFactory $shoppingCheckoutCustomerLimiter
RateLimiterFactory $shoppingCheckoutCustomerLimiter,
BaseInfoRepository $baseInfoRepository
) {
$this->cartService = $cartService;
$this->mailService = $mailService;
Expand All @@ -106,6 +113,7 @@ public function __construct(
$this->shoppingConfirmCustomerLimiter = $shoppingConfirmCustomerLimiter;
$this->shoppingCheckoutIpLimiter = $shoppingCheckoutIpLimiter;
$this->shoppingCheckoutCustomerLimiter = $shoppingCheckoutCustomerLimiter;
$this->baseInfoRepository = $baseInfoRepository;
}

/**
Expand Down Expand Up @@ -689,8 +697,20 @@ public function shippingEdit(Request $request, Shipping $Shipping)

if ($this->isGranted('IS_AUTHENTICATED_FULLY')) {
$this->entityManager->persist($CustomerAddress);

// 会員情報変更時にメールを送信
if ($this->baseInfoRepository->get()->isOptionMailNotifier()) {
$Customer = $this->getUser();

// 情報のセット
$userData['userAgent'] = $request->headers->get('User-Agent');
$userData['ipAddress'] = $request->getClientIp();

$this->mailService->sendCustomerChangeNotifyMail($Customer, $userData, trans('front.mypage.delivery.notify_title'));
}
}


// 合計金額の再計算
$response = $this->executePurchaseFlow($Order);
$this->entityManager->flush();
Expand Down
32 changes: 32 additions & 0 deletions src/Eccube/Entity/BaseInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ class BaseInfo extends \Eccube\Entity\AbstractEntity
*/
private $option_remember_me = true;

/**
* @var boolean
*
* @ORM\Column(name="option_mail_notifier", type="boolean", options={"default":false})
*/
private $option_mail_notifier = false;

/**
* @var string|null
*
Expand Down Expand Up @@ -943,6 +950,31 @@ public function isOptionRememberMe()
return $this->option_remember_me;
}

/**
* Set optionMailNotifier.
*
* @param boolean $optionRememberMe
*
* @return BaseInfo
*/
public function setOptionMailNotifier($optionRememberMe)
{
$this->option_mail_notifier = $optionRememberMe;

return $this;
}

/**
* Get optionRememberMe.
*
* @return boolean
*/
public function isOptionMailNotifier()
{
return $this->option_mail_notifier;
}


/**
* Set authenticationKey.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Eccube/Form/Type/Admin/ShopMasterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->add('option_mypage_order_status_display', ToggleSwitchType::class)
// 自動ログイン
->add('option_remember_me', ToggleSwitchType::class)
// 会員の重要操作時にメールを通知する
->add('option_mail_notifier', ToggleSwitchType::class)
// お気に入り商品設定
->add('option_favorite_product', ToggleSwitchType::class)
// 在庫切れ商品を非表示にする
Expand Down
Loading

0 comments on commit b809b34

Please sign in to comment.