News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Virtuemart State / Province / Region not showing in dropdown

Started by shankar, December 28, 2012, 05:39:10 AM

Previous topic - Next topic

SiberianTiger

Quote from: Maxim Pishnyak on November 22, 2013, 09:14:01 AM
Screen shot of your combos, also see http://forum.virtuemart.net/index.php?topic=119638.0

Hi Maxim,

The current combos are as pictured:


This caused the effect:


Installed the firebug, it shows the empty dropdown content for the combo and the following GET request sent and error code returned for it:

GET https://agenty-buduschego.ru/index.php?option=com_virtuemart&view=state&format=json&virtuemart_country_id=176&lang=ru

303 See other 472ms


Interesting that in the response header I can see http protocol, not https, can this be related to the issue? My website is running on SSL whole.

Response Headers
Connection keep-alive
Content-Length 0
Content-Type text/html; charset=utf-8
Date Fri, 22 Nov 2013 09:23:16 GMT
Location http://agenty-buduschego.ru/index.php?option=com_virtuemart&view=state&format=json&virtuemart_country_id=176&lang=ru
Server nginx/1.1.10




Maxim Pishnyak

You can support Community by voting for Project on the JED
https://extensions.joomla.org/extension/virtuemart/#reviews
Join us at
https://twitter.com/virtuemart

SiberianTiger

When I directly use the GET request in my browser address line, I can see a correct JSON data containing Russia's regions and their codes is returned.

The example output is:
{"virtuemart_state_id":"749","virtuemart_vendor_id":"1","virtuemart_country_id":"176","virtuemart_worldzone_id":"0","state_name":"\u0427\u0435\u0447\u0435\u043d\u0441\u043a\u0430\u044f \u0420\u0435\u0441\u043f\u0443\u0431\u043b\u0438\u043a\u0430","state_3_code":"CE","state_2_code":"20","ordering":"0","shared":"0","published":"1","created_on":"0000-00-00 00:00:00","created_by":"0","modified_on":"0000-00-00 00:00:00","modified_by":"0","locked_on":"0000-00-00 00:00:00","locked_by":"0"},{"virtuemart_state_id":"750","virtuemart_vendor_id":"1","virtuemart_country_id":"176","virtuemart_worldzone_id":"0","state_name":"\u0427\u0443\u0432\u0430\u0448\u0441\u043a\u0430\u044f \u0420\u0435\u0441\u043f\u0443\u0431\u043b\u0438\u043a\u0430","state_3_code":"CU","state_2_code":"21","ordering":"0","shared":"0","published":"1","created_on":"0000-00-00 00:00:00","created_by":"0","modified_on":"0000-00-00 00:00:00","modified_by":"0","locked_on":"0000-00-00 00:00:00","locked_by":"0"},{"virtuemart_state_id":"811","virtuemart_vendor_id":"1","virtuemart_country_id":"176","virtuemart_worldzone_id":"0","state_name":"\u0427\u0443\u043a\u043e\u0442\u0441\u043a\u0438\u0439 \u0430\u0432\u0442\u043e\u043d\u043e\u043c\u043d\u044b\u0439 \u043e\u043a\u0440\u0443\u0433","state_3_code":"CHU","state_2_code":"87","ordering":"0","shared":"0","published":"1","created_on":"0000-00-00 00:00:00","created_by":"0","modified_on":"0000-00-00 00:00:00","modified_by":"0","locked_on":"0000-00-00 00:00:00","locked_by":"0"},{"virtuemart_state_id":"812","virtuemart_vendor_id":"1","virtuemart_country_id":"176","virtuemart_worldzone_id":"0","state_name":"\u042f\u043c\u0430\u043b\u043e-\u041d\u0435\u043d\u0435\u0446\u043a\u0438\u0439 \u0430\u0432\u0442\u043e\u043d\u043e\u043c\u043d\u044b\u0439 \u043e\u043a\u0440\u0443\u0433","state_3_code":"YAN","state_2_code":"89","ordering":"0","shared":"0","published":"1","created_on":"0000-00-00 00:00:00","created_by":"0","modified_on":"0000-00-00 00:00:00","modified_by":"0","locked_on":"0000-00-00 00:00:00","locked_by":"0"},


Still, the dropdown box is not populated.

So, the problem rounds down to the way how this dropdown is filled by entries.
I wonder, which piece of code is supposed to do that?

May it be
administrator/components/com_virtuemart/views/state/view.html.php
administrator/components/com_virtuemart/models/state.php
components/com_virtuemart/controllers/state.php
?


SiberianTiger

Ok, so it appear the issue is in the following piece:

administrator/components/com_virtuemart/helpers/config.php

