Post by andrixx » Tue Jun 21, 2011 11:23 pm

Hi,
I have been struggeling with this quite some time now.

I live in Sweden and we have no use for Zone/Region/State, but in Opencart you need it for shipping, tax and other extensions and modules to work.

I have read this thread http://forum.opencart.com/viewtopic.php?f=20&t=25808 and this one http://forum.opencart.com/viewtopic.php?t=8349

But I don't get it to work properly. And in 1.5 I cant find this file: controller/account/create.php

I made it to a point where it automaticly select a Zone if you have country set to Sweden, but I need it to hide aswell!

From this point I started to get error messages.


If someone could make a nice and clear description for this for opencart 1.5 it would be great!
Also, is there no reason to add some features in the coming updates that can make you choose what information you need from people signing up or using the guest checkout.

I know many people want to remove many fields and some people want to make fields not required to fill out.
Last edited by i2Paq on Wed Jun 22, 2011 12:03 am, edited 1 time in total.
Reason: Use [version] TAG in subject!

New member

Posts

Joined
Sat Jun 18, 2011 7:23 pm

Post by Goffer » Thu Jun 23, 2011 9:58 pm

Indeed, This should be an option in the backend GUI.
But would appreciate a guide to removing some of the standard fields.

Newbie

Posts

Joined
Sun Jun 19, 2011 3:28 pm

Post by gfors » Wed Jul 13, 2011 3:37 pm

This worked for me in 1.5, it's quite quick and easy. You need to modify both controller files and view files for three different scenarios;

1. Guest checkout
2. Account creation during checkout
3. Account creation without checkout (also when editing address in account page)

To remove from guest checkout:

In /catalog/controller/checkout/guest.php

Find (should be around line 58)

Code: Select all

if ($this->request->post['zone_id'] == '') {
	$json['error']['zone'] = $this->language->get('error_zone');
}
and either comment that out or delete.


In /catalog/view/theme/YOURTHEME/template/checkout/guest.tpl

Find (should be around line 59)

Code: Select all

<span class="required">*</span> <?php echo $entry_zone; ?><br />
<select name="zone_id" class="large-field">
</select>
and either comment that out or delete.


In /catalog/view/theme/YOURTHEME/template/checkout/guest_shipping.tpl

Find (should be around line 43)

Code: Select all

<tr>
    <td><span class="required">*</span> <?php echo $entry_zone; ?></td>
    <td><select name="zone_id" class="large-field">
    </select></td>
</tr>
and either comment that out or delete. And add the following in that spot:

Code: Select all

<input type="hidden" name="zone_id" value="0" />

To remove from account creation during checkout:

In /catalog/controller/checkout/register.php

Find (should be around line 60)

Code: Select all

if ($this->request->post['zone_id'] == '') {
	$json['error']['zone'] = $this->language->get('error_zone');
}
and either comment that out or delete.


In /catalog/controller/checkout/address.php

Find two instances of (should be around line 62 AND line 192)

Code: Select all

if ($this->request->post['zone_id'] == '') {
	$json['error']['zone'] = $this->language->get('error_zone');
}
and either comment that out or delete.


In /catalog/view/theme/YOURTHEME/template/checkout/register.tpl

Find (should be around line 69)

Code: Select all

<span class="required">*</span> <?php echo $entry_zone; ?><br />
<select name="zone_id" class="large-field">
</select>
and either comment that out or delete.


In /catalog/view/theme/YOURTHEME/template/checkout/address.tpl

Find (should be around line 63)

Code: Select all

<tr>
    <td><span class="required">*</span> <?php echo $entry_zone; ?></td>
    <td><select name="zone_id" class="large-field">
    </select></td>
</tr>
and either comment that out or delete. And add the following in that spot:

Code: Select all

<input type="hidden" name="zone_id" value="0" />

To remove from account creation without checkout:

In /catalog/controller/account/register.php

Find (should be around line 322)

Code: Select all

if ($this->request->post['zone_id'] == '') {
	$this->error['zone'] = $this->language->get('error_zone');
}
and either comment that out or delete.


In /catalog/controller/account/address.php

Find (should be around line 466)

Code: Select all

if ($this->request->post['zone_id'] == '') {
	$this->error['zone'] = $this->language->get('error_zone');
}
and either comment that out or delete.


In /catalog/view/theme/YOURTHEME/template/account/register.tpl

Find (should be around line 99)

Code: Select all

<tr>
<td><span class="required">*</span> <?php echo $entry_zone; ?></td>
<td><select name="zone_id">
</select>
<?php if ($error_zone) { ?>
<span class="error"><?php echo $error_zone; ?></span>
<?php } ?></td>
</tr>
and either comment that out or delete. And add the following in that spot:

Code: Select all

<input type="hidden" name="zone_id" value="0" />

In /catalog/view/theme/YOURTHEME/template/account/address_form.tpl

Find (should be around line 72)

Code: Select all

<tr>
<td><span class="required">*</span> <?php echo $entry_zone; ?></td>
<td><select name="zone_id">
</select>
<?php if ($error_zone) { ?>
<span class="error"><?php echo $error_zone; ?></span>
<?php } ?></td>
</tr>
and either comment that out or delete. And add the following in that spot:

Code: Select all

<input type="hidden" name="zone_id" value="0" />
That should do it! I apologize for the long post, but I wanted to make it clear so that everyone can follow along. Give me a shout if I missed something!

Newbie

Posts

Joined
Wed Jul 13, 2011 3:05 pm

Post by andrixx » Sat Jul 16, 2011 11:52 pm

Thanks alot, it sounds like it will work! I will try it when my theme update to 1.5

Thumbs up and thanks again!

New member

Posts

Joined
Sat Jun 18, 2011 7:23 pm

Post by fsit » Thu Jul 28, 2011 1:52 am

Thanks! It seems to work, going to test it once more.
Probably catalog\view\Theme\YOUR THEME\template\total\shipping.tpl can use this magic as well. It's the shipping estimator:

Around line 19 this code:

Code: Select all

      <tr>
        <td><span class="required">*</span> <?php echo $entry_zone; ?></td>
        <td><select name="zone_id">
          </select></td>
      </tr>
replaced by:

Code: Select all

<input type="hidden" name="zone_id" value="0" />

New member

Posts

Joined
Mon Jul 25, 2011 12:44 am

Post by Goffer » Wed Aug 10, 2011 6:57 pm

Finally!
A working solution that i could do O0
But, it stills says Region/State when in checkout, and you choose not to use an existing address, or did i skip something in the tutorial?

Newbie

Posts

Joined
Sun Jun 19, 2011 3:28 pm

Post by andrixx » Thu Aug 11, 2011 3:31 am

I can't get it to work, I use a custom theme and my .tpl don't look like the original.

This is the code related to country/zone in my /checkout/guest.tpl

Code: Select all

      
      <div class="s_row_2 clearfix">
        <label><?php echo $entry_zone; ?> *</label>
        <select id="zone_id" name="zone_id" class="required"></select>
      </div>
If I just remove the code that makes the Zone field it don't shows when a guest checks out, but when I klick continue in the checkout process to get to delivery info it just stops.

I think the code I removed just removes the javascript requirement of Zone(maybe theme related), so I don't get an error message. But something else prevents the field to be accepted.

New member

Posts

Joined
Sat Jun 18, 2011 7:23 pm

Post by andrixx » Fri Aug 12, 2011 6:26 am

Hi again, I think I solved the problem, I just need to test it and edit all the template files.

I simply put

Code: Select all

style="display:none;"
inside the select tag for the Zone. And removed the text before it.

Original "Zone code" in template file:

Code: Select all

      <div class="s_row_2 clearfix">
        <label><?php echo $entry_zone; ?> *</label>
        <select id="zone_id" name="zone_id" class="required"></select>
      </div>
edited to:

Code: Select all

      <div class="s_row_2 clearfix">
        <select style="display:none;" id="zone_id" name="zone_id"></select>
      </div>
I have seen other teplates/themes with the exact same codes for zones, so I hope this will help others... if it works! :P

Now, as a rookie on coding I pray this will work.

New member

Posts

Joined
Sat Jun 18, 2011 7:23 pm

Post by andrixx » Fri Aug 12, 2011 7:39 am

Goffer wrote:Finally!
A working solution that i could do O0
But, it stills says Region/State when in checkout, and you choose not to use an existing address, or did i skip something in the tutorial?

I got the same thing, but I used AstroGrep and searched for this code in a localy stored bakup of my site.

Code: Select all

			if ($this->request->post['zone_id'] == '') {
				$json['error']['zone'] = $this->language->get('error_zone');
			}	


Found that it still remained in
catalog/controller/checkout/adress.php
catalog/controller/checkout/guest.php
catalog/controller/total/shipping.php

now I don't get any error messages and no Zone appear anywhere... so far ;)

New member

Posts

Joined
Sat Jun 18, 2011 7:23 pm

Post by zippen » Tue Oct 11, 2011 9:15 pm

Thank you all for this solution. Was a great help.

I didn't want to rewrite the source code so I made the above corrections into a vqmod file. It is the first time i tried to make a vqmod file so please let me know if you have any problems with it.

Remember to replace YOURTHEME with the name of your template.

Good luck with it!

UPDATE
I tested it with Opencart v1.5.1.3. It seems to work if you register an account. But it doesnt work on guest checkout as you cant get any further when you push the continue button. As far as I have found out, it is because the zone is set to --- Please select --- and not the prefered zone.

If somebody can come up with a solution to set the zone to a default area insteadt of --- please select --- then it should work.

I have tried to figure this one out but I am not a programmer. So any help on this will be appreciated :)

Attachments

Remove state/region vqmod

Last edited by zippen on Wed Oct 12, 2011 5:17 pm, edited 2 times in total.

Newbie

Posts

Joined
Tue Oct 11, 2011 9:09 pm

Post by andrixx » Tue Oct 11, 2011 11:33 pm

Great that you made a vqmod file! I will try it the next time I make a new store. :)

for what version of Opencart has this been tested?

New member

Posts

Joined
Sat Jun 18, 2011 7:23 pm

Post by JonnyWee » Tue Oct 25, 2011 6:20 am

Here is a solution that works for all countries, with 1.5.1. The basic idea:

1) Remove all zones from a country, except one (in Configuration > International > Zones). Give the remaining zone the same name as the country (already proposed earlier in this thread).
2) Add the following behaviour to the views: When there is only one zone, select it automatically and hide the selector. Because of the auto-select, it will pass the required field checks. And because only the views are modified (ie: your browser behaviour), you can be pretty sure the zone stuff in the backend keeps working fine.

Step 1: Add a callback to the zone loading routines.
1) Find text /zone&country_id= in the files listed below
2) Every file has two matching lines. On both lines, replace the text '); with ', afterZoneLoad);

List of files that should be edited (from the /view/theme/default directory):
  • template\account\address_form.tpl
    template\account\register.tpl
    template\affiliate\edit.tpl
    template\affiliate\register.tpl
    template\checkout\address.tpl
    template\checkout\guest.tpl
    template\checkout\guest_shipping.tpl
    template\checkout\register.tpl
    template\total\shipping.tpl
Example
You should have 18 lines changed. Example of a single change:

Line before change:

Code: Select all

<td><select name="country_id" onchange="$('select[name=\'zone_id\']').load('index.php? route=account/address/zone&country_id=' + this.value + '&zone_id=<?php echo $zone_id; ?>');">
Same line after change (look for text 'afterZoneLoad' at the end of the line):

Code: Select all

<td><select name="country_id" onchange="$('select[name=\'zone_id\']').load('index.php?route=account/address/zone&country_id=' + this.value + '&zone_id=<?php echo $zone_id; ?>', afterZoneLoad);">
Step 2: Add the callback function to /catalog/view/javascript/common.js:
1) Go to the end of the file and paste the following code:

