/**
  * Get lat lon by address
  * @author Oleg D.
  */
 function getLatLon($address, $updateAddress = 0)
 {
     $addressString = $city = $state = $country = '';
     if (!empty($address['address'])) {
         $addressString = $address['address'] . ' ' . $address['address2'] . ' ' . $address['address3'];
         if (!empty($address['city'])) {
             $city = $address['city'];
         }
         if (!empty($address['Country']['name'])) {
             $country = $address['Country']['name'];
         } elseif (!empty($address['country_name'])) {
             $country = $address['country_name'];
         }
         if (!empty($address['Provincestate']['name'])) {
             $state = $address['Provincestate']['name'];
         } elseif (!empty($address['state_name'])) {
             $state = $address['state_name'];
         }
         App::import('Vendor', 'GoogleMapAPI', array('file' => 'class.GoogleMapAPI.php'));
         $map = new GoogleMapAPI();
         $map->setAPIKey(GOOGLE_MAP_KEY);
         $latLon = $map->getCoordsByAddress(trim($addressString), $city, $state, $country);
         if ($updateAddress && !empty($address['id']) && !empty($latLon['lat']) && !empty($latLon['lon'])) {
             $Address = new Address();
             $Address->save(array('id' => $address['id'], 'latitude' => $latLon['lat'], 'longitude' => $latLon['lon']));
         }
         return $latLon;
     } else {
         return false;
     }
 }
Example #2
0
 public function getPeople($ids, $profileDetails)
 {
     $ret = array();
     $query = "select * from user_profile where user_id in (" . implode(',', $ids) . ")";
     $res = mysql_query($query);
     if ($res) {
         while ($row = @mysql_fetch_assoc($res)) {
             $person_id = $row['user_id'];
             $name = new Name($row['first_name'] . ' ' . $row['last_name']);
             $name->setGivenName($row['first_name']);
             $name->setFamilyName($row['last_name']);
             $person = new Person($row['user_id'], $name);
             $person->setProfileUrl($row['profile_url']);
             $date = date($row['date_of_birth']);
             $person->setDateOfBirth($date);
             $address = new Address($row['city']);
             $address->setLocality($row['city']);
             $person->setAddresses($address);
             $interests = $row['interests'];
             $interests = explode(',', $interests);
             $person->setInterests($interests);
             $person->setThumbnailUrl(!empty($row['user_image']) ? $this->url_prefix . $row['user_image'] : '');
             if (!empty($row['Gender'])) {
                 if ($row['Gender'] == 'f') {
                     $person->setGender('FEMALE');
                 } else {
                     $person->setGender('MALE');
                 }
             }
             $ret[$person_id] = $person;
         }
     }
     return $ret;
 }
Example #3
0
 function deleteAction()
 {
     $id = AF::get($_POST, 'id', 0);
     $modelsID = explode(',', $id);
     $errors = FALSE;
     foreach ($modelsID as $id) {
         $model = new Address();
         $model->model_uset_id = $this->user->user_id;
         if ($model->findByPk($id)) {
             $model->delete($id);
         } else {
             $errors = TRUE;
         }
         if ($model->getErrors()) {
             $errors = TRUE;
         }
         unset($model);
     }
     if (isset($_POST['ajax'])) {
         AF::setJsonHeaders('json');
         if ($errors) {
             Message::echoJsonError(__('address_not_deleted'));
         } else {
             Message::echoJsonSuccess(__('address_deleted'));
         }
     }
     $this->redirect();
 }
Example #4
0
 public function createAddressFromCoordinates($lat, $lng)
 {
     $addressResult = $this->geocoder->reverseGeocode($lat, $lng);
     $address = new Address();
     $address->updateFromAddressResult($addressResult);
     return $address;
 }
