yari92 Posted July 10, 2014 Share Posted July 10, 2014 (edited) Good evening. I'm trying to make a kind of pagination for Stores. There are more than 200 stores to view (when I search for postcode and range 100km for example). That page viewing 20 stores. It's specified in the LIMIT option of the query in StoresController.php: $stores = Db::getInstance()->executeS(' SELECT s.*, cl.name country, st.iso_code state, ('.(int)($multiplicator).' * acos( cos(radians('.(float)(Tools::getValue('latitude')).')) * cos(radians(latitude)) * cos(radians(longitude) - radians('.(float)(Tools::getValue('longitude')).')) + sin(radians('.(float)(Tools::getValue('latitude')).')) * sin(radians(latitude)) ) ) distance, cl.id_country id_country FROM '._DB_PREFIX_.'store s '.Shop::addSqlAssociation('store', 's').' LEFT JOIN '._DB_PREFIX_.'country_lang cl ON (cl.id_country = s.id_country) LEFT JOIN '._DB_PREFIX_.'state st ON (st.id_state = s.id_state) WHERE s.active = 1 AND cl.id_lang = '.(int)$this->context->language->id.' HAVING distance < '.(int)($distance).' ORDER BY distance ASC LIMIT 0,20); I can change it to 200 but it's not a good idea to view 200 stores in one page. So i'm trying to make this pagination. To accomplish this function i have to pass html variables from stores.tpl to StoresController. I found that the method is this: $distance = (int)(Tools::getValue('radius', 100)); With this option radius is passed from stores.tpl where we have this select: <select name="radius" id="radiusSelect" class="form-control"> <option value="15">15</option> <option value="25">25</option> <option value="50">50</option> <option value="100">100</option> </select> I tried to do the passage of variables in this way, but nothing to do. Nothing arrives to StoresController.php. What i'm doing wrong? Is there an easiest way to do that pagination? Thanks for replies. Yari. Edited July 13, 2014 by vekia (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted July 11, 2014 Share Posted July 11, 2014 hello you have to pass these variables with $_POST or $_GET method so, the question, you <select> form is a part of <FORM> ? you submitted these variables? it's necessary otherwise Tools::getValue will not work Link to comment Share on other sites More sharing options...
yari92 Posted July 11, 2014 Author Share Posted July 11, 2014 Hello Vekia. I did not add the form because there were not any form neither for the 'radius', so i though that in this case the form is not necessary. Otherwise i tried to add the form in this way: <form id='formProvaSelect' name='formProvaSelect' action='' method='get'> <select name="provaSelect" id="provaSelect" > <option value="1">1</option> <option value="2">2</option> </select> <input type='submit' name='provaButton' value='Prova' /> </form> but this redirect me to "index.php?provaSelect=1&provaButton=Prova" with these values. Seems legit. The thing that is not clear to me is this: in stores.tpl i have not any form. But 'radius' still arrives to the StoresController.php and it get it with getValue. In which way? Why this is not allowed for my 'select'? Thank you for the replies. Yari. Link to comment Share on other sites More sharing options...
vekia Posted July 12, 2014 Share Posted July 12, 2014 it's based on ajax query turn on browser console, you will see there ajax requests with $_GET variables ajax query is defined in stores.js here is the url var searchUrl = baseUri+'?controller=stores&ajax=1&latitude=' + center.lat() + '&longitude=' + center.lng() + '&radius=' + radius; as you can see there are $_GET params 1 Link to comment Share on other sites More sharing options...
yari92 Posted July 12, 2014 Author Share Posted July 12, 2014 Thank you vekia. Solved. I didn't know this thing. I pass values appending these to searchUrl as radius is appended. Yari. Link to comment Share on other sites More sharing options...
vekia Posted July 13, 2014 Share Posted July 13, 2014 glad to hear that i could help a little :-) i marked topic as solved. with regards, Milos Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now