/** * @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; } }
/** * Generate adapter stub * * @param int $cartTotalPrice Cart total price * @param string $checkoutCurrency Checkout currency * @param string $i18nOutput Output from each translation * * @return \PHPUnit_Framework_MockObject_MockObject */ public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '') { $stubFacade = $this->getMockBuilder('\\Thelia\\Coupon\\BaseFacade')->disableOriginalConstructor()->getMock(); $address = new Address(); $address->setCountryId(10); $stubFacade->expects($this->any())->method('getDeliveryAddress')->will($this->returnValue($address)); $stubFacade->expects($this->any())->method('getConditionEvaluator')->will($this->returnValue(new ConditionEvaluator())); $stubTranslator = $this->getMockBuilder('\\Thelia\\Core\\Translation\\Translator')->disableOriginalConstructor()->getMock(); $stubTranslator->expects($this->any())->method('trans')->will($this->returnValue($i18nOutput)); $stubFacade->expects($this->any())->method('getTranslator')->will($this->returnValue($stubTranslator)); return $stubFacade; }
/** * @param AbstractDeliveryModule $moduleInstance * @param Address $deliveryAddress * @return \Symfony\Component\HttpFoundation\Response */ private function registerVirtualProductDelivery($moduleInstance, $deliveryAddress) { /* get postage amount */ $deliveryModule = $moduleInstance->getModuleModel(); $postage = OrderPostage::loadFromPostage($moduleInstance->getPostage($deliveryAddress->getCountry())); $orderEvent = $this->getOrderEvent(); $orderEvent->setDeliveryAddress($deliveryAddress->getId()); $orderEvent->setDeliveryModule($deliveryModule->getId()); $orderEvent->setPostage($postage->getAmount()); $orderEvent->setPostageTax($postage->getAmountTax()); $orderEvent->setPostageTaxRuleTitle($postage->getTaxRuleTitle()); $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_ADDRESS, $orderEvent); $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_DELIVERY_MODULE, $orderEvent); $this->getDispatcher()->dispatch(TheliaEvents::ORDER_SET_POSTAGE, $orderEvent); return $this->generateRedirectFromRoute("order.invoice"); }
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; } }
/** * Filter the query by a related \Thelia\Model\Address object * * @param \Thelia\Model\Address|ObjectCollection $address The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildCartQuery The current query, for fluid interface */ public function filterByAddressRelatedByAddressInvoiceId($address, $comparison = null) { if ($address instanceof \Thelia\Model\Address) { return $this->addUsingAlias(CartTableMap::ADDRESS_INVOICE_ID, $address->getId(), $comparison); } elseif ($address instanceof ObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(CartTableMap::ADDRESS_INVOICE_ID, $address->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { throw new PropelException('filterByAddressRelatedByAddressInvoiceId() only accepts arguments of type \\Thelia\\Model\\Address or Collection'); } }
public function saveExtraInformation(&$data, Order $order, Address $address) { $service = $this->getRequest()->request->get("tnt_service"); //By default, if no service is selected, choose the INDIVIDUAL ONE if (!in_array($service, ['INDIVIDUAL', 'ENTERPRISE', 'DEPOT', 'DROPOFFPOINT'])) { $this->getRequest()->request->set('tnt_service', 'INDIVIDUAL'); $data['tnt_service'] = 'INDIVIDUAL'; TNTFrance::setExtraOrderData($this->getRequest()->getSession()->getSessionCart()->getId(), $data); /** @var \Thelia\Model\Customer $customer */ if (null == ($customer = $order->getCustomer())) { //Customer in front $customer = $this->getRequest()->getSession()->getCustomerUser(); } //We must ask fasaibility to tnt /** @var Feasibility $ws */ $ws = $this->container->get('tnt.ws.factory')->get('feasibility'); $ws->setZipCode($customer->getDefaultAddress()->getZipcode())->setCity($customer->getDefaultAddress()->getCity())->setType($data['tnt_service']); $choices = $ws->exec(); if (count($choices) > 0) { /** @var \TNTFrance\WebService\Model\TNTService $tntService */ $tntService = $choices[0]; $this->getRequest()->request->set('tnt_serviceCode', $tntService->getServiceCode() . '-' . $tntService->getServiceLabel()); } if ($customer->getDefaultAddress()->getCellphone()) { $phoneNumber = $customer->getDefaultAddress()->getCellphone(); } elseif ($customer->getDefaultAddress()->getPhone()) { $phoneNumber = $customer->getDefaultAddress()->getPhone(); } else { throw new \Exception($this->trans('You must have a phone number to continue this order')); } $this->getRequest()->request->set('tnt_phoneNumber', str_replace(" ", "", $phoneNumber)); $service = 'INDIVIDUAL'; //throw new \Exception($this->trans('Invalid TNT service')); } switch ($service) { case 'INDIVIDUAL': if (null !== ($city = $this->getRequest()->request->get('tnt_city'))) { $address->setCity($city)->save(); } $fields = ['tnt_phoneNumber', 'tnt_accessCode', 'tnt_floorNumber', 'tnt_buldingId']; break; case 'ENTERPRISE': if (null !== ($city = $this->getRequest()->request->get('tnt_city'))) { $address->setCity($city)->save(); } $fields = ['tnt_instructions']; break; case 'DEPOT': $fields = ['tnt_pexCode', 'tnt_city', 'tnt_instructions', 'tnt_depot_address']; break; case 'DROPOFFPOINT': $fields = ['tnt_xettCode', 'tnt_contactLastName', 'tnt_contactFirstName', 'tnt_dop_address']; break; default: $fields = []; break; } foreach ($fields as $field) { $value = $this->getRequest()->request->get($field); if (in_array($field, ['tnt_dop_address', 'tnt_depot_address'])) { $data[$field] = json_decode($value); } else { $data[$field] = $value; } } // save the service code selected $serviceInfos = explode('-', $this->getRequest()->request->get("tnt_serviceCode")); $data["tnt_serviceCode"] = $serviceInfos[0]; $data["tnt_serviceLabel"] = $serviceInfos[1]; $errors = DataValidator::validateData($data, $service); if (count($errors)) { $message = ''; foreach ($errors as $error) { $message .= $error->getMessage() . '<br>'; } throw new \Exception($message); } }
/** * Filter the query by a related \Thelia\Model\Address object * * @param \Thelia\Model\Address|ObjectCollection $address the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildCustomerTitleQuery The current query, for fluid interface */ public function filterByAddress($address, $comparison = null) { if ($address instanceof \Thelia\Model\Address) { return $this->addUsingAlias(CustomerTitleTableMap::ID, $address->getTitleId(), $comparison); } elseif ($address instanceof ObjectCollection) { return $this->useAddressQuery()->filterByPrimaryKeys($address->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByAddress() only accepts arguments of type \\Thelia\\Model\\Address or Collection'); } }
/** * Declares an association between this object and a ChildAddress object. * * @param ChildAddress $v * @return \Thelia\Model\Cart The current object (for fluent API support) * @throws PropelException */ public function setAddressRelatedByAddressInvoiceId(ChildAddress $v = null) { if ($v === null) { $this->setAddressInvoiceId(NULL); } else { $this->setAddressInvoiceId($v->getId()); } $this->aAddressRelatedByAddressInvoiceId = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the ChildAddress object, it will not be re-added. if ($v !== null) { $v->addCartRelatedByAddressInvoiceId($this); } return $this; }
/** * Exclude object from result * * @param ChildAddress $address Object to remove from the list of results * * @return ChildAddressQuery The current query, for fluid interface */ public function prune($address = null) { if ($address) { $this->addUsingAlias(AddressTableMap::ID, $address->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * @param \Thelia\Model\Address $address */ public function setAddress(Address $address) { $this->address = $address; $this->setCustomer($address->getCustomer()); }
protected function initializeData(&$data, Address $address) { $defaults = ['tnt_service' => '', 'tnt_contactLastName' => $address->getLastname(), 'tnt_contactFirstName' => $address->getFirstname(), 'tnt_emailAdress' => $address->getCustomer()->getEmail(), 'tnt_phoneNumber' => $address->getPhone(), 'tnt_zipCode' => $address->getZipcode(), 'tnt_city' => $address->getCity(), 'tnt_department' => $this->getDepartmentFromZipCode($address->getZipcode())]; foreach ($defaults as $varKey => $varVal) { if (empty($data[$varKey])) { $data[$varKey] = $varVal; } } }