Example #5
0
 /**
  * Runs the test.
  */
 public function test()
 {
     $email = '*****@*****.**';
     $name = 'Jyxo';
     // Email and name given
     $address = new Address($email, $name);
     $this->assertEquals($email, $address->getEmail());
     $this->assertEquals($name, $address->getName());
     // Only email given
     $address = new Address($email);
     $this->assertEquals($email, $address->getEmail());
     $this->assertEquals('', $address->getName());
     // It is necessary to trim whitespace
     $address = new Address(' ' . $email, $name . ' ');
     $this->assertEquals($email, $address->getEmail());
     $this->assertEquals($name, $address->getName());
     // Invalid email
     try {
         $address = new Address('žlutý kůň@jyxo.com', $name);
         $this->fail(sprintf('Expected exception %s.', \InvalidArgumentException::class));
     } catch (\PHPUnit_Framework_AssertionFailedError $e) {
         throw $e;
     } catch (\Exception $e) {
         // Correctly thrown exception
         $this->assertInstanceOf(\InvalidArgumentException::class, $e);
     }
 }
 public function up()
 {
     $this->addColumn($this->tableName, $this->columnName, 'int');
     /** @var $data Office[] */
     $data = Office::model()->findAll();
     $migratedAddresses = [];
     foreach ($data as $office) {
         $fullAddress = implode(' ', [$office->address1, $office->address2, $office->address3, $office->address4]);
         if (isset($migratedAddresses[$fullAddress])) {
             $office->addressId = $migratedAddresses[$fullAddress]->id;
             $office->save(false);
             continue;
         }
         $parts = explode(' ', $office->address1);
         $buildingNumber = array_shift($parts);
         $line2 = implode(' ', $parts);
         $address = new Address();
         $address->line1 = $buildingNumber;
         $address->line2 = $line2;
         $address->line5 = $office->address3;
         $address->postcode = $office->postcode;
         $address->save();
         $migratedAddresses[$fullAddress] = $address;
         $office->addressId = $migratedAddresses[$fullAddress]->id;
         $office->save(false);
         continue;
     }
 }
 public function actionCreate()
 {
     if ($model = Shop::getCustomer()) {
         $address = $model->address;
     } else {
         $model = new Customer();
     }
     if (isset($_POST['Customer'])) {
         $model->attributes = $_POST['Customer'];
         if (isset($_POST['Address'])) {
             $address = new Address();
             $address->attributes = $_POST['Address'];
             if ($address->save()) {
                 $model->address_id = $address->id;
             }
         }
         if (!Yii::app()->user->isGuest) {
             $model->user_id = Yii::app()->user->id;
         }
         if ($model->save()) {
             Yii::app()->user->setState('customer_id', $model->customer_id);
             $this->redirect(array('//shop/order/create', 'customer' => $model->customer_id));
         }
     }
     $this->render('create', array('customer' => $model, 'address' => isset($address) ? $address : new Address()));
 }
Example #8
0
 function save($id = FALSE)
 {
     if ($_POST) {
         $about = new Address($id);
         // if($_FILES['image']['name'])
         // {
         // if($about->id){
         // $about->delete_file($about->id,'uploads/about_us/','image');
         // }
         // $_POST['image'] = $about->upload($_FILES['image'],'uploads/about_us/',260,195);
         // }
         // if($_FILES['imagemap']['name'])
         // {
         // if($about->id){
         // $about->delete_file($about->id,'uploads/about_us/','imagemap');
         // }
         // $_POST['imagemap'] = $about->upload($_FILES['imagemap'],'uploads/about_us/');
         // }
         $_POST['name'] = lang_encode($_POST['name']);
         $_POST['address'] = lang_encode($_POST['address']);
         $_POST['tel'] = lang_encode($_POST['tel']);
         $_POST['facebook'] = lang_encode($_POST['facebook']);
         $_POST['twitter'] = lang_encode($_POST['twitter']);
         $_POST['googleplus'] = lang_encode($_POST['googleplus']);
         $_POST['open'] = lang_encode($_POST['open']);
         $_POST['open2'] = lang_encode($_POST['open2']);
         //$_POST['service_time'] = lang_encode($_POST['service_time']);
         $_POST['detail'] = lang_encode($_POST['detail']);
         // $_POST['user_id'] = $this->session->userdata('id');
         $about->from_array($_POST);
         $about->save();
         set_notify('success', lang('save_data_complete'));
     }
     redirect('addresses/admin/addresses');
 }
