Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Easy Country pre Selection


paulm2003

Recommended Posts

(for osC2.2 MS2 don't know about other versions)

 

To make the country selection easyer for costumers of a certain country, i got the following tip on osCommerce.nl . I read a lot of confusing posts about this, so I decided to post this simple safe and efficient solution as a tip.

 

It makes your favorite country selected when people want to create an account, so they wont have to scroll though 239 countries to find it!

 

 

In catalog/create_account.php

change:

 

tep_get_country_list('country')

to

tep_get_country_list('country', '150')

change 150 (Netherlands) to 222 for UK or to 223 for US etc etc

 

You can do the same for (if people want to change address at checkout):

catalog/includes/modules/checkout_new_address.php

 

 

If you use the standard osC country list, this are the country codes:

 

1 "Afghanistan"

2 "Albania"

3 "Algeria"

4 "American Samoa"

5 "Andorra"

6 "Angola"

7 "Anguilla"

8 "Antarctica"

9 "Antigua and Barbuda"

10 "Argentina"

11 "Armenia"

12 "Aruba"

13 "Australia"

14 "Austria"

15 "Azerbaijan"

16 "Bahamas"

17 "Bahrain"

18 "Bangladesh"

19 "Barbados"

20 "Belarus"

21 "Belgium"

22 "Belize"

23 "Benin"

24 "Bermuda"

25 "Bhutan"

26 "Bolivia"

27 "Bosnia and Herzegowina"

28 "Botswana"

29 "Bouvet Island"

30 "Brazil"

31 "British Indian Ocean Territory"

32 "Brunei Darussalam"

33 "Bulgaria"

34 "Burkina Faso"

35 "Burundi"

36 "Cambodia"

37 "Cameroon"

38 "Canada"

39 "Cape Verde"

40 "Cayman Islands"

41 "Central African Republic"

42 "Chad"

43 "Chile"

44 "China"

45 "Christmas Island"

46 "Cocos (Keeling) Islands"

47 "Colombia"

48 "Comoros"

49 "Congo"

50 "Cook Islands"

51 "Costa Rica"

52 "Cote D'Ivoire"

53 "Croatia"

54 "Cuba"

55 "Cyprus"

56 "Czech Republic"

57 "Denmark"

58 "Djibouti"

59 "Dominica"

60 "Dominican Republic"

61 "East Timor"

62 "Ecuador"

63 "Egypt"

64 "El Salvador"

65 "Equatorial Guinea"

66 "Eritrea"

67 "Estonia"

68 "Ethiopia"

69 "Falkland Islands (Malvinas)"

70 "Faroe Islands"

71 "Fiji"

72 "Finland"

73 "France"

74 "France, Metropolitan"

75 "French Guiana"

76 "French Polynesia"

77 "French Southern Territories"

78 "Gabon"

79 "Gambia"

80 "Georgia"

81 "Germany"

82 "Ghana"

83 "Gibraltar"

84 "Greece"

85 "Greenland"

86 "Grenada"

87 "Guadeloupe"

88 "Guam"

89 "Guatemala"

90 "Guinea"

91 "Guinea-bissau"

92 "Guyana"

93 "Haiti"

94 "Heard and Mc Donald Islands"

95 "Honduras"

96 "Hong Kong"

97 "Hungary"

98 "Iceland"

99 "India"

100 "Indonesia"

101 "Iran (Islamic Republic of)"

102 "Iraq"

103 "Ireland"

104 "Israel"

105 "Italy"

106 "Jamaica"

107 "Japan"

108 "Jordan"

109 "Kazakhstan"

110 "Kenya"

111 "Kiribati"

112 "Korea, Democratic People's Republic of"

113 "Korea, Republic of"

114 "Kuwait"

115 "Kyrgyzstan"

116 "Lao People's Democratic Republic"

117 "Latvia"

118 "Lebanon"

119 "Lesotho"

120 "Liberia"

121 "Libyan Arab Jamahiriya"

122 "Liechtenstein"

123 "Lithuania"

124 "Luxembourg"

125 "Macau"

126 "Macedonia, The Former Yugoslav Republic of"

127 "Madagascar"

128 "Malawi"

129 "Malaysia"

130 "Maldives"

131 "Mali"

132 "Malta"

133 "Marshall Islands"

134 "Martinique"

135 "Mauritania"

136 "Mauritius"

137 "Mayotte"

138 "Mexico"

139 "Micronesia, Federated States of"

140 "Moldova, Republic of"

141 "Monaco"

142 "Mongolia"

143 "Montserrat"

144 "Morocco"

145 "Mozambique"

146 "Myanmar"

147 "Namibia"

148 "Nauru"

149 "Nepal"

150 "Netherlands"

151 "Netherlands Antilles"

152 "New Caledonia"

153 "New Zealand"

154 "Nicaragua"

155 "Niger"

156 "Nigeria"

157 "Niue"

158 "Norfolk Island"

159 "Northern Mariana Islands"

160 "Norway"

161 "Oman"

162 "Pakistan"

163 "Palau"

164 "Panama"

165 "Papua New Guinea"

166 "Paraguay"

167 "Peru"

168 "Philippines"

169 "Pitcairn"

170 "Poland"

171 "Portugal"

172 "Puerto Rico"

173 "Qatar"

174 "Reunion"

175 "Romania"

176 "Russian Federation"

177 "Rwanda"

178 "Saint Kitts and Nevis"

179 "Saint Lucia"

180 "Saint Vincent and the Grenadines"

181 "Samoa"

182 "San Marino"

183 "Sao Tome and Principe"

184 "Saudi Arabia"

185 "Senegal"

186 "Seychelles"

187 "Sierra Leone"

188 "Singapore"

189 "Slovakia (Slovak Republic)"

190 "Slovenia"

191 "Solomon Islands"

192 "Somalia"

193 "South Africa"

194 "South Georgia and the South Sandwich Islands"

195 "Spain"

196 "Sri Lanka"

197 "St. Helena"

198 "St. Pierre and Miquelon"

199 "Sudan"

200 "Suriname"

201 "Svalbard and Jan Mayen Islands"

202 "Swaziland"

203 "Sweden"

204 "Switzerland"

205 "Syrian Arab Republic"

206 "Taiwan"

207 "Tajikistan"

208 "Tanzania, United Republic of"

209 "Thailand"

210 "Togo"

211 "Tokelau"

212 "Tonga"

213 "Trinidad and Tobago"

214 "Tunisia"

215 "Turkey"

216 "Turkmenistan"

217 "Turks and Caicos Islands"

218 "Tuvalu"

219 "Uganda"

220 "Ukraine"

221 "United Arab Emirates"

222 "United Kingdom"

223 "United States"

224 "United States Minor Outlying Islands"

225 "Uruguay"

226 "Uzbekistan"

227 "Vanuatu"

228 "Vatican City State (Holy See)"

229 "Venezuela"

230 "Viet Nam"

231 "Virgin Islands (British)"

232 "Virgin Islands (U.S.)"

233 "Wallis and Futuna Islands"

234 "Western Sahara"

235 "Yemen"

236 "Yugoslavia"

237 "Zaire"

238 "Zambia"

239 "Zimbabwe"

 

Paul

PS: look at http://www.televisiedokter.nl/catalog/create_account.php for a Dutch example.

Link to comment
Share on other sites

  • 2 weeks later...

nice one! while i'd eventually like to be able to move a group of countries to the top of the list (especially based upon the current language in use for the session), right now i'll settle for being americentric.

 

one thing, you might also want to change catalog/includes/modules/address_book_details.php, around line 120, from

            <td class="main"><?php echo tep_get_country_list('country', $entry['entry_country_id']) . ' ' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></td>

to

            <td class="main"><?php echo tep_get_country_list('country', ($entry['entry_country_id'] > 0) ? $entry['entry_country_id'] : '223') . ' ' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></td>

(replacing '223' with your favorite country code) so that you get the same functionality when people add additional address book entries.

Link to comment
Share on other sites

This could work as a combined contribution with mine with a common admin interface dont you think? See 'Favourite Countries' in this forum...
Sounds very good to me, since "my" part is very small, it would be best to add it to your contribution if you like.

 

one thing, you might also want to change catalog/includes/modules/address_book_details.php, around line 120
I did not know that. Thanks!

 

Paul

Link to comment
Share on other sites

  • 1 month later...
  • 2 years later...
  • 4 weeks later...

Paul,

 

Dude, you are my HERO!!! I have been looking for days getting more confused by the minute from posts with all sorts of complicated and poorly explained ways to do this...this post is EXACTLY what I was looking for...just AWESOME man!!! 10 seconds and done...BRILLIANT!!!

 

Cheers,

Travis

:thumbsup:

Link to comment
Share on other sites

  • 7 months later...

I am using oscommerce-2.2ms2-060817.

 

Hello Paul, your recommend works fine with catalog/create_account.php but i am afraid it's no so when applied in catalog/includes/modules/checkout_new_address.

 

I also tried another method as given by a reply to Paul's thread, i still couldn't make it happen.

Link to comment
Share on other sites

Ty for that deary :) I have been looking for a way to only accept new customers from the UK so building on from this I made a new error

 

