5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

EC-CUBE4で会員登録時にポイントを付与するカスタマイズ方法

Posted at

以下のようにEventを作成することで会員登録時にポイントを付与するカスタマイズが可能です。

作成するファイル
app/Customize/EventListener/EntryEvent.php

app/Customize/EventListener/EntryEvent.php
<?php


namespace Customize\EventListener;


use Doctrine\ORM\EntityManagerInterface;
use Eccube\Entity\Customer;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class EntryEvent implements EventSubscriberInterface
{
    /**
     * @var EntityManagerInterface
     */
    private $entityManager;

    /**
     * EntryListener constructor.
     * @param EntityManagerInterface $entityManager
     */
    public function __construct(EntityManagerInterface $entityManager)
    {
        $this->entityManager = $entityManager;
    }

    public function onFrontEntryIndexComplete(EventArgs $eventArgs)
    {
        /** @var Customer $Customer */
        $Customer = $eventArgs->getArgument('Customer');

        // ポイントをセット
        $Customer->setPoint(100);

        // データベースに永続化
        $this->entityManager->persist($Customer);
        $this->entityManager->flush();
    }

    public static function getSubscribedEvents()
    {
        return [
            EccubeEvents::FRONT_ENTRY_INDEX_COMPLETE => 'onFrontEntryIndexComplete',
        ];
    }
}
5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?