Example #9
0
 public function setAddress(Address $address)
 {
     if ($this->address !== $address) {
         $this->address = $address;
         $address->setUser($this);
     }
 }
Example #10
0
 public static function compare(Address $a, Address $b)
 {
     if ($a->toArray() == $b->toArray()) {
         return true;
     }
     return false;
 }
Example #11
0
 /**
  * @param Address $address
  * @return bool
  */
 public function isEqualTo(Address $address)
 {
     if ($this->getArray() === $address->getArray()) {
         return true;
     }
     return false;
 }
Example #12
0
 public function renderForm()
 {
     if (!($obj = $this->loadObject(true))) {
         return;
     }
     $image = _PS_STORE_IMG_DIR_ . $obj->id . '.jpg';
     $image_url = ImageManager::thumbnail($image, $this->table . '_' . (int) $obj->id . '.' . $this->imageType, 350, $this->imageType, true, true);
     $image_size = file_exists($image) ? filesize($image) / 1000 : false;
     $tmp_addr = new Address();
     $res = $tmp_addr->getFieldsRequiredDatabase();
     $required_fields = array();
     foreach ($res as $row) {
         $required_fields[(int) $row['id_required_field']] = $row['field_name'];
     }
     $this->fields_form = array('legend' => array('title' => $this->l('Stores'), 'icon' => 'icon-home'), 'input' => array(array('type' => 'text', 'label' => $this->l('Name'), 'name' => 'name', 'required' => false, 'hint' => array($this->l('Store name (e.g. City Center Mall Store).'), $this->l('Allowed characters: letters, spaces and %s'))), array('type' => 'text', 'label' => $this->l('Address'), 'name' => 'address1', 'required' => true), array('type' => 'text', 'label' => $this->l('Address (2)'), 'name' => 'address2'), array('type' => 'text', 'label' => $this->l('Zip/postal Code'), 'name' => 'postcode', 'required' => in_array('postcode', $required_fields)), array('type' => 'text', 'label' => $this->l('City'), 'name' => 'city', 'required' => true), array('type' => 'select', 'label' => $this->l('Country'), 'name' => 'id_country', 'required' => true, 'default_value' => (int) $this->context->country->id, 'options' => array('query' => Country::getCountries($this->context->language->id), 'id' => 'id_country', 'name' => 'name')), array('type' => 'select', 'label' => $this->l('State'), 'name' => 'id_state', 'required' => true, 'options' => array('id' => 'id_state', 'name' => 'name', 'query' => null)), array('type' => 'latitude', 'label' => $this->l('Latitude / Longitude'), 'name' => 'latitude', 'required' => true, 'maxlength' => 12, 'hint' => $this->l('Store coordinates (e.g. 45.265469/-47.226478).')), array('type' => 'text', 'label' => $this->l('Phone'), 'name' => 'phone'), array('type' => 'text', 'label' => $this->l('Fax'), 'name' => 'fax'), array('type' => 'text', 'label' => $this->l('Email address'), 'name' => 'email'), array('type' => 'textarea', 'label' => $this->l('Note'), 'name' => 'note', 'cols' => 42, 'rows' => 4), array('type' => 'switch', 'label' => $this->l('Status'), 'name' => 'active', 'required' => false, 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))), 'hint' => $this->l('Whether or not to display this store.')), array('type' => 'file', 'label' => $this->l('Picture'), 'name' => 'image', 'display_image' => true, 'image' => $image_url ? $image_url : false, 'size' => $image_size, 'hint' => $this->l('Storefront picture.'))), 'hours' => array(), 'submit' => array('title' => $this->l('Save')));
     if (Shop::isFeatureActive()) {
         $this->fields_form['input'][] = array('type' => 'shop', 'label' => $this->l('Shop association'), 'name' => 'checkBoxShopAsso');
     }
     $days = array();
     $days[1] = $this->l('Monday');
     $days[2] = $this->l('Tuesday');
     $days[3] = $this->l('Wednesday');
     $days[4] = $this->l('Thursday');
     $days[5] = $this->l('Friday');
     $days[6] = $this->l('Saturday');
     $days[7] = $this->l('Sunday');
     $hours = $this->getFieldValue($obj, 'hours');
     if (!empty($hours)) {
         $hours_unserialized = Tools::unSerialize($hours);
     }
     $this->fields_value = array('latitude' => $this->getFieldValue($obj, 'latitude') ? $this->getFieldValue($obj, 'latitude') : Configuration::get('PS_STORES_CENTER_LAT'), 'longitude' => $this->getFieldValue($obj, 'longitude') ? $this->getFieldValue($obj, 'longitude') : Configuration::get('PS_STORES_CENTER_LONG'), 'days' => $days, 'hours' => isset($hours_unserialized) ? $hours_unserialized : false);
     return parent::renderForm();
 }
 public function testForm()
 {
     $address = new Address(array('Country' => 'NZ', 'State' => 'Wellington', 'City' => 'TeAro', 'PostalCode' => '1333', 'Address' => '23 Blah Street', 'AddressLine2' => 'Fitzgerald Building, Foor 3', 'Company' => 'Ink inc', 'FirstName' => 'Jerald', 'Surname' => 'Smith', 'Phone' => '12346678'));
     $fields = $address->getFrontEndFields();
     $requiremetns = $address->getRequiredFields();
     $this->assertEquals("23 Blah Street|Fitzgerald Building, Foor 3|TeAro|Wellington|1333|NZ", $address->toString("|"));
 }
