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
*/
public function execute(string $origin, CustomerInterface $customer)
{
return 'toto';
/* Mise en place des données du customer dans le tableau de data */
$this->data[0]['id'] = $customer->getId();
$this->data[0]['firstname'] = $customer->getFirstname();
......
......@@ -4,35 +4,18 @@ 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
* Class SendCustomerDataToElasticsearch
*
* @category PHP
* @package NicolasBejean\Customer\Observer
* @package NicolasBejean\Customer\Observer
* @author Nicolas Béjean <nicolas@bejean.eu>
* @license https://lab.frogg.it/bejean-developpement/magento-2/modules/customer/-/blob/master/LICENCE GPL3 Licence
* @link https://www.bejean.eu
*/
class CustomerRegisterSuccess implements ObserverInterface
class SendCustomerDataToElasticsearch implements ObserverInterface
{
/**
* @var SendCustomer
*/
protected SendCustomer $sendCustomer;
/**
* CustomerRegisterSuccess constructor.
* @param SendCustomer $sendCustomer
*/
public function __construct(
SendCustomer $sendCustomer
) {
$this->sendCustomer = $sendCustomer;
}
public function __construct() {}
/**
* Execute method
......@@ -41,15 +24,10 @@ class CustomerRegisterSuccess implements ObserverInterface
*/
public function execute(Observer $observer)
{
/* 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);
}
}
}
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<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>
</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