define('WRONG_COUNTRY_ERROR', 'Sorry, but we are only posting to customers in the UK at the moment');

 

in includes/languages/english.php

 

and

 

}

 

if ($country != 222) {

$error= true;

$messageStack->add('create_account', WRONG_COUNTRY_ERROR);

 

in catalog/create_account.php

 

It turns out things really are pretty much the same in all programming languages :)

Link to comment
Share on other sites

  • 4 months later...

My client wanted his three top countries moved to the top of the country selected, the US, Canada, and the UK.

 

This is what I did:

 

in includes/functions/general.php

 

right after the country array is loaded from the db:

 

while ($countries_values = tep_db_fetch_array($countries)) {

$countries_array[] = array('countries_id' => $countries_values['countries_id'],

'countries_name' => $countries_values['countries_name']);

}

 

 

add the following code:

 

array_unshift($countries_array,

array('countries_id' => 223, 'countries_name' => "United States"),

array('countries_id' => 38, 'countries_name' => "Canada"),

array('countries_id' => 222, 'countries_name' => "United Kingdom"));

 

 

 

You can add as many as you like. This will add them to the top of the list, they will still appear redundantly in their alphabetic order. Since this is being done in the general function call, it should work anywhere on the site.

Link to comment
Share on other sites

  • 4 weeks later...