static function JcountryStateList($stateIds, $prefix='') {
static $JcountryStateList = array();
// If exist exit
if (isset($JcountryStateList[$prefix]) or !VmConfig::get ('jsite', TRUE)) {
return;
}
$document = JFactory::getDocument();
VmJsApi::jSite();
$document->addScriptDeclaration('
//<![CDATA[
jQuery( function($) {
$("#'.$prefix.'virtuemart_country_id").vm2front("list",{dest : "#'.$prefix.'virtuemart_state_id",ids : "'.$stateIds.'",prefiks : "'.$prefix.'"});
});
//]]>
');
$JcountryStateList[$prefix] = TRUE;
return;
}


This makes a jQuery API call to the $ function in components/com_virtuemart/assets/js/vmsite.js:

(function($){
var undefined,
methods = {
list: function(options) {
var dest = options.dest;
var ids = options.ids;
var prefix = options.prefiks;
            methods.update(this,dest,ids,prefix);
$(this).change( function() { methods.update(this,dest,ids,prefix)});

},
update: function(org,dest,ids,prefix) {
var opt = $(org),
optValues = opt.val() || [],
byAjax = [] ;
if (!$.isArray(optValues)) optValues = jQuery.makeArray(optValues);
if ( typeof  oldValues !== "undefined") {
//remove if not in optValues
$.each(oldValues, function(key, oldValue) {
if ( ($.inArray( oldValue, optValues )) < 0 ) $("#"+prefix+"group"+oldValue).remove();
});
}
//push in 'byAjax' values and do it in ajax
$.each(optValues, function(optkey, optValue) {
if( opt.data( 'd'+optValue) === undefined ) byAjax.push( optValue );
});

if (byAjax.length >0) {
$.getJSON('index.php?option=com_virtuemart&view=state&format=json&virtuemart_country_id=' + byAjax,
function(result){

// Max Bitte Testen
var virtuemart_state_id = $('#'+prefix+'virtuemart_state_id');
var status = virtuemart_state_id.attr('required');

if(status == 'required') {
if( result[byAjax].length > 0 ) {
virtuemart_state_id.attr('required','required');
} else {
virtuemart_state_id.removeAttr('required');
}
}

// ENDE

$.each(result, function(key, value) {
if (value.length >0) {
opt.data( 'd'+key, value );
} else {
opt.data( 'd'+key, 0 );
}
});
methods.addToList(opt,optValues,dest,prefix);
if ( typeof  ids !== "undefined") {
var states =  ids.length ? ids.split(',') : [] ;
$.each(states, function(k,id) {
$(dest).find('[value='+id+']').attr("selected","selected");
});
}
$(dest).trigger("liszt:updated");
}
);
} else {
methods.addToList(opt,optValues,dest,prefix)
$(dest).trigger("liszt:updated");
}
oldValues = optValues ;

},
addToList: function(opt,values,dest,prefix) {
$.each(values, function(dataKey, dataValue) {
var groupExist = $("#"+prefix+"group"+dataValue+"").size();
if ( ! groupExist ) {
var datas = opt.data( 'd'+dataValue );
if (datas.length >0) {
var label = opt.find("option[value='"+dataValue+"']").text();
var group ='<optgroup id="'+prefix+'group'+dataValue+'" label="'+label+'">';
$.each( datas  , function( key, value) {
if (value) group +='<option value="'+ value.virtuemart_state_id +'">'+ value.state_name +'</option>';
});
group += '</optgroup>';
$(dest).append(group);

}
}
});
}
};

$.fn.vm2front = function( method ) {

if ( methods[method] ) {
  return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
  $.error( 'Method ' +  method + ' does not exist on Vm2 front jQuery library' );
}   

};
})(jQuery)


As a result, I'm having a
Quote303 See other (206ms) at jquery.min.js (line 18)

Please find below the request and response headers I'm having:

Request:
Accept application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Cookie 4eb57c2cab77304872032c29b810ab83=ru-RU; 4eb57c2cab77304872032c29b810ab83=ru-RU; ce03aacdace0d694b35279c3e291619f=1D444611571757575C+3415E1460+D+0+010+8565765+F56511712144445+31715115C105647+31469+3+A+6445150525552434A; 192fa9b374f512ee8093cd079b0847d4=071054c64d78b443fc3e47e43ec5d9d8
Host agenty-buduschego.ru
Referer https://agenty-buduschego.ru/index.php?option=com_virtuemart&view=user&layout=edit&lang=ru
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0
X-Requested-With XMLHttpRequest


Response:
Connection keep-alive
Content-Length 0
Content-Type text/html; charset=utf-8
Date Fri, 13 Dec 2013 09:29:10 GMT
Location http://agenty-buduschego.ru/index.php?option=com_virtuemart&view=state&format=json&virtuemart_country_id=176&lang=ru
Server nginx


Virtuemart dev, please help to resolve this, this issue is holding my business from opening. I don't want yet to trash the otherwise fine store extension in favor of some different one.

admiss

Virtuemart 2.0.22b
Joomla 2.5

States in back end are published, but not visible(chooseable) on the site.

Uncaught TypeError: Object [object Object] has no method 'chosen'        >>> user-account:78

$(".vm-chzn-select").chosen({enable_select_all: true,select_all_text : vm2string.select_all_text,select_some_options_text:vm2string.select_some_options_text});


view-source:http://www.foodhungary.co.uk/user-account


Appreciate any help .
Thanks

[attachment cleanup by admin]

jenkinhill

Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

greenkey

Well, if somebody has problem with virtuemart region select (regions not showing), be careful:

If you are using nginx, and set sef url, such as:
try_files $uri $uri/ /index.php?q=$request_uri;

you must create a little fix here:
/components/com_virtuemart/assets/js/vmsite.js

find a string:
$.getJSON('index.php?option=com_virtuemart&view=state&format=json&virtuemart_country_id=' + byAjax,

and replace with:
$.getJSON('/index.php?option=com_virtuemart&view=state&format=json&virtuemart_country_id=' + byAjax,

it solve problem with region seelction.

This problem is actual for Virtuemart 3.0.9

Jason dsg

I just have removed my joomla site loaded a fresh site with a rocket them templet it has gantry 5 i checked the bees templet i have no states on there as well I'm also going to need to pay someone to do some edits or have someone help me i don't want to give out my passwords for help thanks www.dsgcentral.com

GJC Web Design

you have 2 js errors

SyntaxError: expected expression, got keyword 'var'
http://www.dsgcentral.com/components/com_virtuemart/assets/js/vmsite.js?vmver=9058
Line 52

TypeError: $(...).vm2front is not a function
http://www.dsgcentral.com/user/editaddresscartBT
Line 715

I don't see any menus.. have u a menu to the VM frontpage and one to the cart?
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 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
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation