VirtueMart Forum

VirtueMart 2 + 3 + 4 => Administration & Configuration => Topic started by: Mike J on March 19, 2017, 23:29:34 PM

Title: Default country by language
Post by: Mike J 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



Title: Re: Default country by language
Post by: GJC Web Design 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?
Title: Re: Default country by language
Post by: Mike J 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
Title: Re: Default country by language
Post by: MKI-Miro on September 08, 2017, 09:06:10 AM
why this is not included in virtuemart core?  :(
Title: Re: Default country by language
Post by: AH 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.


Title: Re: Default country by language
Post by: MKI-Miro 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 ?
Title: Re: Default country by language
Post by: MKI-Miro 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>
Title: Re: Default country by language
Post by: Studio 42 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.
<?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