public function isModuleDpdPickup(OrderEvent $event)
 {
     $address = AddressIcirelaisQuery::create()->findPk($event->getDeliveryAddress());
     if ($this->check_module($event->getDeliveryModule())) {
         //tmp solution
         $request = $this->getRequest();
         $pr_code = $request->request->get('pr_code');
         if (!empty($pr_code)) {
             // Get details w/ SOAP
             $con = new \SoapClient(__DIR__ . "/../Config/exapaq.wsdl", array('soap_version' => SOAP_1_2));
             $response = $con->GetPudoDetails(array("pudo_id" => $pr_code));
             $xml = new \SimpleXMLElement($response->GetPudoDetailsResult->any);
             if (isset($xml->ERROR)) {
                 throw new \ErrorException("Error while choosing pick-up & go store: " . $xml->ERROR);
             }
             $customer_name = AddressQuery::create()->findPk($event->getDeliveryAddress());
             $request->getSession()->set('DpdPickupDeliveryId', $event->getDeliveryAddress());
             if ($address === null) {
                 $address = new AddressIcirelais();
                 $address->setId($event->getDeliveryAddress());
             }
             // France Métropolitaine
             $address->setCode($pr_code)->setCompany((string) $xml->PUDO_ITEMS->PUDO_ITEM->NAME)->setAddress1((string) $xml->PUDO_ITEMS->PUDO_ITEM->ADDRESS1)->setAddress2((string) $xml->PUDO_ITEMS->PUDO_ITEM->ADDRESS2)->setAddress3((string) $xml->PUDO_ITEMS->PUDO_ITEM->ADDRESS3)->setZipcode((string) $xml->PUDO_ITEMS->PUDO_ITEM->ZIPCODE)->setCity((string) $xml->PUDO_ITEMS->PUDO_ITEM->CITY)->setFirstname($customer_name->getFirstname())->setLastname($customer_name->getLastname())->setTitleId($customer_name->getTitleId())->setCountryId($customer_name->getCountryId())->save();
         } else {
             throw new \ErrorException("No pick-up & go store chosen for DpdPickup delivery module");
         }
     } elseif (null !== $address) {
         $address->delete();
     }
 }
Example #2
0
 /**
  * @param \Thelia\Core\Event\Order\OrderEvent $event
  */
 public function setDeliveryModule(OrderEvent $event)
 {
     $order = $event->getOrder();
     $deliveryModuleId = $event->getDeliveryModule();
     $order->setDeliveryModuleId($deliveryModuleId);
     // Reset postage cost if the delivery module had been removed
     if ($deliveryModuleId <= 0) {
         $order->setPostage(0);
         $order->setPostageTax(0);
         $order->setPostageTaxRuleTitle(null);
     }
     $event->setOrder($order);
 }
 public function isModuleSoColissimo(OrderEvent $event)
 {
     if ($this->check_module($event->getDeliveryModule())) {
         $request = $this->getRequest();
         $dom = $request->get('socolissimo-home');
         $rdv = $request->get('socolissimo-appointment');
         $pr_code = $request->get('socolissimo_code');
         $request->getSession()->set('SoColissimoDeliveryId', 0);
         $request->getSession()->set('SoColissimoDomicile', 0);
         $request->getSession()->set('SoColissimoRdv', 0);
         if ($dom) {
             $request->getSession()->set('SoColissimoDomicile', 1);
             $customer_name = AddressQuery::create()->findPk($event->getDeliveryAddress());
             $address = AddressSocolissimoQuery::create()->findPk($event->getDeliveryAddress());
             $request->getSession()->set('SoColissimoDeliveryId', $event->getDeliveryAddress());
             if ($address === null) {
                 $address = new AddressSocolissimo();
                 $address->setId($event->getDeliveryAddress());
             }
             // France Métropolitaine
             $address->setCode($pr_code)->setType("DOM")->setCompany($customer_name->getCompany())->setAddress1($customer_name->getAddress1())->setAddress2($customer_name->getAddress2())->setAddress3($customer_name->getAddress3())->setZipcode($customer_name->getZipcode())->setCity($customer_name->getCity())->setFirstname($customer_name->getFirstname())->setLastname($customer_name->getLastname())->setTitleId($customer_name->getTitleId())->setCountryId($customer_name->getCountryId())->setCellphone(null)->save();
         } elseif ($rdv) {
             $request->getSession()->set('SoColissimoRdv', 1);
             $customer_name = AddressQuery::create()->findPk($event->getDeliveryAddress());
             $address = AddressSocolissimoQuery::create()->findPk($event->getDeliveryAddress());
             $request->getSession()->set('SoColissimoDeliveryId', $event->getDeliveryAddress());
             if ($address === null) {
                 $address = new AddressSocolissimo();
                 $address->setId($event->getDeliveryAddress());
             }
             // France Métropolitaine
             $address->setCode($pr_code)->setType("RDV")->setCompany($customer_name->getCompany())->setAddress1($customer_name->getAddress1())->setAddress2($customer_name->getAddress2())->setAddress3($customer_name->getAddress3())->setZipcode($customer_name->getZipcode())->setCity($customer_name->getCity())->setFirstname($customer_name->getFirstname())->setLastname($customer_name->getLastname())->setTitleId($customer_name->getTitleId())->setCountryId($customer_name->getCountryId())->setCellphone($request->get('socolissimo-cellphone'))->save();
         } elseif (!empty($pr_code)) {
             $req = new FindById();
             $req->setId($pr_code)->setLangue("FR")->setDate(date("d/m/Y"))->setAccountNumber(ConfigQuery::read('socolissimo_login'))->setPassword(ConfigQuery::read('socolissimo_pwd'));
             $response = $req->exec();
             $customer_name = AddressQuery::create()->findPk($event->getDeliveryAddress());
             $address = AddressSocolissimoQuery::create()->findPk($event->getDeliveryAddress());
             $request->getSession()->set('SoColissimoDeliveryId', $event->getDeliveryAddress());
             if ($address === null) {
                 $address = new AddressSocolissimo();
                 $address->setId($event->getDeliveryAddress());
             }
             // France Métropolitaine
             $address->setCode($pr_code)->setType($response->typeDePoint)->setCompany($response->nom)->setAddress1($response->adresse1)->setAddress2($response->adresse2)->setAddress3($response->adresse3)->setZipcode($response->codePostal)->setCity($response->localite)->setFirstname($customer_name->getFirstname())->setLastname($customer_name->getLastname())->setTitleId($customer_name->getTitleId())->setCountryId($customer_name->getCountryId())->save();
         }
     }
 }
Example #4
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);
     }
 }
Example #5
0
 public function setModuleDelivery(OrderEvent $event)
 {
     if ($event->getDeliveryModule() == TNTFrance::getModuleId()) {
         $request = $this->getRequest();
         $id = $request->getSession()->getSessionCart()->getId();
         $address = TNTFrance::getCartDeliveryAddress($this->getRequest());
         $data = TNTFrance::getExtraOrderData($id);
         try {
             $this->saveExtraInformation($data, $event->getOrder(), $address);
             //We must recalcul postage when this informations are saved :(
             if (array_key_exists('tnt_serviceCode', $data)) {
                 $cartEvent = new CartEvent($this->getRequest()->getSession()->getSessionCart($event->getDispatcher()));
                 $event->getDispatcher()->dispatch(OrderAction::TNT_CALCUL_CART_WEIGHT, $cartEvent);
                 $postage = TNTFrance::calculPriceForService($data['tnt_serviceCode'], $cartEvent->getCart()->getVirtualColumn('total_package'), $cartEvent->getCart()->getVirtualColumn('total_weight'));
                 $event->getOrder()->setPostage($postage);
                 $event->setPostage($postage);
             }
         } catch (\Exception $ex) {
             throw $ex;
         }
         TNTFrance::setExtraOrderData($id, $data);
     }
 }