diff --git a/core/lib/Thelia/Action/Customer.php b/core/lib/Thelia/Action/Customer.php index 916e53a96..6958e11df 100755 --- a/core/lib/Thelia/Action/Customer.php +++ b/core/lib/Thelia/Action/Customer.php @@ -116,8 +116,7 @@ class Customer extends BaseAction implements EventSubscriberInterface $customer = CustomerQuery::create()->findPk(1); - $customerEvent = new CustomerEvent($customer); - $event->getDispatcher()->dispatch(TheliaEvents::BEFORE_CHANGECUSTOMER, $customerEvent); + $data = $form->getData(); @@ -134,8 +133,7 @@ class Customer extends BaseAction implements EventSubscriberInterface $data["country"] ); - $customerEvent->customer = $customer; - $event->getDispatcher()->dispatch(TheliaEvents::AFTER_CHANGECUSTOMER, $customerEvent); + // Update the logged-in user, and redirect to the success URL (exits) // We don-t send the login event, as the customer si already logged. diff --git a/core/lib/Thelia/Model/Customer.php b/core/lib/Thelia/Model/Customer.php index d0a520d3c..11179cf56 100755 --- a/core/lib/Thelia/Model/Customer.php +++ b/core/lib/Thelia/Model/Customer.php @@ -109,9 +109,7 @@ class Customer extends BaseCustomer implements UserInterface $this->setRef($this->generateRef()); $customerEvent = new CustomerEvent($this); - if (!is_null($this->dispatcher)) { - $this->dispatcher->dispatch(TheliaEvents::BEFORE_CREATECUSTOMER, $customerEvent); - } + $this->dispatchEvent(TheliaEvents::BEFORE_CREATECUSTOMER, $customerEvent); return true; } @@ -119,10 +117,30 @@ class Customer extends BaseCustomer implements UserInterface public function postInsert(ConnectionInterface $con = null) { $customerEvent = new CustomerEvent($this); - if (!is_null($this->dispatcher)) { - $this->dispatcher->dispatch(TheliaEvents::AFTER_CREATECUSTOMER, $customerEvent); - } + $this->dispatchEvent(TheliaEvents::AFTER_CREATECUSTOMER, $customerEvent); + + } + + public function preUpdate(ConnectionInterface $con = null) + { + $customerEvent = new CustomerEvent($this); + $this->dispatchEvent(TheliaEvents::BEFORE_CHANGECUSTOMER, $customerEvent); + + return true; + } + + public function postUpdate(ConnectionInterface $con = null) + { + $customerEvent = new CustomerEvent($this); + $this->dispatchEvent(TheliaEvents::AFTER_CHANGECUSTOMER, $customerEvent); + } + + protected function dispatchEvent($eventName, CustomerEvent $customerEvent) + { + if (!is_null($this->dispatcher)) { + $this->dispatcher->dispatch($eventName, $customerEvent); + } } protected function generateRef()