Works like a charm!

 

 

My client wanted his three top countries moved to the top of the country selected, the US, Canada, and the UK.

 

This is what I did:

 

in includes/functions/general.php

 

right after the country array is loaded from the db:

 

while ($countries_values = tep_db_fetch_array($countries)) {

$countries_array[] = array('countries_id' => $countries_values['countries_id'],

'countries_name' => $countries_values['countries_name']);

}

add the following code:

 

array_unshift($countries_array,

array('countries_id' => 223, 'countries_name' => "United States"),

array('countries_id' => 38, 'countries_name' => "Canada"),

array('countries_id' => 222, 'countries_name' => "United Kingdom"));

You can add as many as you like. This will add them to the top of the list, they will still appear redundantly in their alphabetic order. Since this is being done in the general function call, it should work anywhere on the site.

Link to comment
Share on other sites

  • 2 weeks later...

:o Customers have been getting an error message when attempting to order Company "Does not ship there."

On the drop down country list in my OS config it did not have United States it only had United States Outlying Islands? I changed the code to tep_get_country_list('country', '223') as directed by Paulm2003 but it still did not show up. Ended up adding the US to the list but only new 2 letter ISO code. Any suggestions as to why the US did not show up on list or what could be causing error? [email protected]

Link to comment
Share on other sites

  • 1 month later...
  • 7 months later...

