0

We need to add a US/Canada <option> element before region_id to select US or Canada in the Registration Form, and change the region_id <option> element based on if the user selects either using javascript. Here is the current template, which looks similar to the magento default:

<div class="input-box">
    <label for="region_id"><?php echo $this->__('State/Province') ?> <span class="required">*</span></label>
    <select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" class="validate-select" style="display:none;">
       <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
    </select>
    <script type="text/javascript">
       $('region_id').setAttribute('defaultValue',  "<?php echo $this->getFormData()->getRegionId() ?>");
    </script>
    <input type="text" id="region" name="region" value="<?php echo $this->htmlEscape($this->getRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text" style="display:none;" />
</div>

In the Admin panel under System -> Configuration -> General, Countries allowed are United States and Canada. If I can pull these both separately into a javascript array then switching them will be much easier. How can I accomplish this?

Edit: Just had an idea for this, is it possible to detect if the visitor is in US/Canada based on $_SERVER environment variables to auto select a region to populate State/Providence once and not involve javascript?

2

Yes there is mod_geoip2 for apache to get the location from the ip:

http://dev.maxmind.com/geoip/mod_geoip2

| improve this answer | |
  • Very nice. I just need to figure out how to pass this through the form and get the options array. – DWils Aug 10 '13 at 20:48
  • You can add a shipping-address to the order, then I think it should be set automatically – Fabian Blechschmidt Aug 12 '13 at 7:21
1

Here is my extension which allows GeoIP integration on Magento level

https://github.com/tim-bezhashvyly/geoip

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.