Example #1
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));
         }
     }
 }
Example #2
0
 private function _postValidationParameters()
 {
     // Check configuration values
     if (Tools::getValue('ebay_identifier') == NULL) {
         $this->_postErrors[] = $this->l('Your eBay identifier account is not specified or is invalid');
     }
     if (Tools::getValue('ebay_shop') == NULL) {
         $this->_postErrors[] = $this->l('Your ebay shop must be specified');
     }
     if (Tools::getValue('ebay_paypal_email') == NULL or !Validate::isEmail(Tools::getValue('ebay_paypal_email'))) {
         $this->_postErrors[] = $this->l('Your Paypal E-mail account is not specified or is invalid');
     }
     if (Tools::getValue('ebay_shipping_cost') == '' or !is_numeric(Tools::getValue('ebay_shipping_cost'))) {
         $this->_postErrors[] = $this->l('Your shipping cost is not specified or is invalid');
     }
     if (Tools::getValue('ebay_shop_postalcode') == '' or !Validate::isPostCode(Tools::getValue('ebay_shop_postalcode'))) {
         $this->_postErrors[] = $this->l('Your shop\'s postal code is not specified or is invalid');
     }
 }
 public function postProcess()
 {
     // On construit un login pour le compte
     // ------------------------------------
     // Si PS_SHOP_EMAIL = info@axalone.com
     // Alors login      = ps-info-axalone
     //   1/ On ajoute 'ps-' devant l'email
     //   2/ On retire l'extention .com à la fin
     //   3/ On remplace toutes les lettres accentuées par leurs équivalents sans accent
     //   4/ On remplace tous les sigles par des tirets
     //   5/ Enfin on remplace les doubles/triples tirets par des simples
     // --------------------------------------------------------------------------------
     $company_login = '******' . Configuration::get('PS_SHOP_EMAIL');
     $company_login = Tools::substr($company_login, 0, strrpos($company_login, '.'));
     $company_login = EMTools::removeAccents($company_login);
     $company_login = Tools::strtolower($company_login);
     $company_login = preg_replace('/[^a-z0-9-]/', '-', $company_login);
     $company_login = preg_replace('/-{2,}/', '-', $company_login);
     $cart_product = (string) Tools::getValue('product', '');
     // Initialisation de l'API
     // -----------------------
     if (Tools::isSubmit('submitInscription')) {
         // On prépare l'ouverture du compte
         // --------------------------------
         $company_name = (string) Tools::getValue('company_name');
         $company_email = (string) Tools::getValue('company_email');
         $company_phone = (string) Tools::getValue('company_phone');
         $company_address1 = (string) Tools::getValue('company_address1');
         $company_address2 = (string) Tools::getValue('company_address2');
         $company_zipcode = (string) Tools::getValue('company_zipcode');
         $company_city = (string) Tools::getValue('company_city');
         $country_id = (int) Tools::getValue('country_id');
         $country = new Country($country_id);
         if (!is_object($country) || empty($country->id)) {
             $this->errors[] = Tools::displayError('Country is invalid');
         } else {
             $company_country = Country::getNameById($this->context->language->id, $country_id);
         }
         if (!Validate::isGenericName($company_name)) {
             $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Shop name', 'AdminStores') . ' »');
         }
         if (!Validate::isEmail($company_email)) {
             $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Shop email', 'AdminStores') . ' »');
         }
         if (!Validate::isPhoneNumber($company_phone)) {
             $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Phone', 'AdminStores') . ' »');
         }
         if (!Validate::isAddress($company_address1)) {
             $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Shop address line 1', 'AdminStores') . ' »');
         }
         if ($country->zip_code_format && !$country->checkZipCode($company_zipcode)) {
             $this->errors[] = Tools::displayError('Your Zip/postal code is incorrect.') . '<br />' . Tools::displayError('It must be entered as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format)));
         } elseif (empty($company_zipcode) && $country->need_zip_code) {
             $this->errors[] = Tools::displayError('A Zip/postal code is required.');
         } elseif ($company_zipcode && !Validate::isPostCode($company_zipcode)) {
             $this->errors[] = Tools::displayError('The Zip/postal code is invalid.');
         }
         if (!Validate::isGenericName($company_city)) {
             $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('City', 'AdminStores') . ' »');
         }
         // We save these informations in the database
         // ------------------------------------------
         Db::getInstance()->insert('expressmailing_order_address', array('id_address' => 1, 'company_name' => pSQL($company_name), 'company_email' => pSQL($company_email), 'company_address1' => pSQL($company_address1), 'company_address2' => pSQL($company_address2), 'company_zipcode' => pSQL($company_zipcode), 'company_city' => pSQL($company_city), 'country_id' => $country_id, 'company_country' => pSQL($company_country), 'company_phone' => pSQL($company_phone), 'product' => pSQL($cart_product)), false, false, Db::REPLACE);
         // If form contains 1 or more errors, we stop the process
         // ------------------------------------------------------
         if (is_array($this->errors) && count($this->errors)) {
             return false;
         }
         // Open a session on Express-Mailing API
         // -------------------------------------
         if ($this->session_api->openSession()) {
             // We create the account
             // ---------------------
             $response_array = array();
             $base_url = Configuration::get('PS_SSL_ENABLED') == 0 ? Tools::getShopDomain(true, true) : Tools::getShopDomainSsl(true, true);
             $module_dir = Tools::str_replace_once(_PS_ROOT_DIR_, '', _PS_MODULE_DIR_);
             $parameters = array('login' => $company_login, 'info_company' => $company_name, 'info_email' => $company_email, 'info_phone' => $company_phone, 'info_address' => $company_address1 . "\r\n" . $company_address2, 'info_country' => $company_country, 'info_zipcode' => $company_zipcode, 'info_city' => $company_city, 'info_phone' => $company_phone, 'info_contact_firstname' => $this->context->employee->firstname, 'info_contact_lastname' => $this->context->employee->lastname, 'email_report' => $this->context->employee->email, 'gift_code' => 'prestashop_' . Translate::getModuleTranslation('expressmailing', '3320', 'session_api'), 'INFO_WWW' => $base_url . $module_dir . $this->module->name . '/campaigns/index.php');
             if ($this->session_api->createAccount($parameters, $response_array)) {
                 // If the form include the buying process (field 'product')
                 // We initiate a new cart with the product selected
                 // --------------------------------------------------------
                 if ($cart_product) {
                     Tools::redirectAdmin('index.php?controller=AdminMarketingBuy&submitCheckout&campaign_id=' . $this->campaign_id . '&media=' . $this->next_controller . '&product=' . $cart_product . '&token=' . Tools::getAdminTokenLite('AdminMarketingBuy'));
                     exit;
                 }
                 // Else we back to the mailing process
                 // -----------------------------------
                 Tools::redirectAdmin($this->next_action);
                 exit;
             }
             if ($this->session_api->error == 11) {
                 // Account already existe, we print the rescue form (with password input)
                 // ----------------------------------------------------------------------
                 $response_array = array();
                 $parameters = array('login' => $company_login);
                 $this->session_api->resendPassword($parameters, $response_array);
                 $this->generateRescueForm();
                 return;
             } else {
                 // Other error
                 // -----------
                 $this->errors[] = sprintf($this->module->l('Unable to create an account : %s', 'adminmarketinginscription'), $this->session_api->getError());
                 return false;
             }
         } else {
             $this->errors[] = sprintf($this->module->l('Error during communication with Express-Mailing API : %s', 'adminmarketinginscription'), $this->session_api->getError());
             return false;
         }
     } elseif (Tools::isSubmit('submitRescue')) {
         // Rescue form : ask for existing password
         // ---------------------------------------
         if ($this->session_api->openSession()) {
             $response_array = array();
             $password = trim((string) Tools::getValue('api_password'));
             $parameters = array('login' => $company_login, 'password' => $password);
             if ($this->session_api->connectUser($parameters, $response_array)) {
                 Db::getInstance()->insert('expressmailing', array('api_login' => pSQL($company_login), 'api_password' => pSQL($password)), false, false, Db::REPLACE);
                 // If the form include the buying process (field 'product')
                 // We initiate a new cart with the product selected
                 // --------------------------------------------------------
                 if ($cart_product) {
                     Tools::redirectAdmin('index.php?controller=AdminMarketingBuy&submitCheckout&campaign_id=' . $this->campaign_id . '&media=' . $this->next_controller . '&product=' . $cart_product . '&token=' . Tools::getAdminTokenLite('AdminMarketingBuy'));
                     exit;
                 }
                 // Else we back to the mailing process
                 // -----------------------------------
                 Tools::redirectAdmin($this->next_action);
                 exit;
             }
         }
         $this->errors[] = sprintf($this->module->l('Error during communication with Express-Mailing API : %s', 'adminmarketinginscription'), $this->session_api->getError());
         return false;
     }
 }
