From 7545085350a9cbb9961b9dcdbad8cbfce87a9a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20B=C3=A9jean?= <nicolas@bejean.eu> Date: Sat, 30 May 2020 21:17:19 +0200 Subject: [PATCH] =?UTF-8?q?D=C3=A9veloppement=20de=20l'observer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Observer/CustomerRegisterSuccess.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Observer/CustomerRegisterSuccess.php b/Observer/CustomerRegisterSuccess.php index 0348a81..970f821 100644 --- a/Observer/CustomerRegisterSuccess.php +++ b/Observer/CustomerRegisterSuccess.php @@ -4,6 +4,10 @@ namespace NicolasBejean\Customer\Observer; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; +use Magento\Customer\Api\Data\CustomerInterface; + +use NicolasBejean\Customer\Helper\SendCustomer; + /** * Class CustomerRegisterSuccess * @@ -16,11 +20,18 @@ use Magento\Framework\Event\ObserverInterface; class CustomerRegisterSuccess implements ObserverInterface { /** - * CustomerRegisterSuccess constructor. + * @var SendCustomer */ - public function __construct() - { + protected $sendCustomer; + /** + * CustomerRegisterSuccess constructor. + * @param SendCustomer $sendCustomer + */ + public function __construct( + SendCustomer $sendCustomer + ) { + $this->sendCustomer = $sendCustomer; } /** @@ -30,6 +41,15 @@ class CustomerRegisterSuccess implements ObserverInterface */ public function execute(Observer $observer) { - // TODO: Implement execute() method. + /* Récupère l'événement */ + $event = $observer->getEvent(); + + /* Vérifie si le nom de l'événement est bien celui souhaité */ + if ($event->getName() === 'customer_register_success') { + /** @var CustomerInterface $customer */ + $customer = $observer->getData('customer'); + + $this->sendCustomer->execute('frontend', $customer); + } } } -- GitLab