Page 1 of 1

United States Only

Posted: Fri Jul 25, 2008 3:55 am
by jimmywb
Is there a way to only accept orders from within the United States and display a message to everyone else to contact us?

Re: United States Only

Posted: Fri Jul 25, 2008 8:58 am
by Luvz2drv
sure - setup your zones for payment and shipping
they will not be able to check out period

then in your cart/check logic toss a check in to make sure that the zone they are in by your pick of billing/shipping address check or both as to weather they can move forward

Jonathon

Re: United States Only

Posted: Fri Jul 25, 2008 9:35 am
by fido-x
Since placing an order requires registration, a logical place to put this kind of thing would be in the account creation stage.

This can be done by adding the following to your "catalog/controller/account_create.php" file:-

Code: Select all

if ($request->get('country_id', 'post') != 223) {
	$this->error['country_id'] = $language->get('error_country');
}

before

Code: Select all

if (!$this->error) {
  return TRUE;
} else {
  return FALSE;
}
Then add the following to your "catalog/language/english/account_create.php" file:-

Code: Select all

$_['error_country'] = 'Since you are from outside the USA, you must place your order through the contact page. Apologies for any inconvenience this may cause.';
And then alter your "catalog/template/default/content/account_create.tpl" as follows:-
Find the section

Code: Select all

<td><select name="country_id" onchange="$('#zone').load('index.php?controller=account_create&action=zone&country_id='+this.value+'&zone_id=<?php echo $zone_id; ?>');">
  <?php foreach ($countries as $country) { ?>
  <?php if ($country['country_id'] == $country_id) { ?>
  <option value="<?php echo $country['country_id']; ?>" SELECTED><?php echo $country['name']; ?></option>
  <?php } else { ?>
  <option value="<?php echo $country['country_id']; ?>"><?php echo $country['name']; ?></option>
  <?php } ?>
  <?php } ?>
  </select></td>
and change the last line to read:-

Code: Select all

</select><?php if ($error_country) { ?><span class="error"><?php echo $error_country; ?></span><?php } ?></td>
If your customer is not from the USA, this would then display an error message under the entry for "Country".

Regards, Fido-X.

Re: United States Only

Posted: Tue Jul 29, 2008 1:17 am
by jimmywb
Excellent!  Thanks for the replies!

Re: United States Only

Posted: Tue Jul 29, 2008 10:00 pm
by Luvz2drv
yes that works

but if smarty customers get in with fake USA address

you will also want a check on your billing/shipping in the check out as a failsafe

Jonathon

Re: United States Only

Posted: Thu Jul 31, 2008 7:25 pm
by fido-x
Good point. But unless the fake address belongs to someone that they know, how would they get anything shipped to them?

Fido-X.

Re: United States Only

Posted: Fri Aug 22, 2008 9:00 am
by Geek
fido-x wrote: This can be done by adding the following to your "catalog/controller/account_create.php" file:-

Code: Select all

if ($request->get('country_id', 'post') != 223) {
	$this->error['country_id'] = $language->get('error_country');
}

before

Code: Select all

if (!$this->error) {
  return TRUE;
} else {
  return FALSE;
}
This might sound like a stupid question or even a really simple one. But, if I wanted to include more than one country, would I do either

Code: Select all

if ($request->get('country_id', 'post') != 38 or 223 ) {
	$this->error['country_id'] = $language->get('error_country');
}
or

Code: Select all

if ($request->get('country_id', 'post') != 38 || 223) {
	$this->error['country_id'] = $language->get('error_country');
}
or

Code: Select all

if ($request->get('country_id', 'post') != 38 xor 223) {
	$this->error['country_id'] = $language->get('error_country');
}
Just trying to find out which is the best and/or proper way of doing this.

Re: United States Only

Posted: Fri Aug 22, 2008 9:04 am
by Qphoria
Couldn't you just delete all countries from the db except for the ones you want. Then the drop down would limit u

Re: United States Only

