- Posts: 42
- Thank you received: 2
Using AJAX to load states
-- Joomla version -- : 3.4.1
-- PHP version -- : 5.4.43
Hi Hika Team!
We've had to repurpose the states field (when someone creates or edits their address) to load a list of around 6000 shipping zones for our primary country and to work with our own courier. It is working, but we're wanting to reduce the load on our database and are wanting to know which view to edit so that we can load this list using AJAX and Jquery.
Regards,
Bruce Atkinson
Please Log in or Create an account to join the conversation.
The loading of the data and display of the fields is not done in a view. It's done in the file administrator/components/com_hikashop/classes/field.php
So one solution is to do your modifications directly there.
But a cleaner solution is to implement a new type of custom field (that you can have extending from the state type custom field class) via the creation of a HikaShop plugin.
You can see an example of that with the plugin plugins/hikashop/datepickerfield/ and you can see documentation on that in the Fields API section of our developer documentation:
www.hikashop.com/support/support/documen...r-documentation.html
Please Log in or Create an account to join the conversation.
I've written Joomla friendly ajax code using the select2 library, is there an easy way of bundling this up in a hika plugin so that it will display as a field? I have looked at datepickerfield.php and datepickerfield_class.php and have made custom Joomla plugins in the past.
We are using a custom version of the "states" field in out Hika Database. You can see what we're wanting to integrate via the examples below.
select.php
fetch_data.php
So what we're looking for is contents for a new plugin named "customzoneajax". Would we install it at './plugins/hikashop/customzoneajax' and what would the contents of files 'customzoneajax.php' and 'customzoneajax_class.php' be?
Please Log in or Create an account to join the conversation.
We split the plugin custom fields into two files in order to have something light ; so when the field is not required (which is the case in most pages), the class is not loaded.
Like Nicolas told you, the datepicker is today the best example for a plugin custom field ; and when you create your plugin, you can add other PHP files if you want an entry point for the AJAX calls, you can also create a system plugin to be able to catch some Joomla URLs.
Using the plugin system, you can create new kind of custom fields and in these fields, the plugin can display whatever it wants as long as the data can be read in the POST to store a value in the database.
Regards,
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Please Log in or Create an account to join the conversation.
That didn't really help me much. Fortunately I discovered a workaround that achieves my needs by doing the following. For those who want to do something similar, this is what I did.
Create 'ajax' folder in joomla root. Saved select2.min.css and select2.min.js to this folder. Disabled chosen library in hikashop configuration. Created custom /ajax/fetch_data.php file as follows:
Customise address->show view for front-end as follows:
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Could you give more context on what you're trying to do ?
Because the states and countries are already loaded for the addresses in HikaShop.
So I don't understand what you're trying to do where and why.
Please Log in or Create an account to join the conversation.
We've had to do some tweaks as we've been growing with Hikashop over the years, one of which was using the states field for a whole bunch of areas (around 6000). Due to the size of this list, I needed to populate the select field via ajax, which I've done by customising the Address->Show view for front-end. I was able to bypass the fields class by using this condition
So in summary, how could I 'echo' the customer's selected addresses' country and state as a string from the address->show view.
Please Log in or Create an account to join the conversation.
The zone custom field has not been designed to be overridden.
If you want to customize the zone custom field with your own data and own process ; the best will be to create a new kind of custom field using a custom plugin ; like the "advanced date picker".
Just like I wrote in a previous message
Using the plugin system, you can create new kind of custom fields and in these fields, the plugin can display whatever it wants as long as the data can be read in the POST to store a value in the database.
We are not able to help you for the loading of your data for the zone custom field because it has not been design to support it ; it is a too important modification of the field.
Regards,
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
Please Log in or Create an account to join the conversation.
Is there an easy way to get the users's address info from the address->show view?
Please Log in or Create an account to join the conversation.
- get the current user_id with a call to the function hikashop_loadUser()
- do a MySQL on the hikashop_address table where the address_user_id is equal to that user_id
Please Log in or Create an account to join the conversation.