Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

State Selector for BS


raiwa

Recommended Posts

The function tep_draw_pull_down_menu should be fixed as well:

find:

if (tep_not_null($parameters)) $field .= ' ' . $parameters;

replace with:

    if (tep_not_null($parameters)) {
        if (strpos($parameters, 'required') !== false) {
            $parameters .= ' oninvalid="this.setCustomValidity(\'' . FORM_INPUT_VALUE_MISSING. '!\')" onchange="this.setCustomValidity(\'\')"';

        }
        $field .= ' ' . $parameters;
    }

 

Link to comment
Share on other sites

Hi,

If a country does not have zones, we do not need the
state input entry.

This is what I did:

in
includes/modules/checkout_new_address.php
includes/modules/checkout_new_address.php
account_pwa.php (I haven't tested this yet)

replace the block:

<?php
  if (ACCOUNT_STATE == 'true') {
?>
  ...
  <?php
  }
?>

with the following lines:

<?php
  if (ACCOUNT_STATE == 'true') {
?>
      <div id="results" class="form-group has-feedback">
          <?php
                  $zone_id = 0;
                  $check_query = tep_db_query("select count(*) as total from " . TABLE_ZONES . " where zone_country_id = '" . $country . "'");
                  $check = tep_db_fetch_array($check_query);
                  $entry_state_has_zones = ($check['total'] > 0);
                if ($entry_state_has_zones == true) {
                    $zones_array = array();
                    $zones_array[0] = array('id' => '', 'text' => PULL_DOWN_DEFAULT);                        
                    $zones_query = tep_db_query("select zone_name from " . TABLE_ZONES . " where zone_country_id = '" . $country . "' order by zone_name");
                    while ($zones_values = tep_db_fetch_array($zones_query)) {
                        $zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);
                    }
                    echo '<label for="inputState" class="control-label col-sm-3">' . ENTRY_STATE .'</label>';
                    echo '<div class="col-sm-9">';                    
                    echo tep_draw_pull_down_menu('state', $zones_array, (isset($entry['entry_country_id']) ? tep_get_zone_name($entry['entry_country_id'], $entry['entry_zone_id'], $entry['entry_state']) : ''), 'required aria-required="true" id="inputState"');
                    echo FORM_REQUIRED_INPUT;
                    echo '</div>';
                    if (tep_not_null(ENTRY_STATE_TEXT)) echo '<span class="help-block">' . ENTRY_STATE_TEXT . '</span>';
                }
              ?>
      </div>
<?php
  }
?>


in get_states.php

find:
     if ($entry_state_has_zones == true) {
          $zones_array = array();
       $zones_array[0] = array('id' => '', 'text' => PULL_DOWN_DEFAULT);                        
       $zones_query = tep_db_query("select zone_name from zones where zone_country_id = '" . (int)$state . "' order by zone_name");
       while ($zones_values = tep_db_fetch_array($zones_query)) {
            $zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);
       }
       echo tep_draw_pull_down_menu('state', $zones_array, '', 'required aria-required="true" id="inputState"');
       echo FORM_REQUIRED_INPUT;
     } else {
          echo tep_draw_input_field('state', NULL, 'id="inputState" class="form-control" required aria-required="true" placeholder="' . ENTRY_STATE    . '"');
          echo FORM_REQUIRED_INPUT;
     }
    
replace with:

     if ($entry_state_has_zones == true) {
          $zones_array = array();
       $zones_array[0] = array('id' => '', 'text' => PULL_DOWN_DEFAULT);                        
       $zones_query = tep_db_query("select zone_name from zones where zone_country_id = '" . (int)$state . "' order by zone_name");
       while ($zones_values = tep_db_fetch_array($zones_query)) {
            $zones_array[] = array('id' => $zones_values['zone_name'], 'text' => $zones_values['zone_name']);
       }
       echo '<label for="inputState" class="control-label col-sm-3">' . ENTRY_STATE .'</label>';
       echo '<div class="col-sm-9">';
       echo tep_draw_pull_down_menu('state', $zones_array, '', 'required aria-required="true" id="inputState"');
       echo FORM_REQUIRED_INPUT;
       echo '</div>';
     }

 

Link to comment
Share on other sites

If a country does not have zones in the oscommerce zones table, it doesn't mean that zones are not used. That's why the input field is still available for manual customer input like in the standard forms.

If your modification is good for your store ok, but it is not a generic modification which should be added to the add-on package (in my opinion).

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...