Community Forums

Default Region/State to None -- Singapore

Template support & advice for OpenCart v1.x

Default Region/State to None -- Singapore

Postby thegeekz » Fri Jun 15, 2012 9:08 am

Hi,

Is there any way to Default the Region/State to None when Singapore is chosen? So that my customers don't have to click on the dropdown box for the Region/State.

Edit:
In the Registration Forms -- Account / Checkout

So I guess also have to change the code in the Address file.



Thank you.

Regards

Faustine
Last edited by thegeekz on Mon Jun 18, 2012 2:55 am, edited 1 time in total.
Production Cart @ http://eshop.kgshop-sg.com -- OC 1.5.4.1 -- pending
No more using Apsona, as they are not updated.
    Every upgrade -- rem. 2 reinstall vqmod & mindful of modules w/ VQmod -- E.g Import / Export Tool by MHC
Test cart @ http://tshop.kgshop-sg.com -- pending -- still busy with friend's OC cart.
thegeekz
 
Posts: 326
Joined: Tue Nov 02, 2010 2:24 am

Re: Default Region/State to None -- Singapore

Postby MarketInSG » Fri Jun 15, 2012 2:27 pm

The default is selected for v1.5.3.1. Not sure what version you are running on, but the codes below is the correct one that ensures 'none' is selected by default.
Code: Select all
html += '<option value="0" selected="selected"><?php echo $text_none; ?></option>';
User avatar
MarketInSG
 
Posts: 2607
Joined: Wed Nov 16, 2011 3:53 am
Location: Singapore

Re: Default Region/State to None -- Singapore

Postby thegeekz » Fri Jun 15, 2012 2:46 pm

Thank you..

I'm using 1.5.2.1 though.. where can I find this code?

in register.tpl?
Production Cart @ http://eshop.kgshop-sg.com -- OC 1.5.4.1 -- pending
No more using Apsona, as they are not updated.
    Every upgrade -- rem. 2 reinstall vqmod & mindful of modules w/ VQmod -- E.g Import / Export Tool by MHC
Test cart @ http://tshop.kgshop-sg.com -- pending -- still busy with friend's OC cart.
thegeekz
 
Posts: 326
Joined: Tue Nov 02, 2010 2:24 am

Re: Default Region/State to None -- Singapore

Postby MarketInSG » Sat Jun 16, 2012 1:15 am

Ok, if you are on v1.5.2.1, they are different. You will have to access catalog/controller/account/register.php

Find
Code: Select all
$output .= '<option value="0">' . $this->language->get('text_none') . '</option>';


chnage to

Code: Select all
$output .= '<option selected="selected" value="0">' . $this->language->get('text_none') . '</option>';
User avatar
MarketInSG
 
Posts: 2607
Joined: Wed Nov 16, 2011 3:53 am
Location: Singapore

Re: Default Region/State to None -- Singapore

Postby thegeekz » Mon Jun 18, 2012 2:12 am

MarketInSG wrote:Ok, if you are on v1.5.2.1, they are different. You will have to access catalog/controller/account/register.php

Find
Code: Select all
$output .= '<option value="0">' . $this->language->get('text_none') . '</option>';


chnage to

Code: Select all
$output .= '<option selected="selected" value="0">' . $this->language->get('text_none') . '</option>';



Strange.. doesn't seem to work.. though... When using VQMOD..

** Currently the Registration form's Region / State -- have the default shown as Please Select, not the Text -- > None.. Customers will still have to select the None in drop down menu.

With this code change will the dropdown box show "None" directly, rather than needing to select the Region still?

I'll try updating the file directly..
Production Cart @ http://eshop.kgshop-sg.com -- OC 1.5.4.1 -- pending
No more using Apsona, as they are not updated.
    Every upgrade -- rem. 2 reinstall vqmod & mindful of modules w/ VQmod -- E.g Import / Export Tool by MHC
Test cart @ http://tshop.kgshop-sg.com -- pending -- still busy with friend's OC cart.
thegeekz
 
Posts: 326
Joined: Tue Nov 02, 2010 2:24 am

Re: Default Region/State to None -- Singapore

Postby thegeekz » Mon Jun 18, 2012 5:13 am

I read :

viewtopic.php?t=49232 -- Default Country, Default Zone

And followed the examples to the tee, but using VQMOD.

However doesn't seem to have any effect.

Shall attach the XML file here.... For help... :(

** I'm also trying to change the Post code text to Postal code using VQMOD, also doesn't seem to work.... (Language file)
Attachments
default_region_country.xml
(6.06 KiB) Downloaded 35 times
Production Cart @ http://eshop.kgshop-sg.com -- OC 1.5.4.1 -- pending
No more using Apsona, as they are not updated.
    Every upgrade -- rem. 2 reinstall vqmod & mindful of modules w/ VQmod -- E.g Import / Export Tool by MHC
Test cart @ http://tshop.kgshop-sg.com -- pending -- still busy with friend's OC cart.
thegeekz
 
Posts: 326
Joined: Tue Nov 02, 2010 2:24 am

Re: Default Region/State to None -- Singapore

Postby thegeekz » Fri Jun 22, 2012 2:11 am

Anyone?

Help?
Production Cart @ http://eshop.kgshop-sg.com -- OC 1.5.4.1 -- pending
No more using Apsona, as they are not updated.
    Every upgrade -- rem. 2 reinstall vqmod & mindful of modules w/ VQmod -- E.g Import / Export Tool by MHC
Test cart @ http://tshop.kgshop-sg.com -- pending -- still busy with friend's OC cart.
thegeekz
 
Posts: 326
Joined: Tue Nov 02, 2010 2:24 am

Re: Default Region/State to None -- Singapore

Postby MarketInSG » Fri Jun 22, 2012 5:28 am

it doesnt work because you don't know how to use vqmod. search for the whole line would be good. if you really dont get vqmod, you can just directly change the file.
User avatar
MarketInSG
 
Posts: 2607
Joined: Wed Nov 16, 2011 3:53 am
Location: Singapore

Re: Default Region/State to None -- Singapore

Postby thegeekz » Fri Jun 22, 2012 5:43 am

MarketinSG:

Ok, now actually I had set a SG None as the Zone, Zone ID 3968.

So I guess I should just change TPL files suggested in the Default Zone thread?

My Case is slightly different, I would like to maintain the Countries Listing while the Zone will default to SG None when Singapore is selected.

I see Kim's is only one country... one zone....

Is that possible?


thegeekz wrote:
MarketInSG wrote:Ok, if you are on v1.5.2.1, they are different. You will have to access catalog/controller/account/register.php

Find
Code: Select all
$output .= '<option value="0">' . $this->language->get('text_none') . '</option>';


chnage to

Code: Select all
$output .= '<option selected="selected" value="0">' . $this->language->get('text_none') . '</option>';



Strange.. doesn't seem to work.. though... When using VQMOD..

** Currently the Registration form's Region / State -- have the default shown as Please Select, not the Text -- > None.. Customers will still have to select the None in drop down menu.

With this code change will the dropdown box show "None" directly, rather than needing to select the Region still?

I'll try updating the file directly..
Production Cart @ http://eshop.kgshop-sg.com -- OC 1.5.4.1 -- pending
No more using Apsona, as they are not updated.
    Every upgrade -- rem. 2 reinstall vqmod & mindful of modules w/ VQmod -- E.g Import / Export Tool by MHC
Test cart @ http://tshop.kgshop-sg.com -- pending -- still busy with friend's OC cart.
thegeekz
 
Posts: 326
Joined: Tue Nov 02, 2010 2:24 am

Re: Default Region/State to None -- Singapore

Postby MarketInSG » Fri Jun 22, 2012 3:30 pm

don't really get you this time round. if you want to default zones that is 'none', just do as what I listed above. If you want zone with a specific id, you will need to edit template file

Code: Select all
<?php if (id = 'xxxx') { ?><option select="selected" ......><?php } else { ?>original codes <?php { ?>
User avatar
MarketInSG
 
Posts: 2607
Joined: Wed Nov 16, 2011 3:53 am
Location: Singapore

Re: Default Region/State to None -- Singapore

Postby thegeekz » Fri Jun 22, 2012 3:39 pm

MarketInSG wrote:don't really get you this time round. if you want to default zones that is 'none', just do as what I listed above. If you want zone with a specific id, you will need to edit template file

Code: Select all
<?php if (id = 'xxxx') { ?><option select="selected" ......><?php } else { ?>original codes <?php { ?>


OK. I try...

I wanted the customer to :

a) select Singapore from the list
b) don't have to select region - already defaulted to my set choice : SG NONE

I'll see if the above code works.

(As Kim's is only one country .. one zone... which is not what I want - so I can't follow that thread's solution)
Production Cart @ http://eshop.kgshop-sg.com -- OC 1.5.4.1 -- pending
No more using Apsona, as they are not updated.
    Every upgrade -- rem. 2 reinstall vqmod & mindful of modules w/ VQmod -- E.g Import / Export Tool by MHC
Test cart @ http://tshop.kgshop-sg.com -- pending -- still busy with friend's OC cart.
thegeekz
 
Posts: 326
Joined: Tue Nov 02, 2010 2:24 am

Re: Default Region/State to None -- Singapore

Postby MarketInSG » Sat Jun 23, 2012 3:21 am

MarketInSG wrote:Ok, if you are on v1.5.2.1, they are different. You will have to access catalog/controller/account/register.php

Find
Code: Select all
$output .= '<option value="0">' . $this->language->get('text_none') . '</option>';


chnage to

Code: Select all
$output .= '<option selected="selected" value="0">' . $this->language->get('text_none') . '</option>';


Use this will do. Nothing else you need to do. Remove the new zone you added to Singapore. That's not needed
User avatar
MarketInSG
 
Posts: 2607
Joined: Wed Nov 16, 2011 3:53 am
Location: Singapore

Re: Default Region/State to None -- Singapore

Postby thegeekz » Sat Jun 23, 2012 4:57 am

OK.

I tried that earlier but it didn't work..

still default to :

please select

Will try again later.

THANKS!
Production Cart @ http://eshop.kgshop-sg.com -- OC 1.5.4.1 -- pending
No more using Apsona, as they are not updated.
    Every upgrade -- rem. 2 reinstall vqmod & mindful of modules w/ VQmod -- E.g Import / Export Tool by MHC
Test cart @ http://tshop.kgshop-sg.com -- pending -- still busy with friend's OC cart.
thegeekz
 
Posts: 326
Joined: Tue Nov 02, 2010 2:24 am

Re: Default Region/State to None -- Singapore

Postby thegeekz » Mon Jun 25, 2012 7:20 am

Ok I tested with your suggestion earlier..

It didn't work out.

Still defaults to -- Please Select --

Still have to select the Zone!
Production Cart @ http://eshop.kgshop-sg.com -- OC 1.5.4.1 -- pending
No more using Apsona, as they are not updated.
    Every upgrade -- rem. 2 reinstall vqmod & mindful of modules w/ VQmod -- E.g Import / Export Tool by MHC
Test cart @ http://tshop.kgshop-sg.com -- pending -- still busy with friend's OC cart.
thegeekz
 
Posts: 326
Joined: Tue Nov 02, 2010 2:24 am

Re: Default Region/State to None -- Singapore

Postby MarketInSG » Mon Jun 25, 2012 12:58 pm

Well, then something is wrong with your cart. That is the piece of code that is responsible for outputting the option
User avatar
MarketInSG
 
Posts: 2607
Joined: Wed Nov 16, 2011 3:53 am
Location: Singapore

Re: Default Region/State to None -- Singapore

Postby thegeekz » Mon Jun 25, 2012 1:31 pm

ok.. Will try with my other installations and see how it turns out...

Afterall I'm using a custom theme -- Basico...
But shouldn't affect the basic functionality of the cart.

Edit : I just checked -- using Opera, and the Default to None works, but in Firefox it shows the - Please select - as default, but I suspect it also works just did not display correctly... Can anyone using Firefox confirm this?

Oc3.cybermind.com.sg - Register form
Production Cart @ http://eshop.kgshop-sg.com -- OC 1.5.4.1 -- pending
No more using Apsona, as they are not updated.
    Every upgrade -- rem. 2 reinstall vqmod & mindful of modules w/ VQmod -- E.g Import / Export Tool by MHC
Test cart @ http://tshop.kgshop-sg.com -- pending -- still busy with friend's OC cart.
thegeekz
 
Posts: 326
Joined: Tue Nov 02, 2010 2:24 am

Re: Default Region/State to None -- Singapore

Postby opencart-templates » Thu Jan 10, 2013 1:20 pm

Inside the Store Settings -> Local you are required to select the default "Region / State:"

If you dont want this to be set as default you need to add:
Code: Select all
($this->config->get('config_zone_id') != $result['zone_id'])


So vqmod file would look like this:
Code: Select all
<file name="catalog/controller/checkout/guest.php">
   <operation>
      <search position="replace"><![CDATA[
         if (isset($this->request->get['zone_id']) && ($this->request->get['zone_id'] == $result['zone_id'])) {
      ]]></search>
      <add><![CDATA[
         if (isset($this->request->get['zone_id']) && ($this->config->get('config_zone_id') != $result['zone_id']) && ($this->request->get['zone_id'] == $result['zone_id'])) {
      ]]></add>
   </operation>
</file>


The method suggested by: @MarketInSG would break the form from remembering the users data, if there was a error after submitting the checkout.

Digging into the Opencart code you can see that in catalog/controller/checkout/manual.php it uses the config_zone_id to setup the default address for the customer.
Code: Select all
// Tax
if ($this->cart->hasShipping()) {
   $this->tax->setShippingAddress($this->request->post['shipping_country_id'], $this->request->post['shipping_zone_id']);
} else {
   $this->tax->setShippingAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
}

$this->tax->setPaymentAddress($this->request->post['payment_country_id'], $this->request->post['payment_zone_id']);            
$this->tax->setStoreAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));   


And: system/library/tax.php
Code: Select all
<?php
final class Tax {
   private $shipping_address;
   private $payment_address;
   private $store_address;
   
   public function __construct($registry) {
      $this->config = $registry->get('config');
      $this->customer = $registry->get('customer');
      $this->db = $registry->get('db');   
      $this->session = $registry->get('session');
      
      if (isset($this->session->data['shipping_country_id']) || isset($this->session->data['shipping_zone_id'])) {
         $this->setShippingAddress($this->session->data['shipping_country_id'], $this->session->data['shipping_zone_id']);
      } elseif ($this->config->get('config_tax_default') == 'shipping') {
         $this->setShippingAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
      }
      
      if (isset($this->session->data['payment_country_id']) || isset($this->session->data['payment_zone_id'])) {
         $this->setPaymentAddress($this->session->data['payment_country_id'], $this->session->data['payment_zone_id']);
      } elseif ($this->config->get('config_tax_default') == 'payment') {
         $this->setPaymentAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
      }
      
      $this->setStoreAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));   
     }
User avatar
opencart-templates
 
Posts: 107
Joined: Mon May 16, 2011 11:24 am
Location: UK

Re: Default Region/State to None -- Singapore

Postby thegeekz » Fri Jan 11, 2013 2:50 am

opencart-templates wrote:Inside the Store Settings -> Local you are required to select the default "Region / State:"

If you dont want this to be set as default you need to add:
Code: Select all
($this->config->get('config_zone_id') != $result['zone_id'])


So vqmod file would look like this:
Code: Select all
<file name="catalog/controller/checkout/guest.php">
   <operation>
      <search position="replace"><![CDATA[
         if (isset($this->request->get['zone_id']) && ($this->request->get['zone_id'] == $result['zone_id'])) {
      ]]></search>
      <add><![CDATA[
         if (isset($this->request->get['zone_id']) && ($this->config->get('config_zone_id') != $result['zone_id']) && ($this->request->get['zone_id'] == $result['zone_id'])) {
      ]]></add>
   </operation>
</file>


The method suggested by: @MarketInSG would break the form from remembering the users data, if there was a error after submitting the checkout.

Digging into the Opencart code you can see that in catalog/controller/checkout/manual.php it uses the config_zone_id to setup the default address for the customer.
Code: Select all
// Tax
if ($this->cart->hasShipping()) {
   $this->tax->setShippingAddress($this->request->post['shipping_country_id'], $this->request->post['shipping_zone_id']);
} else {
   $this->tax->setShippingAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
}

$this->tax->setPaymentAddress($this->request->post['payment_country_id'], $this->request->post['payment_zone_id']);            
$this->tax->setStoreAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));   


And: system/library/tax.php
Code: Select all
<?php
final class Tax {
   private $shipping_address;
   private $payment_address;
   private $store_address;
   
   public function __construct($registry) {
      $this->config = $registry->get('config');
      $this->customer = $registry->get('customer');
      $this->db = $registry->get('db');   
      $this->session = $registry->get('session');
      
      if (isset($this->session->data['shipping_country_id']) || isset($this->session->data['shipping_zone_id'])) {
         $this->setShippingAddress($this->session->data['shipping_country_id'], $this->session->data['shipping_zone_id']);
      } elseif ($this->config->get('config_tax_default') == 'shipping') {
         $this->setShippingAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
      }
      
      if (isset($this->session->data['payment_country_id']) || isset($this->session->data['payment_zone_id'])) {
         $this->setPaymentAddress($this->session->data['payment_country_id'], $this->session->data['payment_zone_id']);
      } elseif ($this->config->get('config_tax_default') == 'payment') {
         $this->setPaymentAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));
      }
      
      $this->setStoreAddress($this->config->get('config_country_id'), $this->config->get('config_zone_id'));   
     }


Hmm.. Thank you for your reply.

I have already set the default to Singapore, and the region was defaulted to None.

However, in the registration page, it still shows:
Image 1.jpg
Image 1.jpg (13.47 KiB) Viewed 333 times


So I'm back to square one again... Only thing is to remove the Basico theme's part of the code here:

From this...
catalog/view/theme/Basico/template/account/register.tpl
Code: Select all
<div class="selectdiv">
<select class="prod" name="zone_id" style="z-index: 10; opacity: 0;">
</select>

To ...
[code]<div class="selectdiv">
<select name="zone_id">
[/code]


Also have to change the coding in Controller/account/register.php to this (OC1.5.2.1, I'm now using OC1.5.4.1)
:
From this
[code]public function zone() {
      $output = '<option value="">' . $this->language->get('text_select') . '</option>';
      
      $this->load->model('localisation/zone');

       $results = $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']);
       
         foreach ($results as $result) {
           $output .= '<option value="' . $result['zone_id'] . '"';
   
          if (isset($this->request->get['zone_id']) && ($this->request->get['zone_id'] == $result['zone_id'])) {
               $output .= ' selected="selected"';
          }
   
          $output .= '>' . $result['name'] . '</option>';
       }
      
      if (!$results) {
           $output .= '<option value="0">' . $this->language->get('text_none') . '</option>';
      }
   
      $this->response->setOutput($output);
     }  [/code]

To this

[code]public function zone() {

     
         $this->load->model('localisation/zone');

          $results = $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']);

         if (!$results) {
           $output = '<option value="0">' . $this->language->get('text_none') . '</option>';
         } else {
        $output = '<option value="">' . $this->language->get('text_select') . '</option>';
         }
         

        foreach ($results as $result) {
        $output .= '<option value="' . $result['zone_id'] . '"';
   
        if (isset($this->request->get['zone_id']) && ($this->request->get['zone_id'] == $result['zone_id'])) {
               $output .= ' selected="selected"';
        }
   
        $output .= '>' . $result['name'] . '</option>';
          }
   $this->response->setOutput($output);
     }



However I noted that this will break Basico's theme and revert the styling of the dropdown box to the default OC format....
Image 2.jpg
Image 2.jpg (13.3 KiB) Viewed 333 times


And OC1.5.4.1 doesn't have the above public function zone code set anymore.... so how can I default to None now?


Any further help on this?
Production Cart @ http://eshop.kgshop-sg.com -- OC 1.5.4.1 -- pending
No more using Apsona, as they are not updated.
    Every upgrade -- rem. 2 reinstall vqmod & mindful of modules w/ VQmod -- E.g Import / Export Tool by MHC
Test cart @ http://tshop.kgshop-sg.com -- pending -- still busy with friend's OC cart.
thegeekz
 
Posts: 326
Joined: Tue Nov 02, 2010 2:24 am


Return to Template Support

Who is online

Users browsing this forum: sammysomerset, Xyph3r and 15 guests

Hosted by Arvixe Web Hosting