Example #14
0
 public function displayMain()
 {
     global $smarty, $link, $cookie;
     $errors = false;
     if (!$cookie->logged || !User::checkPassword($cookie->id_user, $cookie->passwd)) {
         Tools::redirect($link->getPage('userView'));
     }
     $referer = Tools::Q('referer') ? $link->getPage(Tools::Q('referer')) : $link->getPage('MyAddressesView');
     if ($id_address = Tools::Q('id')) {
         $address = new Address((int) $id_address);
         if (Tools::isSubmit('saveAddress')) {
             $address->copyFromPost();
             if ($address->update()) {
                 Tools::redirect($referer);
             } else {
                 $errors = $address->_errors;
             }
         }
         $smarty->assign('address', $address);
     } elseif (Tools::isSubmit('saveAddress')) {
         $address = new Address();
         $address->copyFromPost();
         $address->id_user = $cookie->id_user;
         if ($address->add()) {
             Tools::redirect($referer);
         } else {
             $errors = $address->_errors;
         }
     }
     $countrys = Country::loadData(1, 1000, 'position', 'asc', array('active' => true));
     $smarty->assign(array('referer' => Tools::Q('referer'), 'countrys' => $countrys, 'errors' => $errors));
     return $smarty->fetch('address.tpl');
 }
 public function add()
 {
     if (!isset($_POST['card_number'])) {
         $this->redirect_to();
     }
     $paymentMethod = new Payment_Method();
     $paymentMethod->assignProperties($_POST);
     $paymentMethod->runValidations();
     if ($_POST['include_new_address'] == "1") {
         require_once '../app/models/Address.php';
         $address = new Address();
         $address->assignProperties($_POST);
         $address->runValidations();
         // A valid payment method will still have one error - fk_payment_method_address  will be missing.
         if (count($paymentMethod->errorsList) == 1 && isset($paymentMethod->errorsList['fk_payment_method_address'])) {
             $addressId = $address->savePreparedStatementToDb('address', $address->properties);
         }
     } else {
         $addressId = $_POST['addressId'];
     }
     $paymentMethod->properties['fk_payment_method_address'] = $addressId;
     $paymentMethodId = $paymentMethod->savePreparedStatementToDb('payment_method', $paymentMethod->properties);
     $_SESSION['paymentMethodId'] = $paymentMethodId;
     $_SESSION['payment_method'] = $paymentMethod;
     if (isset($_SESSION['address'])) {
         $_SESSION['address'] = $address;
     }
     $this->redirect_to($_POST['redirect']);
 }
Example #16
0
 public function __construct(FirstName $firstName, LastName $lastName, Email $email, Address $address)
 {
     $this->firstName = $firstName;
     $this->lastName = $lastName;
     $this->email = $email;
     $this->address = $address;
     $this->shoppingCart = new ShoppingCart($this->address->country());
 }
