Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit dbbffb82 authored by Nicolas's avatar Nicolas
Browse files

feat: Create Observer Base

parent cbf91cda
No related branches found
No related tags found
No related merge requests found
...@@ -84,6 +84,7 @@ class SendCustomer extends AbstractHelper ...@@ -84,6 +84,7 @@ class SendCustomer extends AbstractHelper
*/ */
public function execute(string $origin, CustomerInterface $customer) public function execute(string $origin, CustomerInterface $customer)
{ {
return 'toto';
/* Mise en place des données du customer dans le tableau de data */ /* Mise en place des données du customer dans le tableau de data */
$this->data[0]['id'] = $customer->getId(); $this->data[0]['id'] = $customer->getId();
$this->data[0]['firstname'] = $customer->getFirstname(); $this->data[0]['firstname'] = $customer->getFirstname();
......
...@@ -4,35 +4,18 @@ namespace NicolasBejean\Customer\Observer; ...@@ -4,35 +4,18 @@ namespace NicolasBejean\Customer\Observer;
use Magento\Framework\Event\Observer; use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface; use Magento\Framework\Event\ObserverInterface;
use Magento\Customer\Api\Data\CustomerInterface;
use NicolasBejean\Customer\Helper\SendCustomer;
/** /**
* Class CustomerRegisterSuccess * Class SendCustomerDataToElasticsearch
* *
* @category PHP * @category PHP
* @package NicolasBejean\Customer\Observer * @package NicolasBejean\Customer\Observer
* @author Nicolas Béjean <nicolas@bejean.eu> * @author Nicolas Béjean <nicolas@bejean.eu>
* @license https://lab.frogg.it/bejean-developpement/magento-2/modules/customer/-/blob/master/LICENCE GPL3 Licence * @license https://lab.frogg.it/bejean-developpement/magento-2/modules/customer/-/blob/master/LICENCE GPL3 Licence
* @link https://www.bejean.eu * @link https://www.bejean.eu
*/ */
class CustomerRegisterSuccess implements ObserverInterface class SendCustomerDataToElasticsearch implements ObserverInterface
{ {
/** public function __construct() {}
* @var SendCustomer
*/
protected SendCustomer $sendCustomer;
/**
* CustomerRegisterSuccess constructor.
* @param SendCustomer $sendCustomer
*/
public function __construct(
SendCustomer $sendCustomer
) {
$this->sendCustomer = $sendCustomer;
}
/** /**
* Execute method * Execute method
...@@ -41,15 +24,10 @@ class CustomerRegisterSuccess implements ObserverInterface ...@@ -41,15 +24,10 @@ class CustomerRegisterSuccess implements ObserverInterface
*/ */
public function execute(Observer $observer) public function execute(Observer $observer)
{ {
/* Récupère l'événement */
$event = $observer->getEvent(); $event = $observer->getEvent();
/* Vérifie si le nom de l'événement est bien celui souhaité */
if ($event->getName() === 'customer_register_success') { if ($event->getName() === 'customer_register_success') {
/** @var CustomerInterface $customer */
$customer = $observer->getData('customer');
$this->sendCustomer->execute('frontend', $customer);
} }
} }
} }
<?xml version="1.0"?> <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="customer_register_success"> <event name="customer_register_success">
<observer name="myCustomerRegisterSuccessEvent" instance="NicolasBejean\Customer\Observer\CustomerRegisterSuccess" /> <observer name="send_customer_data_to_elasticsearch" instance="NicolasBejean\Customer\Observer\SendCustomerDateToElasticsearch" />
</event> </event>
</config> </config>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment