move dispatch during customer creation process in post/preInsert methods

This commit is contained in:
Manuel Raynaud
2013-08-09 10:19:36 +02:00
parent 52ea82ae1b
commit 654220882a
3 changed files with 35 additions and 15 deletions

View File

@@ -3,6 +3,7 @@
namespace Thelia\Model;
use Symfony\Component\Config\Definition\Exception\Exception;
use Thelia\Core\Event\CustomerEvent;
use Thelia\Model\Base\Customer as BaseCustomer;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
@@ -105,16 +106,25 @@ class Customer extends BaseCustomer implements UserInterface
public function preInsert(ConnectionInterface $con = null)
{
$customerRef = new CustomRefEvent($this);
$this->setRef($this->generateRef());
$customerEvent = new CustomerEvent($this);
if (!is_null($this->dispatcher)) {
$this->dispatcher->dispatch(TheliaEvents::CREATECUSTOMER_CUSTOMREF, $customerRef);
$this->dispatcher->dispatch(TheliaEvents::BEFORE_CREATECUSTOMER, $customerEvent);
}
$this->setRef($customerRef->hasRef()? $customerRef->getRef() : $this->generateRef());
return true;
}
public function postInsert(ConnectionInterface $con = null)
{
$customerEvent = new CustomerEvent($this);
if (!is_null($this->dispatcher)) {
$this->dispatcher->dispatch(TheliaEvents::AFTER_CREATECUSTOMER, $customerEvent);
}
}
protected function generateRef()
{
return uniqid(substr($this->getLastname(), 0, (strlen($this->getLastname()) >= 3) ? 3 : strlen($this->getLastname())), true);