X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Where to place the common ajax functions for shipping module plugin (https://forum.x-cart.com/showthread.php?t=72523)

aneel13 08-02-2015 02:03 AM

Where to place the common ajax functions for shipping module plugin
 
Where should I place my common ajax functions and can you please give me sample url on ajax calls?

I have got a new shipping methods but I don't know where should I place the ajax related functions specific to my plugin only?

aneel13 08-02-2015 02:17 AM

Re: Where to place the common ajax functions for shipping module plugin
 
Please note the following sample ajax call code. I have to use autocomplete jquery library thatswhy I am doing it normal jQuery way instead of some conventional X-Cart way:

jQuery("document").ready(function(){

jQuery("#shippingaddress-city").autocomplete('test', {
extraParams: {
countrycode: function() { return jQuery("#shippingaddress-country-code").val();},
city: function() { return jQuery("#shippingaddress-city").val(); }
},
minChars: 0,
max: 200,
multiple:false,
scrollHeight: 220,
autoFill: false,
mustMatch: false,
selectFirst:true,
cacheLength:1
});

jQuery("#shippingaddress-zipcode").autocomplete('test', {
extraParams: {
countrycode: function() { return jQuery("#shippingaddress-country-code").val();},
zip: function() { return jQuery("#shippingaddress-zipcode").val(); }
},
minChars: 0,
max: 200,
multiple:false,
scrollHeight: 220,
autoFill: false,
mustMatch: false,
selectFirst:false,
cacheLength:1
});

});

qualiteam 08-03-2015 04:10 AM

Re: Where to place the common ajax functions for shipping module plugin
 
I think it may work if you add this js file to the list of js files loaded by the widget class.

However, it would be better if you could wrap it up into a "controller" and make XC5 autoload it - search for "core.autoload(" in other js files.

aneel13 08-03-2015 04:14 AM

Re: Where to place the common ajax functions for shipping module plugin
 
Sorry for not explaining clearly. I gave the example of jquery because I wanted to insert some xcart specific url to the autocomplete jquery function. So I mean to say that what sort of url should it be. Any example url? And where should I place the php related function which is going to be processed because this url is called.

qualiteam 08-05-2015 11:46 PM

Re: Where to place the common ajax functions for shipping module plugin
 
It can be any URL pointing to a valid controller class. It's the controller and the view classes that should implement the AJAX logic.

If you need json response, use the WidgetsCollection controller as the example.
If you need html response (I believe so), check how the checkout controller reloads page sections.

aneel13 08-06-2015 01:50 AM

Re: Where to place the common ajax functions for shipping module plugin
 
Can you please give me some sample url of how it should be for the controller function or some documentation link which is giving an example of how to write the controller for a new plugin/shipping method?

qualiteam 08-16-2015 09:59 PM

Re: Where to place the common ajax functions for shipping module plugin
 
Hello!

Please use the documentation at http://kb.x-cart.com/ for reference.

The article on creating a new controller is here:
http://kb.x-cart.com/display/XDD/Creating+new+page

aneel13 08-17-2015 08:32 PM

Re: Where to place the common ajax functions for shipping module plugin
 
Thanks! Got it working with the controller functions


All times are GMT -8. The time now is 01:09 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.