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:
$countries = "select countries_id, countries_name
from " . TABLE_COUNTRIES . "
where countries_active > '0'
order by countries_name";
Next I added a constant to admin/includes/languages/countries.php :
define('TEXT_INFO_COUNTRY_ACTIVE', 'Ship to Country?');
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):
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;
Note the added lines:
$countries_active = zen_db_prepare_input($_POST['countries_active']);
'countries_active = '" .(zen_db_input($countries_active) > '' ? 1 : 0) . "'
Then I made changes to the bottom part of the file that displays and allows for editing within the admin screen:
Note the lines added for 'countries_active'
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;
}
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.