public function replace()
 {
     $country = $this->getRequest()->get('country_id', $this->container->get('thelia.taxEngine')->getDeliveryCountry()->getId());
     $this->checkXmlHttpRequest();
     /** @var \Thelia\Model\Customer $customer */
     $customer = $this->getSession()->getCustomerUser();
     $args = array('country' => $country, "predict_id" => Predict::getModuleId(), "customer_cellphone" => $customer->getDefaultAddress()->getCellphone());
     return $this->render('ajax/order-delivery-module-list', $args);
 }
Example #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);
     }
 }