Posted: Fri Aug 22, 2008 9:08 am
by fido-x
Hi TekRaj,

You could do it using the "if" method as you suggested, the correct code would be-

Code: Select all

if ($request->get('country_id') != 38 || $request->get('country_id') != 223) {
  $this->error['country_id'] = $language->get('error_country');
}
Regards, Fido-X.

Re: United States Only

Posted: Fri Aug 22, 2008 10:33 am
by Geek
Qphoria wrote: Couldn't you just delete all countries from the db except for the ones you want. Then the drop down would limit u
Yes, but I plan to implement as many countries into my store as possible, once I work out the international shipping costs and everything.
That might be something that jimmywb might be wanting to do eventually as well. As long as they are all there, why delete them when if
you plan and idea is like what I would like to do or that you plan to eventually use them in some way.
fido-x wrote: Hi TekRaj,

You could do it using the "if" method as you suggested, the correct code would be-

Code: Select all

if ($request->get('country_id') != 38 || $request->get('country_id') != 223) {
  $this->error['country_id'] = $language->get('error_country');
}
Regards, Fido-X.
Thanks for the correction for me. I appreciate the help.

:)

Re: United States Only

Posted: Fri Aug 22, 2008 10:44 am
by Qphoria
Well the thread is titled "United states only" :P
Still, perhaps a way of disable/enable would be useful or something. Ah whatever works :)

Re: United States Only

Posted: Sat Aug 23, 2008 5:38 am
by Geek
I implemented this 'hack' and everything seems fine. But I keep getting an error code on the
account creation page. The error that I receive is "
Notice: Undefined variable: error_country in .../catalog/template/default/content/account_create.tpl on line 87"
right under the country select box.

My code looks like this:

Code: Select all

          
          ');">
              
              
              " SELECTED>
              
              ">
              
              
            
Line 87->     
              
              

Code: Select all

    	if ($request->get('country_id') != 38 || $request->get('country_id') != 223) {
          $this->error['country_id'] = $language->get('error_country');
      }

Code: Select all

    	$_['error_country']        = 'Since you are from outside the USA, you must place your order through the contact page. Apologies for any inconvenience this may cause.';
The error does not go away when United States or Canada is selected. Any input would be appreciated.

Re: United States Only

Posted: Sat Aug 23, 2008 8:46 am
by fido-x
You could try changing your line 87 from

Code: Select all

<?php if ($error_country) { ?>
to

Code: Select all

<?php if (isset($error_country) { ?>
Regards, Fido-X.

Re: United States Only

Posted: Sat Aug 23, 2008 3:09 pm
by Geek
fido-x wrote: You could try changing your line 87 from

Code: Select all

<?php if ($error_country) { ?>
to

Code: Select all

<?php if (isset($error_country) { ?>
Regards, Fido-X.
Well, that cleared up the undefined variable error, but the country error does not show if 38 or 223 is not selected.

Edit:
Problem solved.

In order to fix the error, you have to add:

Code: Select all

$view->set('error_city', @$this->error['city']);
after:

Code: Select all

$view->set('error_country', @$this->error['country']);
The problem was is that the variable, '$error_country' was not being viewed by the '../catalog/controller/account_create.php' file from the '../catalog/language/english/controller/account_create.php' file. Thanks Fido-X for telling me about 'isset', even though it didn't fix my problem, it lead to to understand why I was having the problem. Haha, I bet that you were just trying to lead me in the right direction instead of telling me the answer straight up. Thanks again.

Then you have to change your code further on down the page. So, instead of

Code: Select all

    	if ($request->get('country_id') != 38 || $request->get('country_id') != 223) {
          $this->error['country_id'] = $language->get('error_country');
      }
You need to replace it with:

Code: Select all

    	if ($request->get('country') != 38 || $request->get('country') != 223) {
          $this->error['country'] = $language->get('error_country');
      }
Now, I just have to get it to accept just the 38 and 223. Whenever I select Canada or United States and click the submit button, it stays on the page and leaves the error message up there.