Could you give more details on what it is you ar trying to do ... I am not following your brief description ... :unsure:
Printable View
Could you give more details on what it is you ar trying to do ... I am not following your brief description ... :unsure:
1st post and new to ZC!
I do not use the estimate shipping module but I need to exclude many countries from shipping due to the regulations of U.S. Department of Commerce - Bureau of Industry and Security.
If I continue the code to be the below will it restrict countries *not on the list by ISO Code 2?
Code:$countries = "select countries_id, countries_name
from " . TABLE_COUNTRIES . "
WHERE countries_iso_code_2 = 'US' or countries_iso_code_2 = 'CA', 'AU', 'AT', 'BE', 'BZ', 'CZ', ....etc
order by countries_name";
You would need to write this correctly for more countries ...
Code:
$countries = "select countries_id, countries_name from " . TABLE_COUNTRIES . " WHERE countries_iso_code_2 = 'US' or countries_iso_code_2 = 'CA' or countries_iso_code_2 = 'AU' or countries_iso_code_2 = 'AT' etc. etc. etc. order by countries_name";
Thank you. I think I wrote it like you said but it's didn't work, all countries still appear as options. Is this right? Do I need to change or remove something else? Is it maybe allowing all countries by ISO Code 3 definition? I am using the ups.php module for shipping.
Code:$countries = "select countries_id, countries_name
from " . TABLE_COUNTRIES . "
WHERE countries_iso_code_2 = 'US' or countries_iso_code_2 = 'CA' or countries_iso_code_2 = 'AU' or countries_iso_code_2 = 'AT' or countries_iso_code_2 = 'BE' or countries_iso_code_2 = 'BZ' or countries_iso_code_2 = 'CZ' or countries_iso_code_2 = 'DK' or countries_iso_code_2 = 'EE' or countries_iso_code_2 = 'FJ' or countries_iso_code_2 = 'FI' or countries_iso_code_2 = 'FR' or countries_iso_code_2 = 'DE' or countries_iso_code_2 = 'GR' or countries_iso_code_2 = 'GG' or countries_iso_code_2 = 'HK' or countries_iso_code_2 = 'HU' or countries_iso_code_2 = 'IS' or countries_iso_code_2 = 'IN' or countries_iso_code_2 = 'ID' or countries_iso_code_2 = 'IE' or countries_iso_code_2 = 'IM' or countries_iso_code_2 = 'IL' or countries_iso_code_2 = 'IT' or countries_iso_code_2 = 'JM' or countries_iso_code_2 = 'JP' or countries_iso_code_2 = 'KR' or countries_iso_code_2 = 'LV' or countries_iso_code_2 = 'LI' or countries_iso_code_2 = 'MY' or countries_iso_code_2 = 'MV' or countries_iso_code_2 = 'MU' or countries_iso_code_2 = 'MX' or countries_iso_code_2 = 'MC' or countries_iso_code_2 = 'NL' or countries_iso_code_2 = 'NZ' or countries_iso_code_2 = 'NO' or countries_iso_code_2 = 'PY' or countries_iso_code_2 = 'PU' or countries_iso_code_2 = 'PE' or countries_iso_code_2 = 'PH' or countries_iso_code_2 = 'PL' or countries_iso_code_2 = 'PT' or countries_iso_code_2 = 'PR' or countries_iso_code_2 = 'RO' or countries_iso_code_2 = 'RU' or countries_iso_code_2 = 'SC' or countries_iso_code_2 = 'SG' or countries_iso_code_2 = 'SK' or countries_iso_code_2 = 'SI' or countries_iso_code_2 = 'ZA' or countries_iso_code_2 = 'ES' or countries_iso_code_2 = 'SZ' or countries_iso_code_2 = 'SE' or countries_iso_code_2 = 'CH' or countries_iso_code_2 = 'TW' or countries_iso_code_2 = 'TH' or countries_iso_code_2 = 'TR' or countries_iso_code_2 = 'UA' or countries_iso_code_2 = 'AE' or countries_iso_code_2 = 'GB' or countries_iso_code_2 = 'UM' or countries_iso_code_2 = 'VN'
order by countries_name";
$countries_values = $db->Execute($countries);
$countries_array = array('countries_name' => $countries_values->fields['countries_name'],
'countries_iso_code_2' => $countries_values->fields['countries_iso_code_2'],
'countries_iso_code_3' => $countries_values->fields['countries_iso_code_3']);
Make sure you have it in the right place of the function zen_get_countries:
Code:} else {
/*
$countries = "select countries_id, countries_name
from " . TABLE_COUNTRIES . "
order by countries_name";
*/
$countries = "select countries_id, countries_name
from " . TABLE_COUNTRIES . "
WHERE countries_iso_code_2 = 'US' or countries_iso_code_2 = 'CA' or countries_iso_code_2 = 'AU' or countries_iso_code_2 = 'AT' or countries_iso_code_2 = 'BE' or countries_iso_code_2 = 'BZ' or countries_iso_code_2 = 'CZ' or countries_iso_code_2 = 'DK' or countries_iso_code_2 = 'EE' or countries_iso_code_2 = 'FJ' or countries_iso_code_2 = 'FI' or countries_iso_code_2 = 'FR' or countries_iso_code_2 = 'DE' or countries_iso_code_2 = 'GR' or countries_iso_code_2 = 'GG' or countries_iso_code_2 = 'HK' or countries_iso_code_2 = 'HU' or countries_iso_code_2 = 'IS' or countries_iso_code_2 = 'IN' or countries_iso_code_2 = 'ID' or countries_iso_code_2 = 'IE' or countries_iso_code_2 = 'IM' or countries_iso_code_2 = 'IL' or countries_iso_code_2 = 'IT' or countries_iso_code_2 = 'JM' or countries_iso_code_2 = 'JP' or countries_iso_code_2 = 'KR' or countries_iso_code_2 = 'LV' or countries_iso_code_2 = 'LI' or countries_iso_code_2 = 'MY' or countries_iso_code_2 = 'MV' or countries_iso_code_2 = 'MU' or countries_iso_code_2 = 'MX' or countries_iso_code_2 = 'MC' or countries_iso_code_2 = 'NL' or countries_iso_code_2 = 'NZ' or countries_iso_code_2 = 'NO' or countries_iso_code_2 = 'PY' or countries_iso_code_2 = 'PU' or countries_iso_code_2 = 'PE' or countries_iso_code_2 = 'PH' or countries_iso_code_2 = 'PL' or countries_iso_code_2 = 'PT' or countries_iso_code_2 = 'PR' or countries_iso_code_2 = 'RO' or countries_iso_code_2 = 'RU' or countries_iso_code_2 = 'SC' or countries_iso_code_2 = 'SG' or countries_iso_code_2 = 'SK' or countries_iso_code_2 = 'SI' or countries_iso_code_2 = 'ZA' or countries_iso_code_2 = 'ES' or countries_iso_code_2 = 'SZ' or countries_iso_code_2 = 'SE' or countries_iso_code_2 = 'CH' or countries_iso_code_2 = 'TW' or countries_iso_code_2 = 'TH' or countries_iso_code_2 = 'TR' or countries_iso_code_2 = 'UA' or countries_iso_code_2 = 'AE' or countries_iso_code_2 = 'GB' or countries_iso_code_2 = 'UM' or countries_iso_code_2 = 'VN'
order by countries_name";
$countries_values = $db->Execute($countries);
I think I did. :(
Lines 1-100:
Code:<?php
/**
* functions_lookups.php
* Lookup Functions for various Zen Cart activities such as countries, prices, products, product types, etc
*
* @package functions
* @copyright Copyright 2003-2011 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: functions_lookups.php 19352 2011-08-19 16:13:43Z ajeh $
*/
/**
* Returns an array with countries
*
* @param int If set limits to a single country
* @param boolean If true adds the iso codes to the array
*/
function zen_get_countries($countries_id = '', $with_iso_codes = false) {
global $db;
$countries_array = array();
if (zen_not_null($countries_id)) {
if ($with_iso_codes == true) {
$countries = "select countries_id, countries_name
from " . TABLE_COUNTRIES . "
WHERE countries_iso_code_2 = 'US' or countries_iso_code_2 = 'CA' or countries_iso_code_2 = 'AU' or countries_iso_code_2 = 'AT' or countries_iso_code_2 = 'BE' or countries_iso_code_2 = 'BZ' or countries_iso_code_2 = 'CZ' or countries_iso_code_2 = 'DK' or countries_iso_code_2 = 'EE' or countries_iso_code_2 = 'FJ' or countries_iso_code_2 = 'FI' or countries_iso_code_2 = 'FR' or countries_iso_code_2 = 'DE' or countries_iso_code_2 = 'GR' or countries_iso_code_2 = 'GG' or countries_iso_code_2 = 'HK' or countries_iso_code_2 = 'HU' or countries_iso_code_2 = 'IS' or countries_iso_code_2 = 'IN' or countries_iso_code_2 = 'ID' or countries_iso_code_2 = 'IE' or countries_iso_code_2 = 'IM' or countries_iso_code_2 = 'IL' or countries_iso_code_2 = 'IT' or countries_iso_code_2 = 'JM' or countries_iso_code_2 = 'JP' or countries_iso_code_2 = 'KR' or countries_iso_code_2 = 'LV' or countries_iso_code_2 = 'LI' or countries_iso_code_2 = 'MY' or countries_iso_code_2 = 'MV' or countries_iso_code_2 = 'MU' or countries_iso_code_2 = 'MX' or countries_iso_code_2 = 'MC' or countries_iso_code_2 = 'NL' or countries_iso_code_2 = 'NZ' or countries_iso_code_2 = 'NO' or countries_iso_code_2 = 'PY' or countries_iso_code_2 = 'PU' or countries_iso_code_2 = 'PE' or countries_iso_code_2 = 'PH' or countries_iso_code_2 = 'PL' or countries_iso_code_2 = 'PT' or countries_iso_code_2 = 'PR' or countries_iso_code_2 = 'RO' or countries_iso_code_2 = 'RU' or countries_iso_code_2 = 'SC' or countries_iso_code_2 = 'SG' or countries_iso_code_2 = 'SK' or countries_iso_code_2 = 'SI' or countries_iso_code_2 = 'ZA' or countries_iso_code_2 = 'ES' or countries_iso_code_2 = 'SZ' or countries_iso_code_2 = 'SE' or countries_iso_code_2 = 'CH' or countries_iso_code_2 = 'TW' or countries_iso_code_2 = 'TH' or countries_iso_code_2 = 'TR' or countries_iso_code_2 = 'UA' or countries_iso_code_2 = 'AE' or countries_iso_code_2 = 'GB' or countries_iso_code_2 = 'UM' or countries_iso_code_2 = 'VN'
order by countries_name";
$countries_values = $db->Execute($countries);
$countries_array = array('countries_name' => $countries_values->fields['countries_name'],
'countries_iso_code_2' => $countries_values->fields['countries_iso_code_2'],
'countries_iso_code_3' => $countries_values->fields['countries_iso_code_3']);
} else {
$countries = "select countries_name
from " . TABLE_COUNTRIES . "
where countries_id = '" . (int)$countries_id . "'";
$countries_values = $db->Execute($countries);
$countries_array = array('countries_name' => $countries_values->fields['countries_name']);
}
} else {
$countries = "select countries_id, countries_name
from " . TABLE_COUNTRIES . "
order by countries_name";
$countries_values = $db->Execute($countries);
while (!$countries_values->EOF) {
$countries_array[] = array('countries_id' => $countries_values->fields['countries_id'],
'countries_name' => $countries_values->fields['countries_name']);
$countries_values->MoveNext();
}
}
return $countries_array;
}
/*
* Alias function to zen_get_countries()
*/
function zen_get_country_name($country_id) {
$country_array = zen_get_countries($country_id);
return $country_array['countries_name'];
}
/**
* Alias function to zen_get_countries, which also returns the countries iso codes
*
* @param int If set limits to a single country
*/
function zen_get_countries_with_iso_codes($countries_id) {
return zen_get_countries($countries_id, true);
}
/*
* Return the zone (State/Province) name
* TABLES: zones
*/
function zen_get_zone_name($country_id, $zone_id, $default_zone) {
global $db;
$zone_query = "select zone_name
from " . TABLE_ZONES . "
where zone_country_id = '" . (int)$country_id . "'
and zone_id = '" . (int)$zone_id . "'";
$zone = $db->Execute($zone_query);
if ($zone->RecordCount()) {
return $zone->fields['zone_name'];
} else {
return $default_zone;
}
}
Put your code changes in the SELECT *after* the ELSE you have it in the first part of the IF statement ...
Look at the code I posted to see the difference ...
And..... problem solved. Thanks!
You are most welcome ... thanks for the update that this is now working for you ... :smile:
I am in the process of setting up my store and needed to adjust or select which countries I will ship to. I have a US store and there are some restrictions as to the countries I can ship to. I thought that deleting countries from the database was not an acceptable solution because I may need to add them back, and making such a long selection in the database select code as above gets rather messy. Since the ability to turn on or off countries is not currently implemented, I took it upon myself to implement this feature which turned out to be easier than I thought it would be. Here's what I did:
First, I added a new field to the countries table in the database: countries_active char(1) default 1
I used phpMyAdmin to make the change as it was very easy with this tool and it defaulted all existing entries in the table.
Next I changed the includes/functions/function_lookup.php file and added a where clause to each of the select statements for the countries lookup:
Next I added a constant to admin/includes/languages/countries.php :Code:$countries = "select countries_id, countries_name
from " . TABLE_COUNTRIES . "
where countries_active > '0'
order by countries_name";
The final step is the biggest one, lot of changes to admin/countries.php. First is the update the action steps (these are at the top of the file):Code:define('TEXT_INFO_COUNTRY_ACTIVE', 'Ship to Country?');
Note the added lines:Code:switch ($action) {
case 'insert':
$countries_name = zen_db_prepare_input($_POST['countries_name']);
$countries_iso_code_2 = zen_db_prepare_input($_POST['countries_iso_code_2']);
$countries_iso_code_3 = zen_db_prepare_input($_POST['countries_iso_code_3']);
$address_format_id = zen_db_prepare_input($_POST['address_format_id']);
$countries_active = zen_db_prepare_input($_POST['countries_active']);
$db->Execute("insert into " . TABLE_COUNTRIES . "
(countries_name, countries_iso_code_2, countries_iso_code_3, address_format_id, countries_active)
values ('" . zen_db_input($countries_name) . "',
'" . zen_db_input($countries_iso_code_2) . "',
'" . zen_db_input($countries_iso_code_3) . "',
'" . (int)$address_format_id . "',
'" . (zen_db_input($countries_active) > '' ? 1 : 0) . "')");
zen_redirect(zen_href_link(FILENAME_COUNTRIES));
break;
case 'save':
$countries_id = zen_db_prepare_input($_GET['cID']);
$countries_name = zen_db_prepare_input($_POST['countries_name']);
$countries_iso_code_2 = zen_db_prepare_input($_POST['countries_iso_code_2']);
$countries_iso_code_3 = zen_db_prepare_input($_POST['countries_iso_code_3']);
$address_format_id = zen_db_prepare_input($_POST['address_format_id']);
$countries_active = zen_db_prepare_input($_POST['countries_active']);
$db->Execute("update " . TABLE_COUNTRIES . "
set countries_name = '" . zen_db_input($countries_name) . "',
countries_iso_code_2 = '" . zen_db_input($countries_iso_code_2) . "',
countries_iso_code_3 = '" . zen_db_input($countries_iso_code_3) . "',
address_format_id = '" . (int)$address_format_id . "',
countries_active = '" . (zen_db_input($countries_active) > '' ? 1 : 0) . "'
where countries_id = '" . (int)$countries_id . "'");
zen_redirect(zen_href_link(FILENAME_COUNTRIES, 'page=' . $_GET['page'] . '&cID=' . $countries_id));
break;
Then I made changes to the bottom part of the file that displays and allows for editing within the admin screen:Code:$countries_active = zen_db_prepare_input($_POST['countries_active']);
'countries_active = '" .(zen_db_input($countries_active) > '' ? 1 : 0) . "'
Note the lines added for 'countries_active'
This now allows me to turn on or off the countries I ship to without having to delete entries from the database. Hopefully this will help others with this issue.Code:switch ($action) {
case 'new':
$heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_NEW_COUNTRY . '</b>');
$contents = array('form' => zen_draw_form('countries', FILENAME_COUNTRIES, 'page=' . $_GET['page'] . '&action=insert'));
$contents[] = array('text' => TEXT_INFO_INSERT_INTRO);
$contents[] = array('text' => '<br>' . TEXT_INFO_COUNTRY_NAME . '<br>' . zen_draw_input_field('countries_name'));
$contents[] = array('text' => '<br>' . TEXT_INFO_COUNTRY_CODE_2 . '<br>' . zen_draw_input_field('countries_iso_code_2'));
$contents[] = array('text' => '<br>' . TEXT_INFO_COUNTRY_CODE_3 . '<br>' . zen_draw_input_field('countries_iso_code_3'));
$contents[] = array('text' => '<br>' . TEXT_INFO_ADDRESS_FORMAT . '<br>' . zen_draw_pull_down_menu('address_format_id', zen_get_address_formats()));
$contents[] = array('text' => '<br>' . TEXT_INFO_COUNTRY_ACTIVE . '<br>' . zen_draw_checkbox_field('countries_active', '', true));
$contents[] = array('align' => 'center', 'text' => '<br>' . zen_image_submit('button_insert.gif', IMAGE_INSERT) . ' <a href="' . zen_href_link(FILENAME_COUNTRIES, 'page=' . $_GET['page']) . '">' . zen_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
break;
case 'edit':
$heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_EDIT_COUNTRY . '</b>');
$contents = array('form' => zen_draw_form('countries', FILENAME_COUNTRIES, 'page=' . $_GET['page'] . '&cID=' . $cInfo->countries_id . '&action=save'));
$contents[] = array('text' => TEXT_INFO_EDIT_INTRO);
$contents[] = array('text' => '<br>' . TEXT_INFO_COUNTRY_NAME . '<br>' . zen_draw_input_field('countries_name', htmlspecialchars($cInfo->countries_name, ENT_COMPAT, CHARSET, TRUE)));
$contents[] = array('text' => '<br>' . TEXT_INFO_COUNTRY_CODE_2 . '<br>' . zen_draw_input_field('countries_iso_code_2', $cInfo->countries_iso_code_2));
$contents[] = array('text' => '<br>' . TEXT_INFO_COUNTRY_CODE_3 . '<br>' . zen_draw_input_field('countries_iso_code_3', $cInfo->countries_iso_code_3));
$contents[] = array('text' => '<br>' . TEXT_INFO_ADDRESS_FORMAT . '<br>' . zen_draw_pull_down_menu('address_format_id', zen_get_address_formats(), $cInfo->address_format_id));
$contents[] = array('text' => '<br>' . TEXT_INFO_COUNTRY_ACTIVE . '<br>' . zen_draw_checkbox_field('countries_active', $cInfo->countries_active, $cInfo->countries_active));
$contents[] = array('align' => 'center', 'text' => '<br>' . zen_image_submit('button_update.gif', IMAGE_UPDATE) . ' <a href="' . zen_href_link(FILENAME_COUNTRIES, 'page=' . $_GET['page'] . '&cID=' . $cInfo->countries_id) . '">' . zen_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
break;
case 'delete':
$heading[] = array('text' => '<b>' . TEXT_INFO_HEADING_DELETE_COUNTRY . '</b>');
$contents = array('form' => zen_draw_form('countries', FILENAME_COUNTRIES, 'page=' . $_GET['page'] . '&action=deleteconfirm') . zen_draw_hidden_field('cID', $cInfo->countries_id));
$contents[] = array('text' => TEXT_INFO_DELETE_INTRO);
$contents[] = array('text' => '<br><b>' . $cInfo->countries_name . '</b>');
$contents[] = array('align' => 'center', 'text' => '<br>' . zen_image_submit('button_delete.gif', IMAGE_UPDATE) . ' <a href="' . zen_href_link(FILENAME_COUNTRIES, 'page=' . $_GET['page'] . '&cID=' . $cInfo->countries_id) . '">' . zen_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
break;
default:
if (is_object($cInfo)) {
$heading[] = array('text' => '<b>' . $cInfo->countries_name . '</b>');
$contents[] = array('align' => 'center', 'text' => '<a href="' . zen_href_link(FILENAME_COUNTRIES, 'page=' . $_GET['page'] . '&cID=' . $cInfo->countries_id . '&action=edit') . '">' . zen_image_button('button_edit.gif', IMAGE_EDIT) . '</a> <a href="' . zen_href_link(FILENAME_COUNTRIES, 'page=' . $_GET['page'] . '&cID=' . $cInfo->countries_id . '&action=delete') . '">' . zen_image_button('button_delete.gif', IMAGE_DELETE) . '</a>');
$contents[] = array('text' => '<br>' . TEXT_INFO_COUNTRY_NAME . '<br>' . $cInfo->countries_name);
$contents[] = array('text' => '<br>' . TEXT_INFO_COUNTRY_CODE_2 . ' ' . $cInfo->countries_iso_code_2);
$contents[] = array('text' => '<br>' . TEXT_INFO_COUNTRY_CODE_3 . ' ' . $cInfo->countries_iso_code_3);
$contents[] = array('text' => '<br>' . TEXT_INFO_ADDRESS_FORMAT . ' ' . $cInfo->address_format_id);
$contents[] = array('text' => '<br>' . TEXT_INFO_COUNTRY_ACTIVE . '<br>' . zen_draw_checkbox_field('countries_active', '', $cInfo->countries_active));
}
break;
}