Page 1 of 1

COM_VIRTUEMART_COUNTRY_STATE_NOTEXIST

PostPosted: Mon Aug 20, 2018 10:09 am
by konstantinos
Hello,

I sometimes get this notice in the OPC page (frontend): COM_VIRTUEMART_COUNTRY_STATE_NOTEXIST

Any idea? Thank you

Joomla 3.8.10 / VM 3.2.15 / OPC 2.0.365

Re: COM_VIRTUEMART_COUNTRY_STATE_NOTEXIST

PostPosted: Wed Aug 22, 2018 1:03 pm
by admin
hello, it would help if we knew conditions on how to reproduce this.

what is the status of your "US Mode" in Taxes and Prices tab in OPC ?

this mode sets space to "state id" and thus could make this message to be shown in some special cases. the US Mode makes state invalid so it's not used for tax calculation outside checkout.

if you find out how to reproduce this, i can fix this, but i cannot reproduce on my own site or at my clients right now.

best regards, stan

Re: COM_VIRTUEMART_COUNTRY_STATE_NOTEXIST

PostPosted: Wed Oct 31, 2018 1:59 pm
by loppan
Hi!

I'm also seeing this message since quite recently. Not sure why, and it's only under certain circumstances, so far I've only got reports from US and Australian customers.

Seems to work fine to checkout anyways though.

what is the status of your "US Mode" in Taxes and Prices tab in OPC ?


Is this "American settings"? Mine is disabled.

Curious if we have any ideas here, not sure why I'm getting this :).

Truly greatful for any ideas. Thanks!

Best regards

Peter

Re: COM_VIRTUEMART_COUNTRY_STATE_NOTEXIST

PostPosted: Thu Nov 08, 2018 3:57 pm
by admin
hello peter, what is your OPC config in Taxes and Prices (tab) -> American settings (checkbox)

this checkbox forces invalid state for a country so that it does not calculate taxes by default within non-cart views.

this feature was added back in early vm2.0 days and per your calculation configuration it may not be needed at all right now.

if you got it disabled, and some customers still see the message i can try to insert a debug code into VM so it logs backtrace of why it displayes this message.

best regards, stan

Re: COM_VIRTUEMART_COUNTRY_STATE_NOTEXIST

PostPosted: Fri Nov 09, 2018 2:58 pm
by loppan
Hi stan, thanks for your reply.

My "American settings" checkbox is disabled.

Still receiving this message for US and Australian customers :/. Most likely others too. Still no idea where it comes from. Truly grateful for help :).

Best regards

Peter

Re: COM_VIRTUEMART_COUNTRY_STATE_NOTEXIST

PostPosted: Wed Nov 14, 2018 11:49 am
by admin
hello Peter, i let me know by email and i can insert this debug code into the VM file to find out what's going on.

to supress the message you can modify:
\administrator\components\com_virtuemart\models\state.php

comment this line:
Code: Select all
vmInfo('COM_VIRTUEMART_COUNTRY_STATE_NOTEXIST');


so it looks like:
Code: Select all
// vmInfo('COM_VIRTUEMART_COUNTRY_STATE_NOTEXIST');


to create debug information on how this happens you can update whole function to this:

Code: Select all
/**
    * Tests if a state and country fits together and if they are published
    *
    * @author Max Milbers
    * @return String Attention, this function gives a 0=false back in case of success
    */
   public static function testStateCountry(&$countryId, &$stateId, &$required) {

      $countryId = (int)$countryId;
      $stateId = (int)$stateId;

      if(empty($countryId)) return true;

      $db = JFactory::getDBO();
      $q = 'SELECT * FROM `#__virtuemart_countries` WHERE `virtuemart_country_id`= "'.$countryId.'" AND `published`="1"';
      $db->setQuery($q);
      if($db->loadResult()){
         //Test if country has states
         $q = 'SELECT * FROM `#__virtuemart_states`  WHERE `virtuemart_country_id`= "'.$countryId.'" AND `published`="1"';
         $db->setQuery($q);
         if($db->loadResult()){

            if(!empty($stateId)){
               //Test if virtuemart_state_id fits to virtuemart_country_id
               $q = 'SELECT * FROM `#__virtuemart_states` WHERE `virtuemart_country_id`= "'.$countryId.'" AND `virtuemart_state_id`="'.$stateId.'" and `published`="1"';
               $db->setQuery($q);
               if($db->loadResult()){
                  return true;
               } else {
                  //There is a country, but the state does not exist or is unlisted
                  $stateId = 0;
                  vmLanguage::loadJLang('com_virtuemart_countries');

                  $x = debug_backtrace();
                  $msg = "\n";
                  $br = "<br />\n";
                  foreach ($x as $l) $msg .= @$l['file'].' '.@$l['line'].$br;
                  $msg .= 'country: '.var_export($countryId, true).$br;
                  $msg .= 'state: '.var_export($stateId, true).$br;
                  file_put_contents(JPATH_SITE.DIRECTORY_SEPARATOR.'statelog.html', $msg, FILE_APPEND);
                  
                  //vmInfo('COM_VIRTUEMART_COUNTRY_STATE_NOTEXIST');
                  return false;
               }
            }

         } else {
            //This country has no states listed
            $stateId = 0;
            $required = false;
            return true;
         }

      } else {
         //The given country does not exist, this can happen, when non published country was chosen
         $countryId = 0;
         $stateId = 0;
         vmLanguage::loadJLang('com_virtuemart_countries');
         vmInfo('COM_VIRTUEMART_COUNTRY_NOTEXIST');
         return false;
      }
   }



this will create a log file in your domain.com/statelog.html that will look like
https://php72.rupostel.com/purity/statelog.html

and will tell us why this happens.

this mod will be automatically removed upon further VM update so if the problem is not fixed, the message will be shown again.

best regards, stan