Code: Select all

function afterZoneLoad() {
	if ($('select[name=zone_id] option').size() == 2) {
		$('select[name=zone_id] :nth-child(2)').attr('selected', 'selected')
		$('select[name=zone_id]').parent().parent().css('display', 'none');
	} else {
		$('select[name=zone_id]').parent().parent().css('display', '');
	}
}
Step 3: Double-wrap two odd zone selectors in a span tag to enable hiding:
1) Replace the following text in the files listed at the end of this step:

Code: Select all

  <br />
  <br />
  <span class="required">*</span> <?php echo $entry_zone; ?><br />
  <select name="zone_id" class="large-field">
  </select>
With this text (to just wrap it in <span><span>...</span></span>):

Code: Select all

  <span><span>
    <br />
    <br />
    <span class="required">*</span> <?php echo $entry_zone; ?><br />
    <select name="zone_id" class="large-field">
    </select>
  </span></span>
List of files that should be edited (from the /view/theme/default directory):
  • template\checkout\guest.tpl
    template\checkout\register.tpl
That's it. When there is a single zone anywhere, that zone will be selected and the selector will hide. When you select a country with multiple zones, the selector will pop up again.

DISCLAIMER: Use at your own risk. I've tested it in a custom theme and wrote the manual for the default theme, so it may not be a perfect reflection of my changes. My solution does not run on a live site yet. But hey, it's free ;)

Newbie

Posts

Joined
Tue Oct 25, 2011 5:55 am

Post by andrixx » Tue Oct 25, 2011 5:14 pm

NNice work, I will try that in a few days when I make a shop with no zones. But its a custom theme with diffrent codings in the .tpl-files so we'll see how i'll manage :)

Thanks for posting!

New member

Posts

Joined
Sat Jun 18, 2011 7:23 pm

Post by chrsdlmn » Tue Oct 25, 2011 11:46 pm

Re: [1.5]Hide/remove/defult predefined Region/State

Postby andrixx » Thu Aug 11, 2011 10:26 pm
Hi again, I think I solved the problem, I just need to test it and edit all the template files.

I simply put

Code: Select all
style="display:none;"

inside the select tag for the Zone. And removed the text before it.

Original "Zone code" in template file:

Code: Select all
<div class="s_row_2 clearfix">
<label><?php echo $entry_zone; ?> *</label>
<select id="zone_id" name="zone_id" class="required"></select>
</div>



edited to:

Code: Select all
<div class="s_row_2 clearfix">
<select style="display:none;" id="zone_id" name="zone_id"></select>
</div>



I have seen other teplates/themes with the exact same codes for zones, so I hope this will help others... if it works! :P

Now, as a rookie on coding I pray this will work.
THANK YOU!!! I've been trying for a very long time before finally finding your post. I'm going to need to remember this style="display:none;" :)

Newbie

Posts

Joined
Tue Oct 25, 2011 4:18 am

Post by andrixx » Tue Oct 25, 2011 11:57 pm

THANK YOU!!! I've been trying for a very long time before finally finding your post. I'm going to need to remember this style="display:none;"
Cheers!

New member

Posts

Joined
Sat Jun 18, 2011 7:23 pm

Post by andrixx » Wed Oct 26, 2011 3:57 pm

JonnyWee wrote:Here is a solution that works for all countries, with 1.5.1. The basic idea:
...
I tried your way but it wont work for me. When I selected guest at the checkout process it won't go to the next step. I bet its my custom theme thats messing with me.

I returned to my old method but used the VQMOD file that Zippen made. With a bit tweak. As I said, I used a custom theme so I removed all the lines that are related to the theme .tpl fiels from the vqmod-file.

Then I edited my .tpl manually.

So for you who want to edit the core with the vqmod-file and manually change the template files of your custom theme. Here is what I did.