Example #4
0
 /**
  * test if found postcode relevance is enough for considering the postcode useful in the rest of checkout process
  *
  * @param          $post_code
  * @param stdClass $relevance
  *
  * @return bool
  */
 private function isValid($post_code, stdClass $relevance = null)
 {
     if (!Validate::isPostCode($post_code) || empty($relevance)) {
         return false;
     }
     if (!empty($relevance->percent) && $relevance->percent > DpdGroupSearch::SEARCH_RESULT_RELEVANCE_THRESHOLD_FOR_VALIDATION) {
         return true;
     }
     return false;
 }
 public function preProcess()
 {
     parent::preProcess();
     if (self::$cookie->isLogged() and !Tools::isSubmit('ajax')) {
         Tools::redirect('my-account.php');
     }
     if (Tools::getValue('create_account')) {
         $create_account = 1;
         self::$smarty->assign('email_create', 1);
     }
     if (Tools::isSubmit('SubmitCreate')) {
         if (!Validate::isEmail($email = Tools::getValue('email_create')) or empty($email)) {
             $this->errors[] = Tools::displayError('Invalid e-mail address');
         } elseif (Customer::customerExists($email, false, false)) {
             $this->errors[] = Tools::displayError('An account is already registered with this e-mail, please fill in the password or request a new one.');
             $_POST['email'] = $_POST['email_create'];
             unset($_POST['email_create']);
         } else {
             $create_account = 1;
             self::$smarty->assign('email_create', Tools::safeOutput($email));
             $_POST['email'] = $email;
         }
     }
     if (Tools::isSubmit('submitAccount') or Tools::isSubmit('submitGuestAccount')) {
         $create_account = 1;
         if (Tools::isSubmit('submitAccount')) {
             self::$smarty->assign('email_create', 1);
         }
         /* New Guest customer */
         if (!Tools::getValue('is_new_customer', 1) and !Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) {
             $this->errors[] = Tools::displayError('You cannot create a guest account.');
         }
         if (!Tools::getValue('is_new_customer', 1)) {
             $_POST['passwd'] = md5(time() . _COOKIE_KEY_);
         }
         if (isset($_POST['guest_email']) and $_POST['guest_email']) {
             $_POST['email'] = $_POST['guest_email'];
         }
         /* Preparing customer */
         $customer = new Customer();
         $lastnameAddress = $_POST['lastname'];
         $firstnameAddress = $_POST['firstname'];
         $_POST['lastname'] = $_POST['customer_lastname'];
         $_POST['firstname'] = $_POST['customer_firstname'];
         if (!Tools::getValue('phone') and !Tools::getValue('phone_mobile')) {
             $this->errors[] = Tools::displayError('You must register at least one phone number');
         }
         if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) and !(Tools::getValue('months') == '' and Tools::getValue('days') == '' and Tools::getValue('years') == '')) {
             $this->errors[] = Tools::displayError('Invalid date of birth');
         }
         $customer->birthday = empty($_POST['years']) ? '' : (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
         $this->errors = array_unique(array_merge($this->errors, $customer->validateControler()));
         /* Preparing address */
         $address = new Address();
         $_POST['lastname'] = $lastnameAddress;
         $_POST['firstname'] = $firstnameAddress;
         $address->id_customer = 1;
         $this->errors = array_unique(array_merge($this->errors, $address->validateControler()));
         /* US customer: normalize the address */
         if ($address->id_country == Country::getByIso('US') && Configuration::get('PS_TAASC')) {
             include_once _PS_TAASC_PATH_ . 'AddressStandardizationSolution.php';
             $normalize = new AddressStandardizationSolution();
             $address->address1 = $normalize->AddressLineStandardization($address->address1);
             $address->address2 = $normalize->AddressLineStandardization($address->address2);
         }
         if (!($country = new Country($address->id_country)) || !Validate::isLoadedObject($country)) {
             $this->errors[] = Tools::displayError('Country cannot be loaded with address->id_country');
         }
         $postcode = Tools::getValue('postcode');
         /* Check zip code format */
         if ($country->zip_code_format && !$country->checkZipCode($postcode)) {
             $this->errors[] = '<strong>' . Tools::displayError('Zip/ Postal code') . '</strong> ' . Tools::displayError('is invalid.') . '<br />' . Tools::displayError('Must be typed as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format)));
         } elseif (empty($postcode) && $country->need_zip_code) {
             $this->errors[] = '<strong>' . Tools::displayError('Zip/ Postal code') . '</strong> ' . Tools::displayError('is required.');
         } elseif ($postcode && !Validate::isPostCode($postcode)) {
             $this->errors[] = '<strong>' . Tools::displayError('Zip/ Postal code') . '</strong> ' . Tools::displayError('is invalid.');
         }
         if (Country::isNeedDniByCountryId($address->id_country) and (!Tools::getValue('dni') or !Validate::isDniLite(Tools::getValue('dni')))) {
             $this->errors[] = Tools::displayError('Identification number is incorrect or has already been used.');
         } elseif (!Country::isNeedDniByCountryId($address->id_country)) {
             $address->dni = NULL;
         }
         if (!count($this->errors)) {
             if (Customer::customerExists(Tools::getValue('email'), false, Configuration::get('PS_GUEST_CHECKOUT_ENABLED') && Tools::getValue('is_new_customer') == 0)) {
                 $this->errors[] = Tools::displayError('An account is already registered with this e-mail, please fill in the password or request a new one.');
             }
             if (Tools::isSubmit('newsletter')) {
                 $customer->ip_registration_newsletter = pSQL(Tools::getRemoteAddr());
                 $customer->newsletter_date_add = pSQL(date('Y-m-d H:i:s'));
             }
             if (!count($this->errors)) {
                 $country = new Country((int) $address->id_country, _PS_LANG_DEFAULT_);
                 if (!$country || !Validate::isLoadedObject($country)) {
                     die(Tools::displayError());
                 }
                 if ((int) $country->contains_states && !(int) $address->id_state) {
                     $this->errors[] = Tools::displayError('This country requires a state selection.');
                 } else {
                     $customer->active = 1;
                     /* New Guest customer */
                     if (Tools::isSubmit('is_new_customer')) {
                         $customer->is_guest = !Tools::getValue('is_new_customer', 1);
                     } else {
                         $customer->is_guest = 0;
                     }
                     if (!$customer->add()) {
                         $this->errors[] = Tools::displayError('An error occurred while creating your account.');
                     } else {
                         $address->id_customer = (int) $customer->id;
                         if (!$address->add()) {
                             $this->errors[] = Tools::displayError('An error occurred while creating your address.');
                         } else {
                             if (!$customer->is_guest) {
                                 if (!Mail::Send((int) self::$cookie->id_lang, 'account', Mail::l('Welcome!', (int) self::$cookie->id_lang), array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{passwd}' => Tools::getValue('passwd')), $customer->email, $customer->firstname . ' ' . $customer->lastname)) {
                                     $this->errors[] = Tools::displayError('Cannot send email');
                                 }
                             }
                             self::$smarty->assign('confirmation', 1);
                             self::$cookie->id_customer = (int) $customer->id;
                             self::$cookie->customer_lastname = $customer->lastname;
                             self::$cookie->customer_firstname = $customer->firstname;
                             self::$cookie->passwd = $customer->passwd;
                             self::$cookie->logged = 1;
                             self::$cookie->email = $customer->email;
                             self::$cookie->is_guest = !Tools::getValue('is_new_customer', 1);
                             /* Update cart address */
                             self::$cart->secure_key = $customer->secure_key;
                             self::$cart->id_address_delivery = Address::getFirstCustomerAddressId((int) $customer->id);
                             self::$cart->id_address_invoice = Address::getFirstCustomerAddressId((int) $customer->id);
                             self::$cart->update();
                             Module::hookExec('createAccount', array('_POST' => $_POST, 'newCustomer' => $customer));
                             if (Tools::isSubmit('ajax')) {
                                 $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'isSaved' => true, 'id_customer' => (int) self::$cookie->id_customer, 'id_address_delivery' => self::$cart->id_address_delivery, 'id_address_invoice' => self::$cart->id_address_invoice, 'token' => Tools::getToken(false));
                                 die(Tools::jsonEncode($return));
                             }
                             if ($back = Tools::getValue('back')) {
                                 Tools::redirect($back);
                             }
                             Tools::redirect('my-account.php');
                         }
                     }
                 }
             }
         }
         if (sizeof($this->errors)) {
             if (!Tools::getValue('is_new_customer')) {
                 unset($_POST['passwd']);
             }
             if (Tools::isSubmit('ajax')) {
                 $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'isSaved' => false, 'id_customer' => 0);
                 die(Tools::jsonEncode($return));
             }
         }
     }
     if (Tools::isSubmit('SubmitLogin')) {
         Module::hookExec('beforeAuthentication');
         $passwd = trim(Tools::getValue('passwd'));
         $email = trim(Tools::getValue('email'));
         if (empty($email)) {
             $this->errors[] = Tools::displayError('E-mail address required');
         } elseif (!Validate::isEmail($email)) {
             $this->errors[] = Tools::displayError('Invalid e-mail address');
         } elseif (empty($passwd)) {
             $this->errors[] = Tools::displayError('Password is required');
         } elseif (Tools::strlen($passwd) > 32) {
             $this->errors[] = Tools::displayError('Password is too long');
         } elseif (!Validate::isPasswd($passwd)) {
             $this->errors[] = Tools::displayError('Invalid password');
         } else {
             $customer = new Customer();
             $authentication = $customer->getByEmail(trim($email), trim($passwd));
             if (!$authentication or !$customer->id) {
                 $this->errors[] = Tools::displayError('Authentication failed');
             } else {
                 self::$cookie->id_compare = isset(self::$cookie->id_compare) ? self::$cookie->id_compare : CompareProduct::getIdCompareByIdCustomer($customer->id);
                 self::$cookie->id_customer = (int) $customer->id;
                 self::$cookie->customer_lastname = $customer->lastname;
                 self::$cookie->customer_firstname = $customer->firstname;
                 self::$cookie->logged = 1;
                 self::$cookie->is_guest = $customer->isGuest();
                 self::$cookie->passwd = $customer->passwd;
                 self::$cookie->email = $customer->email;
                 if (Configuration::get('PS_CART_FOLLOWING') and (empty(self::$cookie->id_cart) or Cart::getNbProducts(self::$cookie->id_cart) == 0) and $id_cart = (int) Cart::lastNoneOrderedCart((int) $customer->id)) {
                     self::$cart = new Cart($id_cart);
                 } else {
                     self::$cart->id_carrier = 0;
                     self::$cart->id_address_delivery = Address::getFirstCustomerAddressId((int) $customer->id);
                     self::$cart->id_address_invoice = Address::getFirstCustomerAddressId((int) $customer->id);
                 }
                 self::$cart->id_customer = (int) $customer->id;
                 // If a logged guest logs in as a customer, the cart secure key was already set and needs to be updated
                 self::$cart->secure_key = $customer->secure_key;
                 if ($id_guest = (int) Guest::getFromCustomer(self::$cart->id_customer)) {
                     self::$cart->id_guest = $id_guest;
                 }
                 self::$cart->save();
                 self::$cookie->id_cart = (int) self::$cart->id;
                 self::$cookie->update();
                 Module::hookExec('authentication');
                 if (!Tools::isSubmit('ajax')) {
                     if ($back = Tools::getValue('back')) {
                         Tools::redirect($back);
                     }
                     Tools::redirect('my-account.php');
                 }
             }
         }
         if (Tools::isSubmit('ajax')) {
             $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'token' => Tools::getToken(false));
             die(Tools::jsonEncode($return));
         }
     }
     if (isset($create_account)) {
         /* Select the most appropriate country */
         if (isset($_POST['id_country']) and is_numeric($_POST['id_country'])) {
             $selectedCountry = (int) $_POST['id_country'];
         }
         /* FIXME : language iso and country iso are not similar,
         			 * maybe an associative table with country an language can resolve it,
         			 * But for now it's a bug !
         			 * @see : bug #6968
         			 * @link:http://www.prestashop.com/bug_tracker/view/6968/
         			elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
         			{
         				$array = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
         				if (Validate::isLanguageIsoCode($array[0]))
         				{
         					$selectedCountry = Country::getByIso($array[0]);
         					if (!$selectedCountry)
         						$selectedCountry = (int)(_PS_COUNTRY_DEFAULT_);
         				}
         			}*/
         if (!isset($selectedCountry)) {
             $selectedCountry = (int) _PS_COUNTRY_DEFAULT_;
         }
         if (Configuration::get('PS_RESTRICT_DELIVERED_COUNTRIES')) {
             $countries = Carrier::getDeliveredCountries((int) self::$cookie->id_lang, true, true);
         } else {
             $countries = Country::getCountries((int) self::$cookie->id_lang, true, false, true);
         }
         self::$smarty->assign(array('countries' => $countries, 'sl_country' => isset($selectedCountry) ? $selectedCountry : 0, 'vat_management' => Configuration::get('VATNUMBER_MANAGEMENT')));
         /* Call a hook to display more information on form */
         self::$smarty->assign(array('HOOK_CREATE_ACCOUNT_FORM' => Module::hookExec('createAccountForm'), 'HOOK_CREATE_ACCOUNT_TOP' => Module::hookExec('createAccountTop')));
     }
     /* Generate years, months and days */
     if (isset($_POST['years']) and is_numeric($_POST['years'])) {
         $selectedYears = (int) $_POST['years'];
     }
     $years = Tools::dateYears();
     if (isset($_POST['months']) and is_numeric($_POST['months'])) {
         $selectedMonths = (int) $_POST['months'];
     }
     $months = Tools::dateMonths();
     if (isset($_POST['days']) and is_numeric($_POST['days'])) {
         $selectedDays = (int) $_POST['days'];
     }
     $days = Tools::dateDays();
     self::$smarty->assign(array('years' => $years, 'sl_year' => isset($selectedYears) ? $selectedYears : 0, 'months' => $months, 'sl_month' => isset($selectedMonths) ? $selectedMonths : 0, 'days' => $days, 'sl_day' => isset($selectedDays) ? $selectedDays : 0));
     self::$smarty->assign('newsletter', (int) Module::getInstanceByName('blocknewsletter')->active);
 }
 public function postProcess()
 {
     if (isset($_POST['submitAdd' . $this->table])) {
         // Transform e-mail in id_customer for parent processing
         if ($this->addressType == 'customer') {
             if (Validate::isEmail(Tools::getValue('email'))) {
                 $customer = new Customer();
                 $customer->getByEmail(Tools::getValue('email'), null, true);
                 if (Validate::isLoadedObject($customer)) {
                     $_POST['id_customer'] = $customer->id;
                 } else {
                     $this->_errors[] = Tools::displayError('This e-mail address is not registered.');
                 }
             } elseif ($id_customer = Tools::getValue('id_customer')) {
                 $customer = new Customer((int) $id_customer);
                 if (Validate::isLoadedObject($customer)) {
                     $_POST['id_customer'] = $customer->id;
                 } else {
                     $this->_errors[] = Tools::displayError('Unknown customer');
                 }
             } else {
                 $this->_errors[] = Tools::displayError('Unknown customer');
             }
             if (Country::isNeedDniByCountryId(Tools::getValue('id_country')) and !Tools::getValue('dni')) {
                 $this->_errors[] = Tools::displayError('Identification number is incorrect or has already been used.');
             }
         }
         // Check manufacturer selected
         if ($this->addressType == 'manufacturer') {
             $manufacturer = new Manufacturer((int) Tools::getValue('id_manufacturer'));
             if (!Validate::isLoadedObject($manufacturer)) {
                 $this->_errors[] = Tools::displayError('Manufacturer selected is not valid.');
             }
         }
         /* If the selected country does not contain states */
         $id_state = (int) Tools::getValue('id_state');
         if ($id_country = Tools::getValue('id_country') and $country = new Country((int) $id_country) and !(int) $country->contains_states and $id_state) {
             $this->_errors[] = Tools::displayError('You have selected a state for a country that does not contain states.');
         }
         /* If the selected country contains states, then a state have to be selected */
         if ((int) $country->contains_states && !$id_state) {
             $this->_errors[] = Tools::displayError('An address located in a country containing states must have a state selected.');
         }
         $postcode = Tools::getValue('postcode');
         /* Check zip code format */
         if ($country->zip_code_format && !$country->checkZipCode($postcode)) {
             $this->_errors[] = Tools::displayError('Your zip/postal code is incorrect.') . '<br />' . Tools::displayError('Must be typed as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format)));
         } elseif (empty($postcode) && $country->need_zip_code) {
             $this->_errors[] = Tools::displayError('Postcode required.');
         } elseif ($postcode && !Validate::isPostCode($postcode)) {
             $this->_errors[] = Tools::displayError('Your zip/postal code is incorrect.');
         }
         /* If this address come from order's edition and is the same as the other one (invoice or delivery one)
          ** we delete its id_address to force the creation of a new one */
         if ((int) Tools::getValue('id_order')) {
             $this->_redirect = false;
             if (isset($_POST['address_type'])) {
                 $_POST['id_address'] = '';
             }
         }
     }
     if (Tools::getIsset('delete' . $this->table) && $this->tabAccess['delete'] === '1') {
         call_user_func_array(array($this->className, '_cleanCart'), array(null, (int) Tools::getValue('id_address')));
     }
     if (!sizeof($this->_errors)) {
         parent::postProcess();
     }
     /* Reassignation of the order's new (invoice or delivery) address */
     $address_type = (int) Tools::getValue('address_type') == 2 ? 'invoice' : ((int) Tools::getValue('address_type') == 1 ? 'delivery' : '');
     if (isset($_POST['submitAdd' . $this->table]) and $id_order = (int) Tools::getValue('id_order') and !sizeof($this->_errors) and !empty($address_type)) {
         if (!Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'orders SET `id_address_' . $address_type . '` = ' . Db::getInstance()->Insert_ID() . ' WHERE `id_order` = ' . $id_order)) {
             $this->_errors[] = Tools::displayError('An error occurred while linking this address to its order.');
         } else {
             Tools::redirectAdmin(Tools::getValue('back') . '&conf=4');
         }
     }
 }
 public function postProcess()
 {
     if (isset($_POST['submitAdd' . $this->table])) {
         /* Cleaning fields */
         foreach ($_POST as $kp => $vp) {
             if (!in_array($kp, array('checkBoxShopGroupAsso_store', 'checkBoxShopAsso_store'))) {
                 $_POST[$kp] = trim($vp);
             }
         }
         /* Rewrite latitude and longitude to 8 digits */
         $_POST['latitude'] = number_format((double) $_POST['latitude'], 8);
         $_POST['longitude'] = number_format((double) $_POST['longitude'], 8);
         /* If the selected country does not contain states */
         $id_state = (int) Tools::getValue('id_state');
         $id_country = (int) Tools::getValue('id_country');
         $country = new Country((int) $id_country);
         if ($id_country && $country && !(int) $country->contains_states && $id_state) {
             $this->errors[] = Tools::displayError('You\'ve selected a state for a country that does not contain states.');
         }
         /* If the selected country contains states, then a state have to be selected */
         if ((int) $country->contains_states && !$id_state) {
             $this->errors[] = Tools::displayError('An address located in a country containing states must have a state selected.');
         }
         $latitude = (double) Tools::getValue('latitude');
         $longitude = (double) Tools::getValue('longitude');
         if (empty($latitude) || empty($longitude)) {
             $this->errors[] = Tools::displayError('Latitude and longitude are required.');
         }
         $postcode = Tools::getValue('postcode');
         /* Check zip code format */
         if ($country->zip_code_format && !$country->checkZipCode($postcode)) {
             $this->errors[] = Tools::displayError('Your Zip/postal code is incorrect.') . '<br />' . Tools::displayError('It must be entered as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format)));
         } elseif (empty($postcode) && $country->need_zip_code) {
             $this->errors[] = Tools::displayError('A Zip/postal code is required.');
         } elseif ($postcode && !Validate::isPostCode($postcode)) {
             $this->errors[] = Tools::displayError('The Zip/postal code is invalid.');
         }
         /* Store hours */
         $_POST['hours'] = array();
         for ($i = 1; $i < 8; $i++) {
             $_POST['hours'][] .= Tools::getValue('hours_' . (int) $i);
         }
         $_POST['hours'] = serialize($_POST['hours']);
     }
     if (!count($this->errors)) {
         parent::postProcess();
     } else {
         $this->display = 'add';
     }
 }
 /**
  * Process submit on an account
  */
 protected function processSubmitAccount()
 {
     Hook::exec('actionBeforeSubmitAccount');
     $this->create_account = true;
     if (Tools::isSubmit('submitAccount')) {
         $this->context->smarty->assign('email_create', 1);
     }
     // New Guest customer
     if (!Tools::getValue('is_new_customer', 1) && !Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) {
         $this->errors[] = Tools::displayError('You cannot create a guest account.');
     }
     if (!Tools::getValue('is_new_customer', 1)) {
         $_POST['passwd'] = md5(time() . _COOKIE_KEY_);
     }
     if ($guest_email = Tools::getValue('guest_email')) {
         $_POST['email'] = $guest_email;
     }
     // Checked the user address in case he changed his email address
     if (Validate::isEmail($email = Tools::getValue('email')) && !empty($email)) {
         if (Customer::customerExists($email)) {
             $this->errors[] = Tools::displayError('An account using this email address has already been registered.', false);
         }
     }
     // Preparing customer
     $customer = new Customer();
     $lastnameAddress = Tools::getValue('lastname');
     $firstnameAddress = Tools::getValue('firstname');
     $_POST['lastname'] = Tools::getValue('customer_lastname', $lastnameAddress);
     $_POST['firstname'] = Tools::getValue('customer_firstname', $firstnameAddress);
     $addresses_types = array('address');
     if (!Configuration::get('PS_ORDER_PROCESS_TYPE') && Configuration::get('PS_GUEST_CHECKOUT_ENABLED') && Tools::getValue('invoice_address')) {
         $addresses_types[] = 'address_invoice';
     }
     $error_phone = false;
     if (Configuration::get('PS_ONE_PHONE_AT_LEAST')) {
         if (Tools::isSubmit('submitGuestAccount') || !Tools::getValue('is_new_customer')) {
             if (!Tools::getValue('phone') && !Tools::getValue('phone_mobile')) {
                 $error_phone = true;
             }
         } elseif ((Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && Configuration::get('PS_ORDER_PROCESS_TYPE') || Configuration::get('PS_ORDER_PROCESS_TYPE') && !Tools::getValue('email_create') || Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && Tools::getValue('email_create')) && (!Tools::getValue('phone') && !Tools::getValue('phone_mobile'))) {
             $error_phone = true;
         }
     }
     if ($error_phone) {
         $this->errors[] = Tools::displayError('You must register at least one phone number.');
     }
     $this->errors = array_unique(array_merge($this->errors, $customer->validateController()));
     // Check the requires fields which are settings in the BO
     $this->errors = $this->errors + $customer->validateFieldsRequiredDatabase();
     if (!Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && !$this->ajax && !Tools::isSubmit('submitGuestAccount')) {
         if (!count($this->errors)) {
             $this->processCustomerNewsletter($customer);
             $customer->firstname = Tools::ucwords($customer->firstname);
             $customer->birthday = empty($_POST['years']) ? '' : (int) Tools::getValue('years') . '-' . (int) Tools::getValue('months') . '-' . (int) Tools::getValue('days');
             if (!Validate::isBirthDate($customer->birthday)) {
                 $this->errors[] = Tools::displayError('Invalid date of birth.');
             }
             // New Guest customer
             $customer->is_guest = Tools::isSubmit('is_new_customer') ? !Tools::getValue('is_new_customer', 1) : 0;
             $customer->active = 1;
             if (!count($this->errors)) {
                 if ($customer->add()) {
                     if (!$customer->is_guest) {
                         if (!$this->sendConfirmationMail($customer)) {
                             $this->errors[] = Tools::displayError('The email cannot be sent.');
                         }
                     }
                     $this->updateContext($customer);
                     $this->context->cart->update();
                     Hook::exec('actionCustomerAccountAdd', array('_POST' => $_POST, 'newCustomer' => $customer));
                     if ($this->ajax) {
                         $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'isSaved' => true, 'id_customer' => (int) $this->context->cookie->id_customer, 'id_address_delivery' => $this->context->cart->id_address_delivery, 'id_address_invoice' => $this->context->cart->id_address_invoice, 'token' => Tools::getToken(false));
                         $this->ajaxDie(Tools::jsonEncode($return));
                     }
                     if (($back = Tools::getValue('back')) && $back == Tools::secureReferrer($back)) {
                         Tools::redirect(html_entity_decode($back));
                     }
                     // redirection: if cart is not empty : redirection to the cart
                     if (count($this->context->cart->getProducts(true)) > 0) {
                         $multi = (int) Tools::getValue('multi-shipping');
                         Tools::redirect('index.php?controller=order' . ($multi ? '&multi-shipping=' . $multi : ''));
                     } else {
                         Tools::redirect('index.php?controller=' . ($this->authRedirection !== false ? urlencode($this->authRedirection) : 'my-account'));
                     }
                 } else {
                     $this->errors[] = Tools::displayError('An error occurred while creating your account.');
                 }
             }
         }
     } else {
         // if registration type is in one step, we save the address
         $_POST['lastname'] = $lastnameAddress;
         $_POST['firstname'] = $firstnameAddress;
         $post_back = $_POST;
         // Preparing addresses
         foreach ($addresses_types as $addresses_type) {
             ${$addresses_type} = new Address();
             ${$addresses_type}->id_customer = 1;
             if ($addresses_type == 'address_invoice') {
                 foreach ($_POST as $key => &$post) {
                     if ($tmp = Tools::getValue($key . '_invoice')) {
                         $post = $tmp;
                     }
                 }
             }
             $this->errors = array_unique(array_merge($this->errors, ${$addresses_type}->validateController()));
             if ($addresses_type == 'address_invoice') {
                 $_POST = $post_back;
             }
             if (!($country = new Country(${$addresses_type}->id_country)) || !Validate::isLoadedObject($country)) {
                 $this->errors[] = Tools::displayError('Country cannot be loaded with address->id_country');
             }
             if (!$country->active) {
                 $this->errors[] = Tools::displayError('This country is not active.');
             }
             $postcode = ${$addresses_type}->postcode;
             /* Check zip code format */
             if ($country->zip_code_format && !$country->checkZipCode($postcode)) {
                 $this->errors[] = sprintf(Tools::displayError('The Zip/Postal code you\'ve entered is invalid. It must follow this format: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
             } elseif (empty($postcode) && $country->need_zip_code) {
                 $this->errors[] = Tools::displayError('A Zip / Postal code is required.');
             } elseif ($postcode && !Validate::isPostCode($postcode)) {
                 $this->errors[] = Tools::displayError('The Zip / Postal code is invalid.');
             }
             if ($country->need_identification_number && (!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni')))) {
                 $this->errors[] = Tools::displayError('The identification number is incorrect or has already been used.');
             } elseif (!$country->need_identification_number) {
                 ${$addresses_type}->dni = null;
             }
             if (Tools::isSubmit('submitAccount') || Tools::isSubmit('submitGuestAccount')) {
                 if (!($country = new Country(${$addresses_type}->id_country, Configuration::get('PS_LANG_DEFAULT'))) || !Validate::isLoadedObject($country)) {
                     $this->errors[] = Tools::displayError('Country is invalid');
                 }
             }
             $contains_state = isset($country) && is_object($country) ? (int) $country->contains_states : 0;
             $id_state = isset(${$addresses_type}) && is_object(${$addresses_type}) ? (int) ${$addresses_type}->id_state : 0;
             if ((Tools::isSubmit('submitAccount') || Tools::isSubmit('submitGuestAccount')) && $contains_state && !$id_state) {
                 $this->errors[] = Tools::displayError('This country requires you to choose a State.');
             }
         }
     }
     if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) && !(Tools::getValue('months') == '' && Tools::getValue('days') == '' && Tools::getValue('years') == '')) {
         $this->errors[] = Tools::displayError('Invalid date of birth');
     }
     if (!count($this->errors)) {
         if (Customer::customerExists(Tools::getValue('email'))) {
             $this->errors[] = Tools::displayError('An account using this email address has already been registered. Please enter a valid password or request a new one. ', false);
         }
         $this->processCustomerNewsletter($customer);
         $customer->birthday = empty($_POST['years']) ? '' : (int) Tools::getValue('years') . '-' . (int) Tools::getValue('months') . '-' . (int) Tools::getValue('days');
         if (!Validate::isBirthDate($customer->birthday)) {
             $this->errors[] = Tools::displayError('Invalid date of birth');
         }
         if (!count($this->errors)) {
             $customer->active = 1;
             // New Guest customer
             if (Tools::isSubmit('is_new_customer')) {
                 $customer->is_guest = !Tools::getValue('is_new_customer', 1);
             } else {
                 $customer->is_guest = 0;
             }
             if (!$customer->add()) {
                 $this->errors[] = Tools::displayError('An error occurred while creating your account.');
             } else {
                 foreach ($addresses_types as $addresses_type) {
                     ${$addresses_type}->id_customer = (int) $customer->id;
                     if ($addresses_type == 'address_invoice') {
                         foreach ($_POST as $key => &$post) {
                             if ($tmp = Tools::getValue($key . '_invoice')) {
                                 $post = $tmp;
                             }
                         }
                     }
                     $this->errors = array_unique(array_merge($this->errors, ${$addresses_type}->validateController()));
                     if ($addresses_type == 'address_invoice') {
                         $_POST = $post_back;
                     }
                     if (!count($this->errors) && (Configuration::get('PS_REGISTRATION_PROCESS_TYPE') || $this->ajax || Tools::isSubmit('submitGuestAccount')) && !${$addresses_type}->add()) {
                         $this->errors[] = Tools::displayError('An error occurred while creating your address.');
                     }
                 }
                 if (!count($this->errors)) {
                     if (!$customer->is_guest) {
                         $this->context->customer = $customer;
                         $customer->cleanGroups();
                         // we add the guest customer in the default customer group
                         $customer->addGroups(array((int) Configuration::get('PS_CUSTOMER_GROUP')));
                         if (!$this->sendConfirmationMail($customer)) {
                             $this->errors[] = Tools::displayError('The email cannot be sent.');
                         }
                     } else {
                         $customer->cleanGroups();
                         // we add the guest customer in the guest customer group
                         $customer->addGroups(array((int) Configuration::get('PS_GUEST_GROUP')));
                     }
                     $this->updateContext($customer);
                     $this->context->cart->id_address_delivery = (int) Address::getFirstCustomerAddressId((int) $customer->id);
                     $this->context->cart->id_address_invoice = (int) Address::getFirstCustomerAddressId((int) $customer->id);
                     if (isset($address_invoice) && Validate::isLoadedObject($address_invoice)) {
                         $this->context->cart->id_address_invoice = (int) $address_invoice->id;
                     }
                     if ($this->ajax && Configuration::get('PS_ORDER_PROCESS_TYPE')) {
                         $delivery_option = array((int) $this->context->cart->id_address_delivery => (int) $this->context->cart->id_carrier . ',');
                         $this->context->cart->setDeliveryOption($delivery_option);
                     }
                     // If a logged guest logs in as a customer, the cart secure key was already set and needs to be updated
                     $this->context->cart->update();
                     // Avoid articles without delivery address on the cart
                     $this->context->cart->autosetProductAddress();
                     Hook::exec('actionCustomerAccountAdd', array('_POST' => $_POST, 'newCustomer' => $customer));
                     if ($this->ajax) {
                         $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'isSaved' => true, 'id_customer' => (int) $this->context->cookie->id_customer, 'id_address_delivery' => $this->context->cart->id_address_delivery, 'id_address_invoice' => $this->context->cart->id_address_invoice, 'token' => Tools::getToken(false));
                         $this->ajaxDie(Tools::jsonEncode($return));
                     }
                     // if registration type is in two steps, we redirect to register address
                     if (!Configuration::get('PS_REGISTRATION_PROCESS_TYPE') && !$this->ajax && !Tools::isSubmit('submitGuestAccount')) {
                         Tools::redirect('index.php?controller=address');
                     }
                     if (($back = Tools::getValue('back')) && $back == Tools::secureReferrer($back)) {
                         Tools::redirect(html_entity_decode($back));
                     }
                     // redirection: if cart is not empty : redirection to the cart
                     if (count($this->context->cart->getProducts(true)) > 0) {
                         Tools::redirect('index.php?controller=order' . ($multi = (int) Tools::getValue('multi-shipping') ? '&multi-shipping=' . $multi : ''));
                     } else {
                         Tools::redirect('index.php?controller=' . ($this->authRedirection !== false ? urlencode($this->authRedirection) : 'my-account'));
                     }
                 }
             }
         }
     }
     if (count($this->errors)) {
         //for retro compatibility to display guest account creation form on authentication page
         if (Tools::getValue('submitGuestAccount')) {
             $_GET['display_guest_checkout'] = 1;
         }
         if (!Tools::getValue('is_new_customer')) {
             unset($_POST['passwd']);
         }
         if ($this->ajax) {
             $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'isSaved' => false, 'id_customer' => 0);
             $this->ajaxDie(Tools::jsonEncode($return));
         }
         $this->context->smarty->assign('account_error', $this->errors);
     }
 }
