setTitleId($titleId) ->setFirstname($firstname) ->setLastname($lastname) ->setEmail($email) ->setPassword($plainPassword) ->setReseller($reseller) ->setSponsor($sponsor) ->setDiscount($discount) ; if(!is_null($lang)) { $this->setLang($lang); } $con = Propel::getWriteConnection(CustomerTableMap::DATABASE_NAME); $con->beginTransaction(); try { $this->save($con); $address = new Address(); $address ->setTitleId($titleId) ->setFirstname($firstname) ->setLastname($lastname) ->setAddress1($address1) ->setAddress2($address2) ->setAddress3($address3) ->setPhone($phone) ->setCellphone($cellphone) ->setZipcode($zipcode) ->setCountryId($countryId) ->setIsDefault(1) ->setCustomer($this) ->save($con); $con->commit(); } catch(Exception $e) { $con->rollback(); throw $e; } } public function preInsert(ConnectionInterface $con = null) { $this->setRef($this->generateRef()); $customerEvent = new CustomerEvent($this); $this->dispatchEvent(TheliaEvents::BEFORE_CREATECUSTOMER, $customerEvent); return true; } public function postInsert(ConnectionInterface $con = null) { $customerEvent = new CustomerEvent($this); $this->dispatchEvent(TheliaEvents::AFTER_CREATECUSTOMER, $customerEvent); } public function preUpdate(ConnectionInterface $con = null) { $customerEvent = new CustomerEvent($this); $this->dispatchEvent(TheliaEvents::BEFORE_UPDATECUSTOMER, $customerEvent); return true; } public function postUpdate(ConnectionInterface $con = null) { $customerEvent = new CustomerEvent($this); $this->dispatchEvent(TheliaEvents::AFTER_UPDATECUSTOMER, $customerEvent); } protected function dispatchEvent($eventName, CustomerEvent $customerEvent) { if (!is_null($this->dispatcher)) { $this->dispatcher->dispatch($eventName, $customerEvent); } } protected function generateRef() { return uniqid(substr($this->getLastname(), 0, (strlen($this->getLastname()) >= 3) ? 3 : strlen($this->getLastname())), true); } /** * create hash for plain password and set it in Customer object * * @param string $password plain password before hashing * @return $this|Customer * @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function setPassword($password) { if ($this->isNew() && ($password === null || trim($password) == "")) { throw new InvalidArgumentException("customer password is mandatory on creation"); } if($password !== null && trim($password) != "") { $this->setAlgo("PASSWORD_BCRYPT"); return parent::setPassword(password_hash($password, PASSWORD_BCRYPT)); } return $this; } public function setDispatcher(EventDispatcherInterface $dispatcher) { $this->dispatcher = $dispatcher; } /** * {@inheritDoc} */ public function getUsername() { return $this->getEmail(); } /** * {@inheritDoc} */ public function checkPassword($password) { return password_verify($password, $this->password); } /** * {@inheritDoc} */ public function eraseCredentials() { $this->setPassword(null); } /** * {@inheritDoc} */ public function getRoles() { return array(new Role('CUSTOMER')); } }