Example #17
0
 private function _loadAddress($type)
 {
     $address = new Address();
     $address->practiceId = (int) $this->id;
     $address->type = (int) $type;
     $address->populateWithPracticeIdType();
     return $address;
 }
Example #18
0
 public function testAddressLatitudeAndLongitude()
 {
     $address = new Address();
     $address->latitude = 123.145638;
     $this->assertEquals('123.145638', $address->getLatitude());
     $address->longitude = 121.176129;
     $this->assertEquals('121.176129', $address->getLongitude());
 }
 /**
  * Méthode permettant d'enregistrer une adresse
  * @param $address L'adresse à enregistrer
  * @return void
  */
 public function save(Address $address)
 {
     if ($address->isValid()) {
         $address->isNew() ? $this->add($address) : $this->modify($address);
     } else {
         throw new RuntimeException('L\'adresse doit être valide pour être enregistrée');
     }
 }
Example #20
0
 static function addCoords(Address $address)
 {
     if ($coords = self::coords($address->getOneLiner())) {
         $address->latitude = $coords['latitude'];
         $address->longitude = $coords['longitude'];
     }
     return $address;
 }
Example #21
0
 /**
  * Returns module content for header
  *
  * @param array $params Parameters
  * @return string Content
  */
 function hookFooter($params)
 {
     global $smarty, $cookie, $cart;
     if (isset($smarty->_tpl_vars['HOOK_EXTRACARRIER']) and $smarty->_tpl_vars['page_name'] == 'order') {
         $smarty->assign('TNTCarrierId', $this->_id_carrier);
         //			if ($smarty->_tpl_vars['page_name'] == 'order')
         //				$smarty->assign('TNT_js', 'relaisColis');
         if ($smarty->_tpl_vars['page_name'] == 'history') {
             $smarty->assign('TNT_js', 'suiviColis');
         }
         return $this->display(__FILE__, 'relaistnt_footer.tpl');
     } elseif ($smarty->_tpl_vars['page_name'] == 'order' and (Tools::isSubmit('processCarrier') or Tools::getValue('step') === '3') and Validate::isLoadedObject($cart)) {
         if ($cart->id_carrier != intval($this->_id_carrier)) {
             return;
         }
         if (Configuration::get('PS_TOKEN_ENABLE') == 1 && strcmp(Tools::getToken(false), Tools::getValue('token')) && $cookie->isLogged() === true) {
             $error = $this->l('invalid token');
         }
         $tntRCSelectedCode = pSQL(Tools::getValue('tntRCSelectedCode'));
         if (empty($tntRCSelectedCode) or is_null($tntRCSelectedCode)) {
             $error = $this->l('Avec la livraison TNT, vous devez choisir le relais dans lequel votre colis sera livré.');
         }
         if (!isset($error)) {
             $address_TNT = new Address();
             $address_TNT->id_country = intval(Configuration::get('PS_COUNTRY_DEFAULT'));
             $address_TNT->id_customer = intval($cart->id_customer);
             $address_TNT->alias = $this->l('TNT-') . $cart->id . '-' . $tntRCSelectedCode;
             $address_TNT->lastname = $this->l('TNT');
             $address_TNT->firstname = $this->l('Relais Colis');
             if (Validate::isName(Tools::getValue('tntRCSelectedNom'))) {
                 $address_TNT->company = pSQL(Tools::getValue('tntRCSelectedNom'));
                 $address_TNT->firstname .= ' - ' . pSQL(Tools::getValue('tntRCSelectedNom'));
             }
             if (Validate::isAddress(Tools::getValue('tntRCSelectedAdresse'))) {
                 $address_TNT->address1 = pSQL(Tools::getValue('tntRCSelectedAdresse'));
             }
             if (Validate::isPostCode(Tools::getValue('tntRCSelectedCodePostal'))) {
             }
             $address_TNT->postcode = pSQL(Tools::getValue('tntRCSelectedCodePostal'));
             if (Validate::isCityName(preg_replace('[\\d]', '', pSQL(Tools::getValue('tntRCSelectedCommune'))))) {
                 $address_TNT->city = preg_replace('[\\d]', '', pSQL(Tools::getValue('tntRCSelectedCommune')));
             }
             $address_TNT->deleted = 1;
             $errors = $address_TNT->validateControler();
             if (is_array($errors) and isset($errors[0])) {
                 Tools::redirect('order.php?step=2&error;=' . urlencode($errors[0]));
             }
             if ($address_TNT->save()) {
                 $cart->id_address_delivery = intval($address_TNT->id);
                 $cart->save();
             } else {
                 Tools::redirect('order.php?step=2&error;=' . urlencode($this->l('could not save TNT address')));
             }
         } else {
             Tools::redirect('order.php?step=2&error;=' . urlencode($error));
         }
     }
 }
 public function actionCreate()
 {
     // if some data has been entered before or the user is already logged in,
     // take the already existing data and prefill the input form
     if ($model = Shop::getCustomer()) {
         $address = $model->address;
     } else {
         $model = new Customer();
     }
     if (isset($_POST['Customer'])) {
         $model->attributes = $_POST['Customer'];
         if (isset($_POST['Address'])) {
             $address = new Address();
             $address->attributes = $_POST['Address'];
             if ($address->save()) {
                 $model->address_id = $address->id;
             }
         }
         if (!Yii::app()->user->isGuest) {
             $model->user_id = Yii::app()->user->id;
         }
         $model->validate();
         if (Shop::module()->useWithYum && isset($_POST['register']) && ($_POST['register'] = true)) {
             if (isset($_POST['Customer']['password']) && isset($_POST['Customer']['passwordRepeat'])) {
                 if ($_POST['Customer']['password'] != $_POST['Customer']['passwordRepeat']) {
                     $model->addError('password', Shop::t('Passwords do not match'));
                 } else {
                     if ($_POST['Customer']['password'] == '') {
                         $model->addError('password', Shop::t('Password is empty'));
                     } else {
                         $user = new YumUser();
                         $profile = new YumProfile();
                         $profile->attributes = $_POST['Customer'];
                         $profile->attributes = $_POST['Address'];
                         if ($user->register(strtr($model->email, array('@' => '_', '.' => '_')), $_POST['Customer']['password'], $profile)) {
                             $user->status = YumUser::STATUS_ACTIVE;
                             $user->save(false, array('status'));
                             $model->user_id = $user->id;
                             Shop::setFlash(Shop::t('Successfully registered user'));
                         } else {
                             $model->addErrors($user->getErrors());
                             $model->addErrors($profile->getErrors());
                             Shop::setFlash(Shop::t('Error while registering user'));
                         }
                     }
                 }
             }
         }
         if (!$model->hasErrors()) {
             if ($model->save()) {
                 Yii::app()->user->setState('customer_id', $model->customer_id);
                 $this->redirect(array('//shop/order/create', 'customer' => $model->customer_id));
             }
         }
     }
     $this->render('create', array('customer' => $model, 'address' => isset($address) ? $address : new Address()));
 }
 public function actionAdmin()
 {
     $model = new Address('search');
     $model->unsetAttributes();
     if (isset($_GET['Address'])) {
         $model->setAttributes($_GET['Address']);
     }
     $this->render('admin', array('model' => $model));
 }