Example #9
0
 protected function _update_configuration($key, $value)
 {
     $interface = PS_CLI_Interface::getInterface();
     $validValue = false;
     switch ($key) {
         case 'PS_STORE_DISPLAY_FOOTER':
         case 'PS_STORE_DISPLAY_SITEMAP':
         case 'PS_STORE_SIMPLIFIED':
             $validValue = Validate::isBool($value);
             break;
         case 'PS_STORES_CENTER_LAT':
         case 'PS_STORES_CENTER_LONG':
             $validValue = Validate::isCoordinate($value);
             break;
         case 'PS_SHOP_NAME':
             $validValue = Validate::isName($value);
             break;
         case 'PS_SHOP_EMAIL':
             $validValue = Validate::isEmail($value);
             break;
         case 'PS_SHOP_DETAILS':
             $validValue = Validate::isString($value);
             break;
         case 'PS_SHOP_ADDR1':
         case 'PS_SHOP_ADDR2':
             $validValue = Validate::isAddress($value);
             break;
         case 'PS_SHOP_CODE':
             $validValue = Validate::isPostCode($value);
             break;
         case 'PS_SHOP_CITY':
             $validValue = Validate::isCityName($value);
             break;
         case 'PS_SHOP_COUNTRY_ID':
             if (Validate::isUnsignedId($value)) {
                 $obj = new Country((int) $value);
                 $validValue = Validate::isLoadedObject($obj);
             }
             break;
         case 'PS_SHOP_STATE_ID':
             $validValue = Validate::isUnsignedId($value);
             break;
         case 'PS_SHOP_PHONE':
         case 'PS_SHOP_FAX':
             $validValue = Validate::isPhoneNumber($value);
             break;
         default:
             $interface->error("Configuration key '{$key}' is not handled by this command");
             break;
     }
     if (!$validValue) {
         $interface->error("value '{$value}' is not a valid value for configuration key '{$key}'");
     }
     if (PS_CLI_Utils::update_configuration_value($key, $value)) {
         $interface->success("Successfully updated '{$key}' configuration");
     } else {
         $interface->error("Could not update configuration key '{$key}'");
     }
 }
Example #10
0
 private function validatePostcodeCSVColumn($postcodes_data, $postcodes_data_count, $column)
 {
     $wrong_lines = array();
     for ($i = 0; $i < $postcodes_data_count; $i++) {
         switch ($column) {
             case DpdGroupPostcode::COLUMN_ID_POSTCODE:
                 if (!Validate::isUnsignedId($postcodes_data[$i][DpdGroupPostcode::COLUMN_ID_POSTCODE])) {
                     $wrong_lines[] = $i + self::DEFAULT_FIRST_LINE_INDEX;
                 }
                 break;
             case DpdGroupPostcode::COLUMN_REGION:
                 if (!Validate::isCityName($postcodes_data[$i][DpdGroupPostcode::COLUMN_REGION])) {
                     $wrong_lines[] = $i + self::DEFAULT_FIRST_LINE_INDEX;
                 }
                 break;
             case DpdGroupPostcode::COLUMN_POSTCODE:
                 if (!Validate::isPostCode($postcodes_data[$i][DpdGroupPostcode::COLUMN_POSTCODE])) {
                     $wrong_lines[] = $i + self::DEFAULT_FIRST_LINE_INDEX;
                 }
                 break;
             case DpdGroupPostcode::COLUMN_CITY:
                 if (!Validate::isCityName($postcodes_data[$i][DpdGroupPostcode::COLUMN_CITY])) {
                     $wrong_lines[] = $i + self::DEFAULT_FIRST_LINE_INDEX;
                 }
                 break;
             case DpdGroupPostcode::COLUMN_ADDRESS:
                 if (!Validate::isCityName($postcodes_data[$i][DpdGroupPostcode::COLUMN_ADDRESS])) {
                     $wrong_lines[] = $i + self::DEFAULT_FIRST_LINE_INDEX;
                 }
                 break;
         }
     }
     return empty($wrong_lines) ? true : implode(', ', $wrong_lines);
 }
 public function preProcess()
 {
     parent::preProcess();
     if ($back = Tools::getValue('back')) {
         self::$smarty->assign('back', Tools::safeOutput($back));
     }
     if ($mod = Tools::getValue('mod')) {
         self::$smarty->assign('mod', Tools::safeOutput($mod));
     }
     if (Tools::isSubmit('ajax') && Tools::isSubmit('type')) {
         if (Tools::getValue('type') == 'delivery') {
             $id_address = isset(self::$cart->id_address_delivery) ? (int) self::$cart->id_address_delivery : 0;
         } elseif (Tools::getValue('type') == 'invoice') {
             $id_address = (isset(self::$cart->id_address_invoice) and self::$cart->id_address_invoice != self::$cart->id_address_delivery) ? (int) self::$cart->id_address_invoice : 0;
         } else {
             exit;
         }
     } else {
         $id_address = (int) Tools::getValue('id_address', 0);
     }
     if ($id_address) {
         $this->_address = new Address((int) $id_address);
         if (Validate::isLoadedObject($this->_address) && Customer::customerHasAddress((int) self::$cookie->id_customer, (int) $id_address)) {
             if (Tools::isSubmit('delete')) {
                 if (self::$cart->id_address_invoice == $this->_address->id) {
                     unset(self::$cart->id_address_invoice);
                 }
                 if (self::$cart->id_address_delivery == $this->_address->id) {
                     unset(self::$cart->id_address_delivery);
                 }
                 if ($this->_address->delete()) {
                     Tools::redirect('addresses.php');
                 }
                 $this->errors[] = Tools::displayError('This address cannot be deleted.');
             }
             self::$smarty->assign(array('address' => $this->_address, 'id_address' => (int) $id_address));
         } elseif (Tools::isSubmit('ajax')) {
             exit;
         } else {
             Tools::redirect('addresses.php');
         }
     }
     if (Tools::isSubmit('submitAddress')) {
         $address = new Address();
         $this->errors = $address->validateControler();
         $address->id_customer = (int) self::$cookie->id_customer;
         if (!Tools::getValue('phone') && !Tools::getValue('phone_mobile')) {
             $this->errors[] = Tools::displayError('You must register at least one phone number');
         }
         if (!($country = new Country((int) $address->id_country)) or !Validate::isLoadedObject($country)) {
             die(Tools::displayError());
         }
         /* US customer: normalize the address */
         if ($address->id_country == Country::getByIso('US') && Configuration::get('PS_TAASC')) {
             include_once _PS_TAASC_PATH_ . 'AddressStandardizationSolution.php';
             $normalize = new AddressStandardizationSolution();
             $address->address1 = $normalize->AddressLineStandardization($address->address1);
             $address->address2 = $normalize->AddressLineStandardization($address->address2);
         }
         $postcode = Tools::getValue('postcode');
         /* Check zip code format */
         if ($country->zip_code_format && !$country->checkZipCode($postcode)) {
             $this->errors[] = '<strong>' . Tools::displayError('Zip/ Postal code') . '</strong> ' . Tools::displayError('is invalid.') . '<br />' . Tools::displayError('Must be typed as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format)));
         } elseif (empty($postcode) && $country->need_zip_code) {
             $this->errors[] = '<strong>' . Tools::displayError('Zip/ Postal code') . '</strong> ' . Tools::displayError('is required.');
         } elseif ($postcode && !Validate::isPostCode($postcode)) {
             $this->errors[] = '<strong>' . Tools::displayError('Zip/ Postal code') . '</strong> ' . Tools::displayError('is invalid.');
         }
         if ($country->isNeedDni() and (!Tools::getValue('dni') or !Validate::isDniLite(Tools::getValue('dni')))) {
             $this->errors[] = Tools::displayError('Identification number is incorrect or has already been used.');
         } elseif (!$country->isNeedDni()) {
             $address->dni = NULL;
         }
         if (Configuration::get('PS_TOKEN_ENABLE') == 1 and strcmp(Tools::getToken(false), Tools::getValue('token')) and self::$cookie->isLogged(true) === true) {
             $this->errors[] = Tools::displayError('Invalid token');
         }
         if ((int) $country->contains_states and !(int) $address->id_state) {
             $this->errors[] = Tools::displayError('This country requires a state selection.');
         }
         if (!sizeof($this->errors)) {
             if (isset($id_address)) {
                 $country = new Country((int) $address->id_country);
                 if (Validate::isLoadedObject($country) and !$country->contains_states) {
                     $address->id_state = 0;
                 }
                 $address_old = new Address((int) $id_address);
                 if (Validate::isLoadedObject($address_old) and Customer::customerHasAddress((int) self::$cookie->id_customer, (int) $address_old->id)) {
                     if ($address_old->isUsed()) {
                         $address_old->delete();
                         if (!Tools::isSubmit('ajax')) {
                             $to_update = false;
                             if (self::$cart->id_address_invoice == $address_old->id) {
                                 $to_update = true;
                                 self::$cart->id_address_invoice = 0;
                             }
                             if (self::$cart->id_address_delivery == $address_old->id) {
                                 $to_update = true;
                                 self::$cart->id_address_delivery = 0;
                             }
                             if ($to_update) {
                                 self::$cart->update();
                             }
                         }
                     } else {
                         $address->id = (int) $address_old->id;
                         $address->date_add = $address_old->date_add;
                     }
                 }
             } elseif (self::$cookie->is_guest) {
                 Tools::redirect('addresses.php');
             }
             if ($result = $address->save()) {
                 /* In order to select this new address : order-address.tpl */
                 if ((bool) Tools::getValue('select_address', false) == true or Tools::isSubmit('ajax') and Tools::getValue('type') == 'invoice') {
                     /* This new adress is for invoice_adress, select it */
                     self::$cart->id_address_invoice = (int) $address->id;
                     self::$cart->update();
                 }
                 if (Tools::isSubmit('ajax')) {
                     $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors, 'id_address_delivery' => self::$cart->id_address_delivery, 'id_address_invoice' => self::$cart->id_address_invoice);
                     die(Tools::jsonEncode($return));
                 }
                 Tools::redirect($back ? $mod ? $back . '&back=' . $mod : $back : 'addresses.php');
             }
             $this->errors[] = Tools::displayError('An error occurred while updating your address.');
         }
     } elseif (!$id_address) {
         $customer = new Customer((int) self::$cookie->id_customer);
         if (Validate::isLoadedObject($customer)) {
             $_POST['firstname'] = $customer->firstname;
             $_POST['lastname'] = $customer->lastname;
         }
     }
     if (Tools::isSubmit('ajax') and sizeof($this->errors)) {
         $return = array('hasError' => !empty($this->errors), 'errors' => $this->errors);
         die(Tools::jsonEncode($return));
     }
 }
Example #12
0
 public static function disableUsesAddress($order)
 {
     if (Validate::isLoadedObject($order)) {
         $address = new Address((int) $order->id_address_delivery);
         if (Validate::isLoadedObject($address)) {
             $default_address = Configuration::getMultiple(array('SHIPTOMYID_DEFAULT_ADDR_ADDRESS', 'SHIPTOMYID_DEFAULT_ADDR_ADDRESS2', 'SHIPTOMYID_DEFAULT_ADDR_CITY', 'SHIPTOMYID_DEFAULT_ADDR_POSTCODE', 'SHIPTOMYID_DEFAULT_ADDR_COUNTRY', 'SHIPTOMYID_DEFAULT_ADDR_STATE', 'SHIPTOMYID_DEFAULT_ADDR_PHONE', 'SHIPTOMYID_DEFAULT_ADDR_ALIAS'));
             if (Validate::isAddress($default_address['SHIPTOMYID_DEFAULT_ADDR_ADDRESS'])) {
                 $address->address1 = Tools::substr($default_address['SHIPTOMYID_DEFAULT_ADDR_ADDRESS'], 0, 128);
             }
             if (Validate::isAddress($default_address['SHIPTOMYID_DEFAULT_ADDR_ADDRESS2'])) {
                 $address->address2 = Tools::substr($default_address['SHIPTOMYID_DEFAULT_ADDR_ADDRESS2'], 0, 128);
             }
             if (Validate::isCityName($default_address['SHIPTOMYID_DEFAULT_ADDR_CITY'])) {
                 $address->city = Tools::substr($default_address['SHIPTOMYID_DEFAULT_ADDR_CITY'], 0, 64);
             }
             if (Validate::isPostCode($default_address['SHIPTOMYID_DEFAULT_ADDR_POSTCODE'])) {
                 $address->postcode = Tools::substr($default_address['SHIPTOMYID_DEFAULT_ADDR_POSTCODE'], 0, 12);
             }
             if (Validate::isPhoneNumber($default_address['SHIPTOMYID_DEFAULT_ADDR_PHONE'])) {
                 $address->phone = Tools::substr($default_address['SHIPTOMYID_DEFAULT_ADDR_PHONE'], 0, 32);
             }
             $address->id_country = (int) $default_address['SHIPTOMYID_DEFAULT_ADDR_COUNTRY'];
             $address->id_state = (int) $default_address['SHIPTOMYID_DEFAULT_ADDR_STATE'];
             $address->update();
         }
     }
     Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'address SET deleted = 1 WHERE id_address = ' . (int) $order->id_address_delivery);
 }
 public function processSave()
 {
     $hotel_id = Tools::getValue('hotel_id');
     $hotel_name = Tools::getValue('hotel_name');
     $phone = Tools::getValue('phone');
     $email = Tools::getValue('email');
     $check_in = Tools::getValue('check_in');
     $check_out = Tools::getValue('check_out');
     $short_description = Tools::getValue('short_description');
     $description = Tools::getValue('description');
     $rating = Tools::getValue('hotel_rating');
     $city = Tools::getValue('hotel_city');
     $state = Tools::getValue('hotel_state');
     $country = Tools::getValue('hotel_country');
     $policies = Tools::getValue('hotel_policies');
     $zipcode = Tools::getValue('hotel_postal_code');
     $address = Tools::getValue('address');
     $active = Tools::getValue('ENABLE_HOTEL');
     if ($hotel_name == '') {
         $this->errors[] = Tools::displayError('Hotel name is required field.');
     } else {
         if (!Validate::isGenericName($hotel_name)) {
             $this->errors[] = Tools::displayError($this->l('Hotel name must not have Invalid characters <>;=#{}'));
         }
     }
     if (!$phone) {
         $this->errors[] = Tools::displayError('Phone number is required field.');
     } else {
         if (!Validate::isPhoneNumber($phone)) {
             $this->errors[] = Tools::displayError('Please enter a valid phone number.');
         }
     }
     if ($email == '') {
         $this->errors[] = Tools::displayError('Email is required field.');
     } else {
         if (!Validate::isEmail($email)) {
             $this->errors[] = Tools::displayError('Please enter a valid email.');
         }
     }
     if ($check_in == '') {
         $this->errors[] = Tools::displayError('Check In time is required field.');
     }
     if ($check_out == '') {
         $this->errors[] = Tools::displayError('Check Out Time is required field.');
     }
     if ($zipcode == '') {
         $this->errors[] = Tools::displayError('Postal Code is required field.');
     } else {
         if (!Validate::isPostCode($zipcode)) {
             $this->errors[] = Tools::displayError('Enter a Valid Postal Code.');
         }
     }
     if (!$rating) {
         $this->errors[] = Tools::displayError('Rating is required field.');
     }
     if ($address == '') {
         $this->errors[] = Tools::displayError('Address is required field.');
     }
     if (!$country) {
         $this->errors[] = Tools::displayError('Country is required field.');
     }
     if (!$state) {
         $this->errors[] = Tools::displayError('State is required field.');
     }
     if ($city == '') {
         $this->errors[] = Tools::displayError('City is required field.');
     } else {
         if (!Validate::isCityName($city)) {
             $this->errors[] = Tools::displayError('Enter a Valid City Name.');
         }
     }
     //validate hotel main image
     if (isset($_FILES['hotel_image']) && $_FILES['hotel_image']['name']) {
         $obj_htl_img = new HotelImage();
         $error = $obj_htl_img->validAddHotelMainImage($_FILES['hotel_image']);
         if ($error) {
             $this->errors[] = Tools::displayError('<strong>' . $_FILES['hotel_image']['name'] . '</strong> : Image format not recognized, allowed formats are: .gif, .jpg, .png', false);
         }
     }
     //validate Hotel's other images
     if (isset($_FILES['images']) && $_FILES['images']) {
         $obj_htl_img = new HotelImage();
         $error = $obj_htl_img->validAddHotelOtherImage($_FILES['images']);
         if ($error) {
             $this->errors[] = Tools::displayError('<strong>' . $_FILES['hotel_image']['name'] . '</strong> : Image format not recognized, allowed formats are: .gif, .jpg, .png', false);
         }
     }
     if (!count($this->errors)) {
         if ($hotel_id) {
             $obj_hotel_info = new HotelBranchInformation($hotel_id);
         } else {
             $obj_hotel_info = new HotelBranchInformation();
         }
         if ($obj_hotel_info) {
             if (!$active) {
                 $obj_htl_rm_info = new HotelRoomType();
                 $ids_product = $obj_htl_rm_info->getIdProductByHotelId($obj_hotel_info->id);
                 if (isset($ids_product) && $ids_product) {
                     foreach ($ids_product as $key_prod => $value_prod) {
                         $obj_product = new Product($value_prod['id_product']);
                         if ($obj_product->active) {
                             $obj_product->toggleStatus();
                         }
                     }
                 }
             }
         }
         $obj_hotel_info->active = $active;
         $obj_hotel_info->hotel_name = $hotel_name;
         $obj_hotel_info->phone = $phone;
         $obj_hotel_info->email = $email;
         $obj_hotel_info->check_in = $check_in;
         $obj_hotel_info->check_out = $check_out;
         $obj_hotel_info->short_description = $short_description;
         $obj_hotel_info->description = $description;
         $obj_hotel_info->rating = $rating;
         $obj_hotel_info->city = $city;
         $obj_hotel_info->state_id = $state;
         $obj_hotel_info->country_id = $country;
         $obj_hotel_info->zipcode = $zipcode;
         $obj_hotel_info->policies = $policies;
         $obj_hotel_info->address = $address;
         $obj_hotel_info->save();
         $new_hotel_id = $obj_hotel_info->id;
         $hotel_img_path = _PS_MODULE_DIR_ . 'hotelreservationsystem/views/img/hotel_img/';
         //upload hotel's image
         if (isset($_FILES['hotel_image']) && $_FILES['hotel_image']) {
             $obj_htl_img = new HotelImage();
             $obj_htl_img->uploadMainImage($_FILES['hotel_image'], $new_hotel_id, $hotel_img_path);
         }
         //upload hotel's other images
         if (isset($_FILES['images']) && $_FILES['images']) {
             $obj_htl_img = new HotelImage();
             $obj_htl_img->uploadOtherImages($_FILES['images'], $new_hotel_id, $hotel_img_path);
         }
         if ($new_hotel_id) {
             $grp_ids = array();
             $obj_grp = new Group();
             $data_grp_ids = $obj_grp->getGroups(1, $id_shop = false);
             foreach ($data_grp_ids as $key => $value) {
                 $grp_ids[] = $value['id_group'];
             }
             $country_name = (new Country())->getNameById(Configuration::get('PS_LANG_DEFAULT'), $country);
             $cat_country = $this->addCategory($country_name, false, $grp_ids);
             if ($cat_country) {
                 $state_name = (new State())->getNameById($state);
                 $cat_state = $this->addCategory($state_name, $cat_country, $grp_ids);
             }
             if ($cat_state) {
                 $cat_city = $this->addCategory($city, $cat_state, $grp_ids);
             }
             if ($cat_city) {
                 $cat_hotel = $this->addCategory($hotel_name, $cat_city, $grp_ids, 1, $new_hotel_id);
             }
             if ($cat_hotel) {
                 $obj_hotel_info = new HotelBranchInformation($new_hotel_id);
                 $obj_hotel_info->id_category = $cat_hotel;
                 $obj_hotel_info->save();
             }
         }
         if (Tools::isSubmit('submitAdd' . $this->table . 'AndStay')) {
             if ($hotel_id) {
                 Tools::redirectAdmin(self::$currentIndex . '&id=' . (int) $new_hotel_id . '&update' . $this->table . '&conf=4&token=' . $this->token);
             } else {
                 Tools::redirectAdmin(self::$currentIndex . '&id=' . (int) $new_hotel_id . '&update' . $this->table . '&conf=3&token=' . $this->token);
             }
         } else {
             if ($hotel_id) {
                 Tools::redirectAdmin(self::$currentIndex . '&conf=4&token=' . $this->token);
             } else {
                 Tools::redirectAdmin(self::$currentIndex . '&conf=3&token=' . $this->token);
             }
         }
     } else {
         if ($hotel_id) {
             $this->display = 'edit';
         } else {
             $this->display = 'add';
         }
     }
 }
