本文整理汇总了PHP中Country::checkZipCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Country::checkZipCode方法的具体用法?PHP Country::checkZipCode怎么用?PHP Country::checkZipCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Country
的用法示例。
在下文中一共展示了Country::checkZipCode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processSave
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');
}
}
}
示例2: postProcess
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';
}
}
示例3: processCreateRule
protected function processCreateRule()
{
$zip_code = Tools::getValue('zipcode');
$id_rule = (int) Tools::getValue('id_tax_rule');
$id_tax = (int) Tools::getValue('id_tax');
$id_tax_rules_group = (int) Tools::getValue('id_tax_rules_group');
$behavior = (int) Tools::getValue('behavior');
$description = pSQL(Tools::getValue('description'));
if ((int) ($id_country = Tools::getValue('country')) == 0) {
$countries = Country::getCountries($this->context->language->id);
$this->selected_countries = array();
foreach ($countries as $country) {
$this->selected_countries[] = (int) $country['id_country'];
}
} else {
$this->selected_countries = array($id_country);
}
$this->selected_states = Tools::getValue('states');
if (empty($this->selected_states) || count($this->selected_states) == 0) {
$this->selected_states = array(0);
}
$tax_rules_group = new TaxRulesGroup((int) $id_tax_rules_group);
foreach ($this->selected_countries as $id_country) {
$first = true;
foreach ($this->selected_states as $id_state) {
if ($tax_rules_group->hasUniqueTaxRuleForCountry($id_country, $id_state, $id_rule)) {
$this->errors[] = Tools::displayError('A tax rule already exists for this country/state with tax only behavior.');
continue;
}
$tr = new TaxRule();
// update or creation?
if (isset($id_rule) && $first) {
$tr->id = $id_rule;
$first = false;
}
$tr->id_tax = $id_tax;
$tax_rules_group = new TaxRulesGroup((int) $id_tax_rules_group);
$tr->id_tax_rules_group = (int) $tax_rules_group->id;
$tr->id_country = (int) $id_country;
$tr->id_state = (int) $id_state;
list($tr->zipcode_from, $tr->zipcode_to) = $tr->breakDownZipCode($zip_code);
// Construct Object Country
$country = new Country((int) $id_country, (int) $this->context->language->id);
if ($zip_code && $country->need_zip_code) {
if ($country->zip_code_format) {
foreach (array($tr->zipcode_from, $tr->zipcode_to) as $zip_code) {
if ($zip_code) {
if (!$country->checkZipCode($zip_code)) {
$this->errors[] = sprintf(Tools::displayError('The Zip/postal code is invalid. It must be typed as follows: %s for %s.'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))), $country->name);
}
}
}
}
}
$tr->behavior = (int) $behavior;
$tr->description = $description;
$this->tax_rule = $tr;
$_POST['id_state'] = $tr->id_state;
$this->errors = array_merge($this->errors, $this->validateTaxRule($tr));
if (count($this->errors) == 0) {
$tax_rules_group = $this->updateTaxRulesGroup($tax_rules_group);
$tr->id = (int) $tax_rules_group->getIdTaxRuleGroupFromHistorizedId((int) $tr->id);
$tr->id_tax_rules_group = (int) $tax_rules_group->id;
if (!$tr->save()) {
$this->errors[] = Tools::displayError('An error has occurred: Cannot save the current tax rule.');
}
}
}
}
if (count($this->errors) == 0) {
Tools::redirectAdmin(self::$currentIndex . '&' . $this->identifier . '=' . (int) $tax_rules_group->id . '&conf=4&update' . $this->table . '&token=' . $this->token);
} else {
$this->display = 'edit';
}
}
示例4: processSubmitAccount
//.........这里部分代码省略.........
if (count($this->context->cart->getProducts(true)) > 0) {
Tools::redirect('index.php?controller=order&multi-shipping=' . (int) Tools::getValue('multi-shipping'));
} else {
Tools::redirect('index.php?controller=my-account');
}
}
}
}
} else {
$lastnameAddress = $inv_first_on ? $_POST['lastname_invoice'] : $_POST['lastname'];
$firstnameAddress = $inv_first_on ? $_POST['firstname_invoice'] : $_POST['firstname'];
// Preparing address
$id_address = isset($this->context->cart->id_address_delivery) ? (int) $this->context->cart->id_address_delivery : 0;
if ($id_address > 0) {
$address = new Address($id_address);
} else {
$address = new Address();
}
$_POST['lastname'] = $lastnameAddress;
$_POST['firstname'] = $firstnameAddress;
$address->id_customer = 1;
$this->errors = array_unique(array_merge($this->errors, $address->validateController()));
// US customer: normalize the address
if (version_compare(_PS_VERSION_, "1.6.0") < 0 && $address->id_country == Country::getByIso('US')) {
include_once _PS_TAASC_PATH_ . 'AddressStandardizationSolution.php';
$normalize = new AddressStandardizationSolution();
$address->address1 = $normalize->AddressLineStandardization($address->address1);
$address->address2 = $normalize->AddressLineStandardization($address->address2);
}
$inv_suffix = $inv_first_on ? "_invoice" : "";
$country = new Country((int) Tools::getValue('id_country' . $inv_suffix));
if ($country->need_zip_code) {
if (($postcode = Tools::getValue('postcode' . $inv_suffix)) && $country->zip_code_format) {
if (!$country->checkZipCode($postcode)) {
$this->errors[] = sprintf(Tools::displayError('Zip/Postal code is invalid. Must be typed as follows: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
}
} elseif ($country->zip_code_format && !$this->context->cart->isVirtualCart()) {
$this->errors[] = Tools::displayError('Zip/Postal code is required.');
} elseif ($postcode && !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode)) {
$this->errors[] = Tools::displayError('Zip/Postal code is invalid.');
}
}
/*if ($country->need_identification_number && (!Tools::getValue('dni') || !Validate::isDniLite(Tools::getValue('dni'))))
$this->errors[] = Tools::displayError('Identification number is incorrect or has already been used.');
elseif (!$country->need_identification_number)
$address->dni = null;*/
}
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 is already registered with this e-mail, please enter your password or request a new one.', false);
}
if (Tools::isSubmit('newsletter')) {
$this->processCustomerNewsletter($customer);
}
$customer->birthday = empty($_POST['years']) ? '' : (int) $_POST['years'] . '-' . (int) $_POST['months'] . '-' . (int) $_POST['days'];
if (!Validate::isBirthDate($customer->birthday)) {
$this->errors[] = Tools::displayError('Invalid birthday.');
}
if (!count($this->errors)) {
// if registration type is in one step, we save the address
if (Configuration::get('PS_REGISTRATION_PROCESS_TYPE')) {
if (!($country = new Country($address->id_country, Configuration::get('PS_LANG_DEFAULT'))) || !Validate::isLoadedObject($country)) {
die(Tools::displayError());
示例5: processCreateRule
protected function processCreateRule()
{
$zip_code = Tools::getValue('zipcode');
$id_rule = (int) Tools::getValue('id_tax_rule');
$id_tax = (int) Tools::getValue('id_tax');
$id_tax_rules_group = (int) Tools::getValue('id_tax_rules_group');
$behavior = (int) Tools::getValue('behavior');
$description = pSQL(Tools::getValue('description'));
$this->selected_countries = Tools::getValue('country');
$this->selected_states = Tools::getValue('states');
if (empty($this->selected_states) || count($this->selected_states) == 0) {
$this->selected_states = array(0);
}
foreach ($this->selected_countries as $id_country) {
foreach ($this->selected_states as $id_state) {
$tr = new TaxRule();
// update or creation?
if (isset($id_rule)) {
$tr->id = $id_rule;
}
$tr->id_tax = $id_tax;
$tr->id_tax_rules_group = (int) $id_tax_rules_group;
$tr->id_country = (int) $id_country;
$tr->id_state = (int) $id_state;
list($tr->zipcode_from, $tr->zipcode_to) = $tr->breakDownZipCode($zip_code);
// Construct Object Country
$country = new Country((int) $id_country);
if ($zip_code && $country->need_zip_code) {
if ($country->zip_code_format) {
foreach (array($tr->zipcode_from, $tr->zipcode_to) as $zip_code) {
if ($zip_code) {
if (!$country->checkZipCode($zip_code)) {
$this->errors[] = sprintf(Tools::displayError('Zip/Postal code is invalid. Must be typed as follows: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
}
}
}
}
}
$tr->behavior = (int) $behavior;
$tr->description = $description;
$this->tax_rule = $tr;
$_POST['id_state'] = $tr->id_state;
$this->errors = array_merge($this->errors, $this->validateTaxRule($tr));
if (count($this->errors) == 0) {
if (!$tr->save()) {
$this->errors[] = Tools::displayError('An error has occurred: Can\'t save the current tax rule');
} else {
Tools::redirectAdmin(self::$currentIndex . '&' . $this->identifier . '=' . $tr->id_tax_rules_group . '&conf=4&update' . $this->table . '&token=' . $this->token);
}
}
}
}
if (count($this->errors) == 0) {
Tools::redirectAdmin(self::$currentIndex . '&' . $this->identifier . '=' . (int) $id_tax_rules_group . '&conf=4&update' . $this->table . '&token=' . $this->token);
} else {
$this->display = 'edit';
}
}
示例6: checkCSVZip
private function checkCSVZip($id_country, $iso_code)
{
$country = new Country($id_country);
return $country->checkZipCode($iso_code);
}
示例7: postProcess
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();
}
}
示例8: postProcess
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');
}
}
}