Example #24
0
 /**
  * Tests the `__construct` method.
  *
  * @return void
  * @access public
  */
 public function test__construct()
 {
     $this->_object = new \Postman\Library\Email\Address\Recipient('*****@*****.**', 'cc');
     $this->assertIdentical($this->_object->getAddress(), '*****@*****.**');
     $this->assertIdentical($this->_object->getType(), 'cc');
     // This should throw an exception since it's not a valid recipient type.
     $this->expectException();
     $this->_object = new \Postman\Library\Email\Address\Recipient('*****@*****.**', 'fail');
 }
Example #25
0
 public function init()
 {
     parent::init();
     if (Tools::isSubmit('storedelivery') && (int) Tools::getValue('storedelivery') != 0) {
         //Save cookie only if previous id_adress wasn't a store
         $cookie = new Cookie('storedelivery');
         $cookie->__set('id_address_delivery', $this->context->cart->id_address_delivery);
         $store = new Store(Tools::getValue('storedelivery'));
         //Test if store address exist in address table
         Tools::strlen($store->name) > 32 ? $storeName = Tools::substr(preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name), 0, 29) . '...' : ($storeName = preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name));
         $sql = 'SELECT id_address FROM ' . _DB_PREFIX_ . 'address WHERE alias=\'' . addslashes($storeName) . '\' AND address1=\'' . addslashes($store->address1) . '\' AND address2=\'' . addslashes($store->address2) . '\' AND postcode=\'' . $store->postcode . '\' AND city=\'' . addslashes($store->city) . '\' AND id_country=\'' . addslashes($store->id_country) . '\' AND active=1 AND deleted=0';
         $id_address = Db::getInstance()->getValue($sql);
         //Create store adress if not exist for this user
         if (empty($id_address)) {
             $country = new Country($store->id_country, $this->context->language->id);
             $address = new Address();
             $address->id_country = $store->id_country;
             $address->id_state = $store->id_state;
             $address->country = $country->name;
             Tools::strlen($store->name) > 32 ? $address->alias = Tools::substr(preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name), 0, 29) . '...' : ($address->alias = preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name));
             Tools::strlen($store->name) > 32 ? $address->lastname = Tools::substr(preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name), 0, 29) . '...' : ($address->lastname = preg_replace("/[^a-zA-Zěščřžýáíéèêàô ]+/", '', $store->name));
             $address->firstname = " ";
             $address->address1 = $store->address1;
             $address->address2 = $store->address2;
             $address->postcode = $store->postcode;
             $address->city = $store->city;
             $address->phone = $store->phone;
             $address->deleted = 0;
             //create an address non deleted to register them in order
             $address->add();
             $id_address = $address->id;
         }
         //Update cart info
         $cart = $this->context->cart;
         $cart->id_address_delivery = $id_address;
         $cart->update();
         //Change address of all product in cart else we are redirect on step Carrier because of function autostep or OrderController
         Db::getInstance()->update('cart_product', array('id_address_delivery' => (int) $id_address), $where = 'id_cart = ' . $this->context->cart->id);
         //Change post carrier option else bad default carrier is saved by fonction processCarrier of ParentOrderController
         $array = array_values(Tools::getValue('delivery_option'));
         $_POST['delivery_option'] = array($id_address => $array[0]);
     } else {
         $cookie = new Cookie('storedelivery');
         $id_address_delivery = $cookie->__get('id_address_delivery');
         if ($id_address_delivery != false && $this->context->cart->id_address_delivery != $id_address_delivery && Tools::isSubmit('storedelivery')) {
             $this->context->cart->id_address_delivery = $cookie->__get('id_address_delivery');
             $this->context->cart->update();
             //Change address of all product in cart else we are redirect on step Carrier because of function autostep or OrderController
             Db::getInstance()->update('cart_product', array('id_address_delivery' => (int) $cookie->__get('id_address_delivery')), $where = 'id_cart = ' . $this->context->cart->id);
             //Change post carrier option else bad default carrier is saved by fonction processCarrier of ParentOrderController
             $array = array_values(Tools::getValue('delivery_option'));
             $_POST['delivery_option'] = array($cookie->__get('id_address_delivery') => $array[0]);
             $cookie->__unset('id_address_delivery');
         }
     }
 }
 function __construct($controller, $name = "ShippingEstimateForm")
 {
     $address = new Address();
     // get address to access it's getCountryField method
     $fields = new FieldList($address->getCountryField(), TextField::create('State', _t('Address.db_State', 'State')), TextField::create('City', _t('Address.db_City', 'City')), TextField::create('PostalCode', _t('Address.db_PostalCode', 'Postal Code')));
     $actions = new FieldList(FormAction::create("submit", _t('ShippingEstimateForm.FormActionTitle', 'Estimate')));
     $validator = new RequiredFields(array('Country'));
     parent::__construct($controller, $name, $fields, $actions, $validator);
     $this->extend('updateForm');
 }
 public function actionAdd($id = 0)
 {
     if (!empty($id)) {
         $Insurance = Insurance::model()->findByPk($id);
         if (!Yii::app()->user->checkAccess('admin') && ((Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY || Yii::app()->user->getProfile()->company_id != $Insurance->user->company_id) && (Yii::app()->getUser()->getProfile()->modules->insurance != '1' || $Insurance->user_id != Yii::app()->user->id) || Yii::app()->getUser()->getProfile()->company->active == '0')) {
             throw new CHttpException(403);
         }
         $Address = $Insurance->address;
         $ContentManager = null;
     } else {
         if (Yii::app()->user->getProfile()->content_manager == '0') {
             if (!Yii::app()->user->checkAccess('admin') && (Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY && Yii::app()->getUser()->getProfile()->modules->insurance != '1' || Yii::app()->getUser()->getProfile()->company->active == '0')) {
                 throw new CHttpException(403);
             } elseif (!Yii::app()->getUser()->getProfile()->company->validate) {
                 $this->redirect('/complete');
             }
             $ContentManager = null;
         } else {
             $ContentManager = new ContentManager();
         }
         $Insurance = new Insurance();
         $Address = new Address();
         $Address->setscenario('insurance');
     }
     //if(isset($_POST['save'])) {
     if (!empty($_POST)) {
         if (!empty($Insurance->address)) {
             Address::model()->deleteByPk($Insurance->address->address_id);
         }
         if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
             $ContentManager->setAttributes($_POST['ContentManager'], false);
             $contentValid = $ContentManager->validate();
         } else {
             $contentValid = true;
         }
         $Insurance->setAttributes($_POST['Insurance'], false);
         $Address->setAttributes($_POST['Address'], false);
         $valid = $Address->validate();
         $valid = $Insurance->validate() && $valid && $contentValid;
         if ($valid) {
             if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
                 $Insurance->user_id = User::createFakeUser($ContentManager);
                 $Insurance->contact_id = $Insurance->user_id;
             }
             $Address->save();
             $Insurance->address_id = $Address->address_id;
             $Insurance->save();
             $Insurance->autosearch();
             //                $this->redirect('/insurance');
             $this->render('insuranceaddsuccess', ['Insurance' => $Insurance, 'contacts' => User::getContact()]);
             exit;
         }
     }
     $this->render('add', ['Insurance' => $Insurance, 'Address' => $Address, 'contacts' => User::getContact(), 'ContentManager' => $ContentManager]);
 }
