示例#1
0
 /**
  * @param  int                                       $titleId          customer title id (from customer_title table)
  * @param  string                                    $firstname        customer first name
  * @param  string                                    $lastname         customer last name
  * @param  string                                    $address1         customer address
  * @param  string                                    $address2         customer adress complement 1
  * @param  string                                    $address3         customer adress complement 2
  * @param  string                                    $phone            customer phone number
  * @param  string                                    $cellphone        customer cellphone number
  * @param  string                                    $zipcode          customer zipcode
  * @param  string                                    $city
  * @param  int                                       $countryId        customer country id (from Country table)
  * @param  string                                    $email            customer email, must be unique
  * @param  string                                    $plainPassword    customer plain password, hash is made calling setPassword method. Not mandatory parameter but an exception is thrown if customer is new without password
  * @param  string                                    $lang
  * @param  int                                       $reseller
  * @param  null                                      $sponsor
  * @param  int                                       $discount
  * @param  null                                      $company
  * @param  null                                      $ref
  * @param  bool                                      $forceEmailUpdate true if the email address could be updated.
  * @param  int                                       $stateId          customer state id (from State table)
  * @throws \Exception
  * @throws \Propel\Runtime\Exception\PropelException
  */
 public function createOrUpdate($titleId, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $city, $countryId, $email = null, $plainPassword = null, $lang = null, $reseller = 0, $sponsor = null, $discount = 0, $company = null, $ref = null, $forceEmailUpdate = false, $stateId = null)
 {
     $this->setTitleId($titleId)->setFirstname($firstname)->setLastname($lastname)->setEmail($email, $forceEmailUpdate)->setPassword($plainPassword)->setReseller($reseller)->setSponsor($sponsor)->setDiscount($discount)->setRef($ref);
     if (!is_null($lang)) {
         $this->setLangId($lang);
     }
     $con = Propel::getWriteConnection(CustomerTableMap::DATABASE_NAME);
     $con->beginTransaction();
     try {
         if ($this->isNew()) {
             $address = new Address();
             $address->setLabel(Translator::getInstance()->trans("Main address"))->setCompany($company)->setTitleId($titleId)->setFirstname($firstname)->setLastname($lastname)->setAddress1($address1)->setAddress2($address2)->setAddress3($address3)->setPhone($phone)->setCellphone($cellphone)->setZipcode($zipcode)->setCity($city)->setCountryId($countryId)->setStateId($stateId)->setIsDefault(1);
             $this->addAddress($address);
             if (ConfigQuery::isCustomerEmailConfirmationEnable()) {
                 $this->setConfirmationToken(bin2hex(random_bytes(32)));
             }
         } else {
             $address = $this->getDefaultAddress();
             $address->setCompany($company)->setTitleId($titleId)->setFirstname($firstname)->setLastname($lastname)->setAddress1($address1)->setAddress2($address2)->setAddress3($address3)->setPhone($phone)->setCellphone($cellphone)->setZipcode($zipcode)->setCity($city)->setCountryId($countryId)->setStateId($stateId)->save($con);
         }
         $this->save($con);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
 }
示例#2
0
 protected function createOrUpdate(AddressModel $addressModel, AddressCreateOrUpdateEvent $event)
 {
     $addressModel->setDispatcher($event->getDispatcher());
     $con = Propel::getWriteConnection(AddressTableMap::DATABASE_NAME);
     $con->beginTransaction();
     try {
         $addressModel->setLabel($event->getLabel())->setTitleId($event->getTitle())->setFirstname($event->getFirstname())->setLastname($event->getLastname())->setAddress1($event->getAddress1())->setAddress2($event->getAddress2())->setAddress3($event->getAddress3())->setZipcode($event->getZipcode())->setCity($event->getCity())->setCountryId($event->getCountry())->setStateId($event->getState())->setCellphone($event->getCellphone())->setPhone($event->getPhone())->setCompany($event->getCompany())->save();
         if ($event->getIsDefault() && !$addressModel->getIsDefault()) {
             $addressModel->makeItDefault();
         }
         $event->setAddress($addressModel);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollback();
         throw $e;
     }
 }