Still does not working in checkout_shipping_address.php and checkout_payment_addres.php

 

when I clicked on change address seem that only the country is there but no states :(

 

does anyone can help me?

Link to comment
Share on other sites

(for osC2.2 MS2 don't know about other versions)

 

To make the country selection easyer for costumers of a certain country, i got the following tip on osCommerce.nl . I read a lot of confusing posts about this, so I decided to post this simple safe and efficient solution as a tip.

 

It makes your favorite country selected when people want to create an account, so they wont have to scroll though 239 countries to find it!

 

 

In catalog/create_account.php

change:

 

tep_get_country_list('country')

to

tep_get_country_list('country', '150')

change 150 (Netherlands) to 222 for UK or to 223 for US etc etc

 

You can do the same for (if people want to change address at checkout):

catalog/includes/modules/checkout_new_address.php

 

 

If you use the standard osC country list, this are the country codes:

 

<SNIPPED CODES>

 

Paul

PS: look at http://www.televisiedokter.nl/catalog/create_account.php for a Dutch example.

 

Just in case anyone is interested, the country list that ships with osC is incomplete. The complete, up to date list is available here:

http://www.iso.org/iso/english_country_nam...d_code_elements

* * * * * * * * * * * * * * * * * * * * *

Porpoises are most happy when wet!

\ _ \ _ \ _ \ _ \ _ \ _ \ _ \ _ \ _ \ _ \ _ \ _

Link to comment
Share on other sites

Just in case anyone is interested, the country list that ships with osC is incomplete. The complete, up to date list is available here:

http://www.iso.org/iso/english_country_nam...d_code_elements

 

Hi, from Brasil!

 

 

Get the list for import in database:

 

http://www.iso.org/iso/iso3166_en_code_lists.txt

 

Thanks for posts. (They were of great help!)

 

Aziz Guilherme

Link to comment
Share on other sites

This rocks!!! Thanks soooo much!!

 

My client wanted his three top countries moved to the top of the country selected, the US, Canada, and the UK.

 

This is what I did:

 

in includes/functions/general.php

 

right after the country array is loaded from the db:

 

while ($countries_values = tep_db_fetch_array($countries)) {

$countries_array[] = array('countries_id' => $countries_values['countries_id'],

'countries_name' => $countries_values['countries_name']);

}

 

 

add the following code:

 

array_unshift($countries_array,

array('countries_id' => 223, 'countries_name' => "United States"),

array('countries_id' => 38, 'countries_name' => "Canada"),

array('countries_id' => 222, 'countries_name' => "United Kingdom"));

 

 

 

You can add as many as you like. This will add them to the top of the list, they will still appear redundantly in their alphabetic order. Since this is being done in the general function call, it should work anywhere on the site.

Kyla

Rangeline Design

Michigan USA

Link to comment
Share on other sites

  • 3 weeks later...
  • 4 months later...
in includes/functions/general.php

 

right after the country array is loaded from the db:

 

while ($countries_values = tep_db_fetch_array($countries)) {

$countries_array[] = array('countries_id' => $countries_values['countries_id'],

'countries_name' => $countries_values['countries_name']);

}

 

 

add the following code:

 

array_unshift($countries_array,

array('countries_id' => 223, 'countries_name' => "United States"),

array('countries_id' => 38, 'countries_name' => "Canada"),

array('countries_id' => 222, 'countries_name' => "United Kingdom"));

 

Is it maybe possible that it looks like:

 

Please Select:

Untied States

Canada

United Kingdom

------------------

and after that the rest of the country list in alphabetic order?

 

I hope somebody can help me!

Link to comment
Share on other sites

Is it maybe possible that it looks like:

 

Please Select:

Untied States

Canada

United Kingdom

------------------

and after that the rest of the country list in alphabetic order?

 

I hope somebody can help me!

 

I got the same problem, and solved it.

I had to remove the countries listed at the the top in the alfabetical list otherwise the preselected country would be in the alfabetical list and not in the top preselected list.

 

in general.php find

 

while ($countries_values = tep_db_fetch_array($countries)) {

$cid=$countries_values['countries_id'];

$countries_array[] = array('countries_id' => $countries_values['countries_id'],

'countries_name' => $countries_values['countries_name']);

}

}

 

replace with:

 

while ($countries_values = tep_db_fetch_array($countries)) {

$cid=$countries_values['countries_id'];

if ($cid==14 || $cid==21 || $cid==57 || $cid==73 || $cid==81 || $cid==150 || $cid==160 || $cid==195 ||$cid==204 ||$cid==222 ){

// these country codes are not added to the alfabetical list

} else {

// add normally

$countries_array[] = array('countries_id' => $countries_values['countries_id'],

'countries_name' => $countries_values['countries_name']);

}

}

// add the items at the top of the list, end with a separator

array_unshift($countries_array,

array('countries_id' => 14, 'countries_name' => "Austria"),

array('countries_id' => 21, 'countries_name' => "Belgium"),

array('countries_id' => 57, 'countries_name' => "Denmark"),

array('countries_id' => 73, 'countries_name' => "France"),

array('countries_id' => 81, 'countries_name' => "Germany"),

array('countries_id' => 150, 'countries_name' => "Netherlands"),

array('countries_id' => 160, 'countries_name' => "Norway"),

array('countries_id' => 195, 'countries_name' => "Spain"),

array('countries_id' => 204, 'countries_name' => "Switzerland"),

array('countries_id' => 222, 'countries_name' => "United Kingdom"),

array('countries_id' => 0, 'countries_name' => "--------------")

 

);

 

Seems to work!

 

I combined this code with the preselection by browser as written in:

this link

 

Looks nice this way.. not tested on other forms, only create_account

Link to comment
Share on other sites

Thank you very much for your answer!

 

Now it looks like:

 

Please select:

Austria

Belgium

Denmark

Germany

----------

 

But "-------" is pre selectet instead of: "Please select:"

 

I could solve the problem by using the preselection by browser but because the preselection for AOL users from Germany would be USA, I can't use this.

 

Do you know what I maybe can do that "Please select" will be preselected on first place instead of ---------?

 

Thank you very much for your help!

Link to comment
Share on other sites

Thank you very much for your answer!

 

Now it looks like:

 

Please select:

Austria

Belgium

Denmark

Germany

----------

 

But "-------" is pre selectet instead of: "Please select:"

 

I could solve the problem by using the preselection by browser but because the preselection for AOL users from Germany would be USA, I can't use this.

 

Do you know what I maybe can do that "Please select" will be preselected on first place instead of ---------?

 

Thank you very much for your help!

 

It is because you have not combined it with the preselection based on browser, or at least it is not working.

I added "0" and "-------" so if the fucntion is called without coutry code it selects 0, thus "----" maybe fill the table with another country code that's not used. So "0" and "-------" replaced by "1" and "-------"

Link to comment
Share on other sites

  • 1 month later...
nice one! while i'd eventually like to be able to move a group of countries to the top of the list (especially based upon the current language in use for the session), right now i'll settle for being americentric.

 

one thing, you might also want to change catalog/includes/modules/address_book_details.php, around line 120, from

            <td class="main"><?php echo tep_get_country_list('country', $entry['entry_country_id']) . ' ' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></td>

to

            <td class="main"><?php echo tep_get_country_list('country', ($entry['entry_country_id'] > 0) ? $entry['entry_country_id'] : '223') . ' ' . (tep_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="inputRequirement">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?></td>

(replacing '223' with your favorite country code) so that you get the same functionality when people add additional address book entries.

 

 

 

You made a mistake in the code. The ")" should be removed after <td class="main"><?php echo tep_get_country_list('country', ($entry['entry_country_id'] > 0

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...