Example #28
0
 public function delete()
 {
     $addresses = $this->getAddresses((int) Configuration::get('PS_LANG_DEFAULT'));
     foreach ($addresses as $address) {
         $obj = new Address((int) $address['id_address']);
         $obj->delete();
     }
     Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'customer_group` WHERE `id_customer` = ' . (int) $this->id);
     Discount::deleteByIdCustomer((int) $this->id);
     return parent::delete();
 }
Example #29
0
 public function delete()
 {
     $address = new Address($this->id_address);
     if (!$address->delete()) {
         return false;
     }
     if (parent::delete()) {
         CartRule::cleanProductRuleIntegrity('manufacturers', $this->id);
         return $this->deleteImage();
     }
 }
Example #30
0
 public function testMapping()
 {
     $user_address = array('city_name' => 'Athens', 'country_name' => 'Greece', 'state' => 'Attiki', 'postal_code' => '23456', 'address_line_1' => 'Address 7 Street', 'phone_number' => '30210123456', 'fullname' => 'Andreas Kollaros');
     $address = new Address();
     $address->setFields($user_address);
     $address->map('fullname', 'SHIPTONAME')->map('phone_number', 'PHONENUM')->map('city_name', 'SHIPTOCITY')->map('address_line_1', 'SHIPTOSTREET')->map('state', 'SHIPTOSTATE')->map('country_name', 'SHIPTOCOUNTRY')->map('postal_code', 'SHIPTOZIP');
     $fields = $address->getMappedFields();
     $this->assertEquals('Attiki', $fields['SHIPTOSTATE']);
     $this->assertEquals('Athens', $fields['SHIPTOCITY']);
     $this->assertEquals('23456', $fields['SHIPTOZIP']);
 }