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

How to show states after selecting country ?

Started by jibon57, July 01, 2014, 18:28:31 PM

Previous topic - Next topic

jibon57

Hello,

I am trying to extended the default VM shipping plugin & want to add states when user will choose countries. How I can get all the states list when user will choose one country as in "Tax & Calculation Rule" in VM ? Here is what I did:

I added new file in elements folder called "vmstates.php" so that I can get all available states list in xml file. Here is my vmstates.php file:


<?php
defined
('_JEXEC') or die();

class 
JElementVmStates extends JElement {

    
/**
     * Element name
     * @access protected
     * @var string
     */
    
var $_name 'states';

    function 
fetchElement($name$value, &$node$control_name) {

        
$db =  JFactory::getDBO();

        
$query 'SELECT `virtuemart_state_id` AS value, `state_name` AS text FROM `#__virtuemart_states`
                WHERE `published` = 1 ORDER BY `state_name` ASC '
        
;

        
$db->setQuery($query);
        
$fields $db->loadObjectList();
    $class = ($node->attributes('class') ? 'class="' $node->attributes('class') . '"' '');


    $class 'multiple="true" size="10"  ';
        return 
JHTML::_('select.genericlist'$fields$control_name '[' $name '][]'$class'value''text'$value$control_name $name);
    }

}


& my xml file:


<params addpath="/plugins/vmshipment/weight_countries/elements"/>
<param name="states" type="vmstates" scope="com_virtuemart" default=""
               label="States" description="States"/>


But I am getting all the states list. Is there anyway to retrieve data according to country that should be select from top ?

GJC Web Design

the states arereturned by an ajax call dependent of the country chosen - have a look at the normal user registration and trace the JS used to trigger the call -
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

jibon57

Quote from: GJC Web Design on July 01, 2014, 23:22:17 PM
the states arereturned by an ajax call dependent of the country chosen - have a look at the normal user registration and trace the JS used to trigger the call -

Thanks for your reply. Can you help me to give me more clear idea please ? I tried in all ways but really can't figure out :(

GJC Web Design

have a look at the JS in components/com_virtuemart/assets/js/vmsite.js from about line 39

but the basic call to get a country dependent state list is

/index.php?option=com_virtuemart&view=state&format=json&virtuemart_country_id=222

returns a JSON state list of that country

e.g.

{"222":[{"virtuemart_state_id":"65","virtuemart_vendor_id":"1","virtuemart_country_id":"222","virtuemart_worldzone_id":"0","state_name":"England","state_3_code":"ENG","state_2_code":"EN","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":"66","virtuemart_vendor_id":"1","virtuemart_country_id":"222","virtuemart_worldzone_id":"0","state_name":"Northern Ireland","state_3_code":"NOI","state_2_code":"NI","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":"67","virtuemart_vendor_id":"1","virtuemart_country_id":"222","virtuemart_worldzone_id":"0","state_name":"Scotland","state_3_code":"SCO","state_2_code":"SD","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":"68","virtuemart_vendor_id":"1","virtuemart_country_id":"222","virtuemart_worldzone_id":"0","state_name":"Wales","state_3_code":"WLS","state_2_code":"WS","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"}]}
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

Pirated


jibon57

#5
Thanks for your reply GJC Web Design & Pirated. But Pirated will you please write down the code here what you did ? I ain't such expert really :) .  The main problem is I really can't understand how I will send request from xml file? In shipping system all those are handled by xml file. That's why it's making me confusion :( .  Thanks in advance :)