Author Topic: Default country by language  (Read 617 times)

Mike J

  • Beginner
  • *
  • Posts: 22
Default country by language
« on: March 19, 2017, 23:29:34 pm »
Does anyone know how to set by chosen language the default/preselected country in the cart?

For example
en-GB = United Kingdom
en-US = United States etc



VirtueMart 3.0.18
Joomla! 3.6.5

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 7621
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 2.6.22 & 3.2.2
Re: Default country by language
« Reply #1 on: March 21, 2017, 00:53:35 am »
(A Jenks copy/paste)

Did you miss the vital security release?
https://www.joomla.org/announcements/release-news/5693-joomla-3-6-5-released.html
http://forum.virtuemart.net/index.php?topic=118683.0

you have a language choice for USA and GB?
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Mike J

  • Beginner
  • *
  • Posts: 22
Re: Default country by language
« Reply #2 on: March 21, 2017, 01:41:51 am »
Hello GJC Web Design,

No, I hadn't updated my profile on the forum since the last time I posted. So sorry about that (I find it incredible that he finds that incredible).

Yes.

Am currently using this : http://extensions.virtuemart.net/vm-orders/vm-localise-detail which does a pretty good job but would rather have the selected site language or currency determine the default/preselected country in my case (If it's not too much of a drama).

Anyways, that's for taking the time to respond... You're about the only one who ever does :)

M
VirtueMart 3.0.18
Joomla! 3.6.5

MKI-Miro

  • Jr. Member
  • **
  • Posts: 132
Re: Default country by language
« Reply #3 on: September 08, 2017, 09:06:10 am »
why this is not included in virtuemart core?  :(

AH

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 2628
  • VirtueMart Version: 3.2.5
Re: Default country by language
« Reply #4 on: September 08, 2017, 09:23:35 am »
MKI

I see another of your recent posts also mentions things being in the core.

Not everything is, or will be included, in the core.  That is why third party plugins exist.

When someone mentions a third party plugin then assume that your problem might be solveable, and you might have to assign some funds to your project to get things to work exactly how you want them.


regards
A

Joomla 3.8.2
php 5.6 + php 7

MKI-Miro

  • Jr. Member
  • **
  • Posts: 132
Re: Default country by language
« Reply #5 on: October 01, 2017, 16:42:16 pm »
i am trying to do it on my own but country dropdown is not simple <select>

any idea how to code ?

MKI-Miro

  • Jr. Member
  • **
  • Posts: 132
Re: Default country by language
« Reply #6 on: October 01, 2017, 17:16:02 pm »
I have found that it uses chosen jquery plugin so solution is:

<?php
$lang = JFactory::getLanguage();
$langTag = $lang->getTag();
?>

<script>
  jQuery(document).ready(function(){

  <?php if ($langTag == "sk-SK") { ?>
      jQuery('#virtuemart_country_id_field').val(189);
      jQuery('#virtuemart_country_id_field').trigger("chosen:updated");
  <?php } elseif($langTag == "en-GB") { ?>
      jQuery('#virtuemart_country_id_field').val(222);
      jQuery('#virtuemart_country_id_field').trigger("chosen:updated");   
  <?php } elseif($langTag == "hu-HU") { ?>
      jQuery('#virtuemart_country_id_field').val(97);
      jQuery('#virtuemart_country_id_field').trigger("chosen:updated"); 
  <?php } elseif($langTag == "de-DE") { ?>
      jQuery('#virtuemart_country_id_field').val(81);
      jQuery('#virtuemart_country_id_field').trigger("chosen:updated"); 
  <?php } elseif($langTag == "de-AT") { ?>
      jQuery('#virtuemart_country_id_field').val(14);
      jQuery('#virtuemart_country_id_field').trigger("chosen:updated"); 
  <?php } elseif($langTag == "ro-RO") { ?>
      jQuery('#virtuemart_country_id_field').val(175);
      jQuery('#virtuemart_country_id_field').trigger("chosen:updated");   
  <?php } elseif($langTag == "pl-PL") { ?>
      jQuery('#virtuemart_country_id_field').val(170);
      jQuery('#virtuemart_country_id_field').trigger("chosen:updated");   
  <?php } ?>
  });
</script>

Studio 42

  • Contributing Developer
  • Full Member
  • *
  • Posts: 2355
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 &amp; 3.0.x.y
Re: Default country by language
« Reply #7 on: October 02, 2017, 00:25:58 am »
our code is not fine.
You should check if jQuery('#virtuemart_country_id_field').val() is empty or only call it if address (or check with js a required field) is empty on load.

And to simply your code or add other countries.
Code: [Select]
<?php 
$lang 
JFactory::getLanguage();
$langTag $lang->getTag();
$langId null;
if (
$langTag == "sk-SK"$langId 189;
elseif(
$langTag == "en-GB"$langId 222;
elseif(
$langTag == "hu-HU"$langId 97;
// add all $langTag ...
if($langId !==null) { ?>

<script>
  jQuery(document).ready(function(){
      jQuery('#virtuemart_country_id_field').val(<?php echo $langId ?>).trigger("chosen:updated");
  });
</script>
<?php