1. First add this modifed vqmod-file: 2. Grab the following template files:
  • catalog/view/theme/YOURTHEME/template/checkout/guest.tpl
    catalog/view/theme/YOURTHEME/template/checkout/guest_shipping.tpl
    catalog/view/theme/YOURTHEME/template/checkout/register.tpl
    catalog/view/theme/YOURTHEME/template/checkout/address.tpl
    catalog/view/theme/YOURTHEME/template/account/register.tpl
    catalog/view/theme/YOURTHEME/template/account/address_form.tpl
    catalog/view/theme/YOURTHEME/template/total/shipping.tpl
Find your custom code that may not look like mine:

Code: Select all

      <div class="s_row_2 clearfix">
        <label><?php echo $entry_zone; ?> *</label>
        <select id="zone_id" name="zone_id" class="required"></select>
      </div>
Edit and add

Code: Select all

style="display:none;"
:

Code: Select all

   <div class="s_row_2 clearfix">
        <select id="zone_id" name="zone_id" style="display:none;"></select>
      </div>
Now repeat this manual editing on the rest of the files.
That should be it. :)

New member

Posts

Joined
Sat Jun 18, 2011 7:23 pm

Post by andrixx » Wed Oct 26, 2011 7:52 pm

I get the same error as Zippen. When I am at guest checkout it say "This field is required."

EDIT:
I changed back to the default theme and it worked. So it's theme related. Then I found the problem in:
view/theme/YOURTHEME/template/checkout/guest.tpl

where I before added

Code: Select all

style="display:none;"
there was a

Code: Select all

class="required"
::)


so Zippen, I hope this one works for you too :)

New member

Posts

Joined
Sat Jun 18, 2011 7:23 pm

Post by Jaro » Thu Nov 24, 2011 10:56 pm

Thanks, this was very helpful. I have one small addition. The remove_region_state.xml of Zippen only worked for me (also for guest checkout) after I changed line 11 in this file to:

Code: Select all

<add><![CDATA[$this->request->post['zone_id'] = ''; /*if ($this->request->post['zone_id'] == '') {
Probable cause (by deduction): because the 'zone_id' is not in the post, not having a 'zone_id' in the post-array will lead to an error further down the code of guest.php.

Newbie

Posts

Joined
Thu Nov 24, 2011 10:42 pm

Post by Gjald » Tue Apr 03, 2012 9:34 pm

Hi i am also struggling with this, so far i installed the VQmod of andrixx, and did Jaro's edit of line 11

Then i got to step 2 and realized my theme was quite different in coding so before i f**k too much up, I would appreciate if someone would take a glimpse at the coding ;-)

Code: Select all

    <td><span class="required">*</span> <?php echo $entry_zone; ?></td>
    <td><select name="zone_id" class="large-field">
      </select></td>
  </tr>
</table>
<br />
<div class="buttons">
  <div class="right"><a id="button-guest-shipping" class="button"><span><?php echo $button_continue; ?></span></a></div>
</div>
<script type="text/javascript"><!--
$('#shipping-address select[name=\'zone_id\']').load('index.php?route=checkout/address/zone&country_id=<?php echo $country_id; ?>&zone_id=<?php echo $zone_id; ?>');
//--></script> 
Should i still just


Add

Code: Select all

style="display:none;"
Remove

Code: Select all

class="required"
Thanks alot in advance ;-)

Newbie

Posts

Joined
Thu Feb 02, 2012 7:11 pm

Post by andrixx » Wed Apr 04, 2012 12:17 am

I am not sure but it looks like you still need to remove the code that makes the field required. And then also add the display none.

at this code (taken from your template)

Code: Select all

<td><span class="required">*</span> <?php echo $entry_zone; ?></td>
    <td><select name="zone_id" class="large-field">
      </select></td>
try remove the first part and edit the rest so the whole part looks like this:

Code: Select all

<td><select style="display:none;" name="zone_id" class="large-field">
      </select></td>

New member

Posts

Joined
Sat Jun 18, 2011 7:23 pm
Who is online

Users browsing this forum: No registered users and 27 guests