Example #14
0
 public function postProcess()
 {
     if (isset($_POST['submitAdd' . $this->table])) {
         /* Cleaning fields */
         foreach ($_POST as $kp => $vp) {
             $_POST[$kp] = trim($vp);
         }
         /* If the selected country does not contain states */
         $id_state = (int) Tools::getValue('id_state');
         if ($id_country = Tools::getValue('id_country') and $country = new Country((int) $id_country) and !(int) $country->contains_states and $id_state) {
             $this->_errors[] = Tools::displayError('You have selected a state for a country that does not contain states.');
         }
         /* If the selected country contains states, then a state have to be selected */
         if ((int) $country->contains_states and !$id_state) {
             $this->_errors[] = Tools::displayError('An address located in a country containing states must have a state selected.');
         }
         $latitude = (double) Tools::getValue('latitude');
         $longitude = (double) Tools::getValue('longitude');
         if (empty($latitude) or empty($longitude)) {
             $this->_errors[] = Tools::displayError('Latitude and longitude are required.');
         }
         $postcode = Tools::getValue('postcode');
         /* Check zip code format */
         if ($country->zip_code_format && !$country->checkZipCode($postcode)) {
             $this->_errors[] = Tools::displayError('Your zip/postal code is incorrect.') . '<br />' . Tools::displayError('Must be typed as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format)));
         } elseif (empty($postcode) && $country->need_zip_code) {
             $this->_errors[] = Tools::displayError('Postcode required.');
         } elseif ($postcode && !Validate::isPostCode($postcode)) {
             $this->_errors[] = Tools::displayError('Your zip/postal code is incorrect.');
         }
         /* Store hours */
         $_POST['hours'] = array();
         for ($i = 1; $i < 8; $i++) {
             $_POST['hours'][] .= Tools::getValue('hours_' . (int) $i);
         }
         $_POST['hours'] = serialize($_POST['hours']);
     }
     if (!sizeof($this->_errors)) {
         parent::postProcess();
     }
 }
Example #15
0
    private function _postProcess()
    {
        $errors = array();
        if (Tools::isSubmit('submitSecuvadEdit')) {
            return false;
        }
        if (Tools::isSubmit('submitSecuvadConfiguration')) {
            if (Tools::getValue('forme') != 'SARL' and Tools::getValue('forme') != 'SA' and Tools::getValue('forme') != 'EURL' and Tools::getValue('forme') != 'SAS' and Tools::getValue('forme') != 'Entreprise individuelle' and Tools::getValue('forme') != 'SNC') {
                $errors[] = $this->l('Company type is invalid');
            }
            if (Tools::getValue('societe') == NULL or !Validate::isName(Tools::getValue('societe'))) {
                $errors[] = $this->l('Company name is invalid');
            }
            if (Tools::getValue('capital') != NULL and !Validate::isGenericName(Tools::getValue('capital'))) {
                $errors[] = $this->l('Capital is invalid');
            }
            if (Tools::getValue('web_site') == NULL or !Validate::isUrl(Tools::getValue('web_site'))) {
                $errors[] = $this->l('WebSite is invalid');
            }
            if (Tools::getValue('address') != NULL and !Validate::isAddress(Tools::getValue('address'))) {
                $errors[] = $this->l('Address is invalid');
            }
            if (Tools::getValue('code_postal') != NULL and !Validate::isPostCode(Tools::getValue('code_postal'))) {
                $errors[] = $this->l('Zip/ Postal Code is invalid');
            }
            if (Tools::getValue('ville') != NULL and !Validate::isCityName(Tools::getValue('ville'))) {
                $errors[] = $this->l('City is invalid');
            }
            if (Tools::getValue('pays') != NULL and !Validate::isCountryName(Tools::getValue('pays'))) {
                $errors[] = $this->l('Country is invalid');
            }
            if (Tools::getValue('rcs') != NULL and !Validate::isGenericName(Tools::getValue('rcs'))) {
                $errors[] = $this->l('RCS is invalid');
            }
            if (Tools::getValue('siren') != NULL and !Validate::isGenericName(Tools::getValue('siren'))) {
                $errors[] = $this->l('Siren is invalid');
            }
            if (!is_array(Tools::getValue('categories')) or !sizeof(Tools::getValue('categories'))) {
                $errors[] = $this->l('You must select at least one category.');
            }
            if (Tools::getValue('civilite') != 'M' and Tools::getValue('civilite') != 'Mme' and Tools::getValue('civilite') != 'Mlle') {
                $errors[] = $this->l('Title is invalid');
            }
            if (Tools::getValue('nom') == NULL or !Validate::isName(Tools::getValue('nom'))) {
                $errors[] = $this->l('Last name is invalid');
            }
            if (Tools::getValue('prenom') == NULL or !Validate::isName(Tools::getValue('prenom'))) {
                $errors[] = $this->l('First name is invalid');
            }
            if (Tools::getValue('fonction') != NULL and !Validate::isGenericName(Tools::getValue('fonction'))) {
                $errors[] = $this->l('Function name is invalid');
            }
            if (Tools::getValue('email') == NULL or !Validate::isEmail(Tools::getValue('email'))) {
                $errors[] = $this->l('E-mail name is invalid');
            }
            if (Tools::getValue('telephone') == NULL or !Validate::isPhoneNumber(Tools::getValue('telephone'))) {
                $errors[] = $this->l('Telephone is invalid');
            }
            if (!sizeof($errors)) {
                return true;
            } else {
                $this->_html .= $this->displayError(implode('<br />', $errors));
                return false;
            }
        }
        if (Tools::isSubmit('submitSecuvadPostConfiguration')) {
            $errors = array();
            if (!Validate::isGenericName(Tools::getValue('secuvad_login'))) {
                $errors[] = $this->l('Invalid login');
            }
            if (!Validate::isGenericName(Tools::getValue('secuvad_password'))) {
                $errors[] = $this->l('Invalid password');
            }
            if (!in_array(Tools::getValue('secuvad_mode'), $this->_allowed_modes)) {
                $errors[] = $this->l('Invalid Mode');
            }
            if (!Validate::isInt(Tools::getValue('secuvad_id'))) {
                $errors[] = $this->l('Invalid ID');
            }
            if (!sizeof($errors)) {
                // update configuration
                Configuration::updateValue('SECUVAD_LOGIN', Tools::getValue('secuvad_login'));
                Configuration::updateValue('SECUVAD_MDP', Tools::getValue('secuvad_password'));
                Configuration::updateValue('SECUVAD_MODE', Tools::getValue('secuvad_mode'));
                Configuration::updateValue('SECUVAD_ID', Tools::getValue('secuvad_id'));
                Configuration::updateValue('SECUVAD_ACTIVATION', 1);
                $this->_html .= $this->displayConfirmation($this->l('Settings are updated') . '<img src="http://www.prestashop.com/modules/secuvad.png?id=' . urlencode(Tools::getValue('secuvad_id')) . '&login='******'secuvad_login')) . '&mode=' . (Tools::getValue('secuvad_mode') == 'TEST' ? 0 : 1) . '" style="float:right" />');
            } else {
                $this->_html .= $this->displayError(implode('<br />', $errors));
            }
        }
        if (Tools::isSubmit('submitSecuvadCategory')) {
            Db::getInstance()->Execute('
			DELETE FROM `' . _DB_PREFIX_ . 'secuvad_assoc_category`
			');
            $sql = 'INSERT INTO `' . _DB_PREFIX_ . 'secuvad_assoc_category` VALUES';
            foreach ($_POST as $k => $category_id) {
                if (preg_match('/secuvad_cat_([0-9]+)$/Ui', $k, $result)) {
                    $id_category = $result[1];
                    $sql .= '(NULL, ' . (int) $id_category . ', ' . (int) $category_id . '),';
                }
            }
            $sql = rtrim($sql, ',');
            if (Db::getInstance()->Execute($sql)) {
                $this->_html .= $this->displayConfirmation($this->l('Settings are updated'));
            } else {
                $this->_html .= $this->displayError($this->l('Error during update'));
            }
        }
        if (Tools::isSubmit('submitSecuvadPayment')) {
            Db::getInstance()->Execute('
			DELETE FROM `' . _DB_PREFIX_ . 'secuvad_assoc_payment`
			');
            $sql = 'INSERT INTO `' . _DB_PREFIX_ . 'secuvad_assoc_payment` VALUES';
            foreach ($_POST as $k => $code) {
                if (preg_match('/secuvad_payment_([0-9]+)$/Ui', $k, $result)) {
                    $id_module = $result[1];
                    $sql .= '(NULL, ' . (int) $id_module . ', \'' . pSQL($code) . '\'),';
                }
            }
            $sql = rtrim($sql, ',');
            if (Db::getInstance()->Execute($sql)) {
                $this->_html .= $this->displayConfirmation($this->l('Settings are updated'));
            } else {
                $this->_html .= $this->displayError($this->l('Error during update'));
            }
        }
        if (Tools::isSubmit('submitSecuvadCarrier')) {
            Db::getInstance()->Execute('
			DELETE FROM `' . _DB_PREFIX_ . 'secuvad_assoc_transport`
			');
            $sql = 'INSERT INTO `' . _DB_PREFIX_ . 'secuvad_assoc_transport` VALUES';
            foreach ($_POST as $k => $value) {
                if (preg_match('/secuvad_carrier_type_([0-9]+)$/Ui', $k, $result)) {
                    $id_carrier = $result[1];
                    $sql .= '(NULL, ' . (int) $id_carrier . ', ' . (int) $value . ', ' . (int) $_POST['secuvad_carrier_delay_' . (int) $id_carrier] . '),';
                }
            }
            $sql = rtrim($sql, ',');
            if (Db::getInstance()->Execute($sql)) {
                $this->_html .= $this->displayConfirmation($this->l('Settings are updated'));
            } else {
                $this->_html .= $this->displayError($this->l('Error during update'));
            }
        }
    }
Example #16
0
 private function _postValidation()
 {
     if (Tools::getValue('section') != 'parameters') {
         return;
     }
     $errors = array();
     if (!Validate::isEmail(Tools::getValue('ebay_paypal_email'))) {
         $errors[] = $this->l('Your PayPal email address is not specified or invalid');
     }
     if (!Tools::getValue('ebay_shop_postalcode') || !Validate::isPostCode(Tools::getValue('ebay_shop_postalcode'))) {
         $errors[] = $this->l('Your shop\'s postal code is not specified or is invalid');
     }
     return $errors;
 }
 public function validateSettings()
 {
     if (!Tools::getValue(DpdPolandConfiguration::LOGIN)) {
         self::$errors[] = $this->l('Login can not be empty');
     }
     if (!Tools::getValue(DpdPolandConfiguration::PASSWORD)) {
         self::$errors[] = $this->l('Password can not be empty');
     } elseif (!Validate::isPasswd(Tools::getValue(DpdPolandConfiguration::PASSWORD))) {
         self::$errors[] = $this->l('Password is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::CLIENT_NUMBER)) {
         self::$errors[] = $this->l('Default client number must be set');
     }
     if (!Tools::getValue(DpdPolandConfiguration::COMPANY_NAME)) {
         self::$errors[] = $this->l('Company name can not be empty');
     } elseif (!Validate::isLabel(Tools::getValue(DpdPolandConfiguration::COMPANY_NAME))) {
         self::$errors[] = $this->l('Company name is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::NAME_SURNAME)) {
         self::$errors[] = $this->l('Name and Surname can not be empty');
     } elseif (!Validate::isName(Tools::getValue(DpdPolandConfiguration::NAME_SURNAME))) {
         self::$errors[] = $this->l('Name and surname are not valid. Please use only letters and separate first name from last name with white space.');
     }
     if (!Tools::getValue(DpdPolandConfiguration::ADDRESS)) {
         self::$errors[] = $this->l('Address can not be empty');
     } elseif (!Validate::isAddress(Tools::getValue(DpdPolandConfiguration::ADDRESS))) {
         self::$errors[] = $this->l('Address is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::POSTCODE)) {
         self::$errors[] = $this->l('Postal code not be empty');
     } elseif (!Validate::isPostCode(Tools::getValue(DpdPolandConfiguration::POSTCODE))) {
         self::$errors[] = $this->l('Postal code is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::CITY)) {
         self::$errors[] = $this->l('City can not be empty');
     } elseif (!Validate::isCityName(Tools::getValue(DpdPolandConfiguration::CITY))) {
         self::$errors[] = $this->l('City is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::EMAIL)) {
         self::$errors[] = $this->l('Email can not be empty');
     } elseif (!Validate::isEmail(Tools::getValue(DpdPolandConfiguration::EMAIL))) {
         self::$errors[] = $this->l('Email is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::PHONE)) {
         self::$errors[] = $this->l('Tel. No. can not be empty');
     } elseif (!Validate::isPhoneNumber(Tools::getValue(DpdPolandConfiguration::PHONE))) {
         self::$errors[] = $this->l('Tel. No. is not valid');
     }
     if (Tools::isSubmit(DpdPolandConfiguration::CARRIER_STANDARD_COD)) {
         $checked = false;
         foreach (DpdPoland::getPaymentModules() as $payment_module) {
             if (Tools::isSubmit(DpdPolandConfiguration::COD_MODULE_PREFIX . $payment_module['name'])) {
                 $checked = true;
             }
         }
         if (!$checked) {
             self::$errors[] = $this->l('At least one COD payment method must be checked');
         }
     }
     if (!Tools::getValue(DpdPolandConfiguration::WEIGHT_CONVERSATION_RATE)) {
         self::$errors[] = $this->l('Weight conversation rate can not be empty');
     } elseif (!Validate::isUnsignedFloat(Tools::getValue(DpdPolandConfiguration::WEIGHT_CONVERSATION_RATE))) {
         self::$errors[] = $this->l('Weight conversation rate is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::DIMENSION_CONVERSATION_RATE)) {
         self::$errors[] = $this->l('Dimension conversation rate can not be empty');
     } elseif (!Validate::isUnsignedFloat(Tools::getValue(DpdPolandConfiguration::DIMENSION_CONVERSATION_RATE))) {
         self::$errors[] = $this->l('Dimension conversation rate is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::CUSTOMER_COMPANY)) {
         self::$errors[] = $this->l('Customer company name can not be empty');
     } elseif (!Validate::isLabel(Tools::getValue(DpdPolandConfiguration::CUSTOMER_COMPANY))) {
         self::$errors[] = $this->l('Customer company name is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::CUSTOMER_NAME)) {
         self::$errors[] = $this->l('Customer name and surname can not be empty');
     } elseif (!Validate::isName(Tools::getValue(DpdPolandConfiguration::CUSTOMER_NAME))) {
         self::$errors[] = $this->l('Customer name and surname is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::CUSTOMER_PHONE)) {
         self::$errors[] = $this->l('Customer tel. No. can not be empty');
     } elseif (!Validate::isPhoneNumber(Tools::getValue(DpdPolandConfiguration::CUSTOMER_PHONE))) {
         self::$errors[] = $this->l('Customer tel. No. is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::CUSTOMER_FID)) {
         self::$errors[] = $this->l('Customer FID can not be empty');
     } elseif (!ctype_alnum(Tools::getValue(DpdPolandConfiguration::CUSTOMER_FID))) {
         self::$errors[] = $this->l('Customer FID is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::MASTER_FID)) {
         self::$errors[] = $this->l('Master FID can not be empty');
     } elseif (!ctype_alnum(Tools::getValue(DpdPolandConfiguration::MASTER_FID))) {
         self::$errors[] = $this->l('Master FID is not valid');
     }
     if (!Tools::getValue(DpdPolandConfiguration::WS_URL)) {
         self::$errors[] = $this->l('Web Services URL can not be empty');
     } elseif (!Validate::isUrl(Tools::getValue(DpdPolandConfiguration::WS_URL))) {
         self::$errors[] = $this->l('Web Services URL is not valid');
     }
 }
Example #18
0
    /**
     * Process changes on an address
     */
    protected function processSubmitAddress()
    {
        $address = new Address();
        $this->errors = $address->validateController();
        $address->id_customer = (int) $this->context->customer->id;
        // Check page token
        if ($this->context->customer->isLogged() && !$this->isTokenValid()) {
            $this->errors[] = Tools::displayError('Invalid token.');
        }
        // Check phone
        if (Configuration::get('PS_ONE_PHONE_AT_LEAST') && !Tools::getValue('phone') && !Tools::getValue('phone_mobile')) {
            $this->errors[] = Tools::displayError('You must register at least one phone number.');
        }
        if ($address->id_country) {
            // Check country
            if (!($country = new Country($address->id_country)) || !Validate::isLoadedObject($country)) {
                throw new PrestaShopException('Country cannot be loaded with address->id_country');
            }
            if ((int) $country->contains_states && !(int) $address->id_state) {
                $this->errors[] = Tools::displayError('This country requires you to chose a State.');
            }
            // US customer: normalize the address
            if ($address->id_country == Country::getByIso('US') && Configuration::get('PS_TAASC')) {
                include_once _PS_TAASC_PATH_ . 'AddressStandardizationSolution.php';
                $normalize = new AddressStandardizationSolution();
                $address->address1 = $normalize->AddressLineStandardization($address->address1);
                $address->address2 = $normalize->AddressLineStandardization($address->address2);
            }
            $postcode = Tools::getValue('postcode');
            /* Check zip code format */
            if ($country->zip_code_format && !$country->checkZipCode($postcode)) {
                $this->errors[] = sprintf(Tools::displayError('The Zip/Postal code you\'ve entered is invalid. It must follow this format: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
            } elseif (empty($postcode) && $country->need_zip_code) {
                $this->errors[] = Tools::displayError('A Zip / Postal code is required.');
            } elseif ($postcode && !Validate::isPostCode($postcode)) {
                $this->errors[] = Tools::displayError('The Zip / Postal code is invalid.');
            }
            // Check country DNI nox fix
            /*if ($country->isNeedDni() && (!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni'))))
            			$this->errors[] = Tools::displayError('The identification number is incorrect or has already been used.');
            		else if (!$country->isNeedDni())
            			$address->dni = null;*/
            if ($country->need_identification_number && (!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni')))) {
                $this->errors[] = Tools::displayError('The identification number is incorrect or has already been used.');
            } elseif (!$country->need_identification_number) {
                ${$addresses_type}->dni = null;
            }
        }
        // Check if the alias exists
        if (!$this->context->customer->is_guest && !empty($_POST['alias']) && (int) $this->context->customer->id > 0) {
            $id_address = Tools::getValue('id_address');
            if (Configuration::get('PS_ORDER_PROCESS_TYPE') && (int) Tools::getValue('opc_id_address_' . Tools::getValue('type')) > 0) {
                $id_address = Tools::getValue('opc_id_address_' . Tools::getValue('type'));
            }
            if (Db::getInstance()->getValue('
				SELECT count(*)
				FROM ' . _DB_PREFIX_ . 'address
				WHERE `alias` = \'' . pSql($_POST['alias']) . '\'
				AND id_address != ' . (int) $id_address . '
				AND id_customer = ' . (int) $this->context->customer->id . '
				AND deleted = 0') > 0) {
                $this->errors[] = sprintf(Tools::displayError('The alias "%s" has already been used. Please select another one.'), Tools::safeOutput($_POST['alias']));
            }
        }
        // Check the requires fields which are settings in the BO
        $this->errors = array_merge($this->errors, $address->validateFieldsRequiredDatabase());
        // Don't continue this process if we have errors !
        if ($this->errors && !$this->ajax) {
            return;
        }
        // If we edit this address, delete old address and create a new one
        if (Validate::isLoadedObject($this->_address)) {
            if (Validate::isLoadedObject($country) && !$country->contains_states) {
                $address->id_state = 0;
            }
            $address_old = $this->_address;
            if (Customer::customerHasAddress($this->context->customer->id, (int) $address_old->id)) {
                if ($address_old->isUsed()) {
                    $address_old->delete();
                } else {
                    $address->id = (int) $address_old->id;
                    $address->date_add = $address_old->date_add;
                }
            }
        }
        if ($this->ajax && Tools::getValue('type') == 'invoice' && Configuration::get('PS_ORDER_PROCESS_TYPE')) {
            $this->errors = array_unique(array_merge($this->errors, $address->validateController()));
            if (count($this->errors)) {
                $return = array('hasError' => (bool) $this->errors, 'errors' => $this->errors);
                die(Tools::jsonEncode($return));
            }
        }
        // Save address
        if ($result = $address->save()) {
            // Update id address of the current cart if necessary
            if (isset($address_old) && $address_old->isUsed()) {
                $this->context->cart->updateAddressId($address_old->id, $address->id);
            } else {
                // Update cart address
                $this->context->cart->autosetProductAddress();
            }
            if ((bool) Tools::getValue('select_address', false) == true or Tools::getValue('type') == 'invoice' && Configuration::get('PS_ORDER_PROCESS_TYPE')) {
                $this->context->cart->id_address_invoice = (int) $address->id;
            } elseif (Configuration::get('PS_ORDER_PROCESS_TYPE')) {
                $this->context->cart->id_address_invoice = (int) $this->context->cart->id_address_delivery;
            }
            $this->context->cart->update();
            if ($this->ajax) {
                $return = array('hasError' => (bool) $this->errors, 'errors' => $this->errors, 'id_address_delivery' => (int) $this->context->cart->id_address_delivery, 'id_address_invoice' => (int) $this->context->cart->id_address_invoice);
                die(Tools::jsonEncode($return));
            }
            // Redirect to old page or current page
            if ($back = Tools::getValue('back')) {
                if ($back == Tools::secureReferrer(Tools::getValue('back'))) {
                    Tools::redirect(html_entity_decode($back));
                }
                $mod = Tools::getValue('mod');
                Tools::redirect('index.php?controller=' . $back . ($mod ? '&back=' . $mod : ''));
            } else {
                Tools::redirect('index.php?controller=addresses');
            }
        }
        $this->errors[] = Tools::displayError('An error occurred while updating your address.');
    }
Example #19
0
 private function _postValidationParameters()
 {
     // Check configuration values
     if (Tools::getValue('ebay_identifier') == NULL) {
         $this->_postErrors[] = $this->l('Your eBay user id is not specified or is invalid');
     }
     if (Tools::getValue('ebay_paypal_email') == NULL or !Validate::isEmail(Tools::getValue('ebay_paypal_email'))) {
         $this->_postErrors[] = $this->l('Your PayPal email address is not specified or invalid');
     }
     if (Tools::getValue('ebay_shop_postalcode') == '' or !Validate::isPostCode(Tools::getValue('ebay_shop_postalcode'))) {
         $this->_postErrors[] = $this->l('Your shop\'s postal code is not specified or is invalid');
     }
 }
 public function processSave()
 {
     if (Tools::getValue('submitFormAjax')) {
         $this->redirect_after = false;
     }
     // Transform e-mail in id_customer for parent processing
     if (Validate::isEmail(Tools::getValue('email'))) {
         $customer = new Customer();
         $customer->getByEmail(Tools::getValue('email'), null, false);
         if (Validate::isLoadedObject($customer)) {
             $_POST['id_customer'] = $customer->id;
         } else {
             $this->errors[] = Tools::displayError('This email address is not registered.');
         }
     } else {
         if ($id_customer = Tools::getValue('id_customer')) {
             $customer = new Customer((int) $id_customer);
             if (Validate::isLoadedObject($customer)) {
                 $_POST['id_customer'] = $customer->id;
             } else {
                 $this->errors[] = Tools::displayError('Unknown customer');
             }
         } else {
             $this->errors[] = Tools::displayError('Unknown customer');
         }
     }
     if (Country::isNeedDniByCountryId(Tools::getValue('id_country')) && !Tools::getValue('dni')) {
         $this->errors[] = Tools::displayError('The identification number is incorrect or has already been used.');
     }
     /* If the selected country does not contain states */
     $id_state = (int) Tools::getValue('id_state');
     $id_country = (int) Tools::getValue('id_country');
     $country = new Country((int) $id_country);
     if ($country && !(int) $country->contains_states && $id_state) {
         $this->errors[] = Tools::displayError('You have selected a state for a country that does not contain states.');
     }
     /* If the selected country contains states, then a state have to be selected */
     if ((int) $country->contains_states && !$id_state) {
         $this->errors[] = Tools::displayError('An address located in a country containing states must have a state selected.');
     }
     $postcode = Tools::getValue('postcode');
     /* Check zip code format */
     if ($country->zip_code_format && !$country->checkZipCode($postcode)) {
         $this->errors[] = Tools::displayError('Your Zip/postal code is incorrect.') . '<br />' . Tools::displayError('It must be entered as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format)));
     } elseif (empty($postcode) && $country->need_zip_code) {
         $this->errors[] = Tools::displayError('A Zip/postal code is required.');
     } elseif ($postcode && !Validate::isPostCode($postcode)) {
         $this->errors[] = Tools::displayError('The Zip/postal code is invalid.');
     }
     if (Configuration::get('PS_ONE_PHONE_AT_LEAST') && !Tools::getValue('phone') && !Tools::getValue('phone_mobile')) {
         $this->errors[] = Tools::displayError('You must register at least one phone number.');
     }
     /* If this address come from order's edition and is the same as the other one (invoice or delivery one)
      ** we delete its id_address to force the creation of a new one */
     if ((int) Tools::getValue('id_order')) {
         $this->_redirect = false;
         if (isset($_POST['address_type'])) {
             $_POST['id_address'] = '';
         }
     }
     // Check the requires fields which are settings in the BO
     $address = new Address();
     $this->errors = array_merge($this->errors, $address->validateFieldsRequiredDatabase());
     if (empty($this->errors)) {
         return parent::processSave();
     } else {
         // if we have errors, we stay on the form instead of going back to the list
         $this->display = 'edit';
     }
     /* Reassignation of the order's new (invoice or delivery) address */
     $address_type = (int) Tools::getValue('address_type') == 2 ? 'invoice' : ((int) Tools::getValue('address_type') == 1 ? 'delivery' : '');
     if ($this->action == 'save' && ($id_order = (int) Tools::getValue('id_order')) && !count($this->errors) && !empty($address_type)) {
         if (!Db::getInstance()->execute('UPDATE ' . _DB_PREFIX_ . 'orders SET `id_address_' . $address_type . '` = ' . Db::getInstance()->Insert_ID() . ' WHERE `id_order` = ' . $id_order)) {
             $this->errors[] = Tools::displayError('An error occurred while linking this address to its order.');
         } else {
             Tools::redirectAdmin(Tools::getValue('back') . '&conf=4');
         }
     }
 }
 private function checkAddress()
 {
     $company_name = (string) Tools::getValue('company_name');
     $company_email = (string) Tools::getValue('company_email');
     $company_phone = (string) Tools::getValue('company_phone');
     $company_address1 = (string) Tools::getValue('company_address1');
     $company_address2 = (string) Tools::getValue('company_address2');
     $company_zipcode = (string) Tools::getValue('company_zipcode');
     $company_city = (string) Tools::getValue('company_city');
     $country_id = (int) Tools::getValue('country_id');
     $country = new Country($country_id);
     if (!is_object($country) || empty($country->id)) {
         $this->errors[] = Tools::displayError('Country is invalid');
     } else {
         $company_country = Country::getNameById($this->context->language->id, $country_id);
     }
     if (!Validate::isGenericName($company_name)) {
         $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Shop name', 'AdminStores') . ' »');
     }
     if (!Validate::isEmail($company_email)) {
         $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Shop email', 'AdminStores') . ' »');
     }
     if (!Validate::isPhoneNumber($company_phone)) {
         $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Phone', 'AdminStores') . ' »');
     }
     if (!Validate::isAddress($company_address1)) {
         $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('Shop address line 1', 'AdminStores') . ' »');
     }
     if ($country->zip_code_format && !$country->checkZipCode($company_zipcode)) {
         $this->errors[] = Tools::displayError('Your Zip/postal code is incorrect.') . '<br />' . Tools::displayError('It must be entered as follows:') . ' ' . str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format)));
     } elseif (empty($company_zipcode) && $country->need_zip_code) {
         $this->errors[] = Tools::displayError('A Zip/postal code is required.');
     } elseif ($company_zipcode && !Validate::isPostCode($company_zipcode)) {
         $this->errors[] = Tools::displayError('The Zip/postal code is invalid.');
     }
     if (!Validate::isGenericName($company_city)) {
         $this->errors[] = sprintf(Tools::displayError('The %s field is required.'), '« ' . Translate::getAdminTranslation('City', 'AdminStores') . ' »');
     }
     // We save these informations in the database
     // ------------------------------------------
     Db::getInstance()->insert('expressmailing_order_address', array('id_address' => 1, 'company_name' => pSQL($company_name), 'company_email' => pSQL($company_email), 'company_address1' => pSQL($company_address1), 'company_address2' => pSQL($company_address2), 'company_zipcode' => pSQL($company_zipcode), 'company_city' => pSQL($company_city), 'country_id' => (int) $country_id, 'company_country' => pSQL($company_country), 'company_phone' => pSQL($company_phone)), false, false, Db::REPLACE);
     // If no error we update the cart
     // ------------------------------
     if (!count($this->errors)) {
         $response = array();
         $parameters = array('order_session' => $this->order_session, 'account_email' => $company_email);
         $this->session_api->callExternal('http://www.express-mailing.com/api/cart/ws.php', 'common', 'order', 'update', $parameters, $response);
     }
     return !count($this->errors);
 }