Esempio n. 1
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;
     }
 }
Esempio n. 2
0
 /**
  * @param  OrderEvent                                     $event
  * @throws \Thelia\Form\Exception\FormValidationException
  */
 public function cellphoneCheck(OrderEvent $event)
 {
     if (Predict::getModuleId() === $event->getDeliveryModule()) {
         $cellphone = $this->request->request->get("predict_cellphone");
         $cellphone = str_replace(array(' ', '.', '-', ',', ';', '/', '\\', '(', ')'), '', $cellphone);
         $partial_number = "";
         if (empty($cellphone) || !preg_match('#^[0|\\+33][6-7]([0-9]{8})$#', $cellphone, $partial_number)) {
             throw new FormValidationException(Translator::getInstance()->trans("You must give a cellphone number in order to use Predict services", [], Predict::MESSAGE_DOMAIN));
         }
         $cellphone = str_replace("+33", "0", $cellphone);
         $banned_cellphones = array('00000000', '11111111', '22222222', '33333333', '44444444', '55555555', '66666666', '77777777', '88888888', '99999999', '12345678', '23456789', '98765432');
         if (in_array($partial_number[1], $banned_cellphones)) {
             throw new FormValidationException(Translator::getInstance()->trans("This phone number is not valid", [], Predict::MESSAGE_DOMAIN));
         }
         /** @var \Thelia\Model\Customer $customer */
         $customer = $this->getRequest()->getSession()->getCustomerUser();
         $address = $customer->getDefaultAddress();
         $addressEvent = new AddressCreateOrUpdateEvent($address->getLabel(), $address->getTitleId(), $address->getFirstname(), $address->getLastname(), $address->getAddress1(), $address->getAddress2(), $address->getAddress3(), $address->getZipcode(), $address->getCity(), $address->getCountryId(), $cellphone, $address->getPhone(), $address->getCompany());
         $addressEvent->setAddress($address);
         $dispatcher = $event->getDispatcher();
         $dispatcher->dispatch(TheliaEvents::ADDRESS_UPDATE, $addressEvent);
     }
 }
Esempio n. 3
0
 /**
  * Bug found in Thelia 2.0.2
  */
 public function testUpdateDefaultAddress()
 {
     /**
      * Disable propel cache in order to get a new instance of the
      * active record in $updatedAddress
      */
     Propel::disableInstancePooling();
     /**
      * Get a customer and it's default address
      */
     $customer = CustomerQuery::create()->findOne();
     $defaultAddress = $customer->getDefaultAddress();
     $addressId = $defaultAddress->getId();
     /**
      * Try to update the address, and set the isDefault argument,
      * that should keep this address as the default one.
      */
     $addressEvent = new AddressCreateOrUpdateEvent("", 1, "Thelia modif", "Thelia modif", "cour des étoiles", "rue des miracles", "", "63000", "clermont-ferrand", 64, "0102030405", "", "", 1);
     $addressEvent->setAddress($defaultAddress);
     $addressEvent->setDispatcher($this->getMock("Symfony\\Component\\EventDispatcher\\EventDispatcherInterface"));
     /**
      * Do the update
      */
     $actionAddress = new Address();
     $actionAddress->update($addressEvent);
     $updatedAddress = AddressQuery::create()->findPk($addressId);
     /**
      * This address should still be the default address
      */
     $this->assertEquals(1, $updatedAddress->getIsDefault());
     /**
      * Renable it after
      */
     Propel::enableInstancePooling();
 }