Jump to content

[SOLVED] problem with Tools::getValue Usage.


Recommended Posts

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,
				* acos(
					* 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>

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.


Edited by vekia (see edit history)
Link to comment
Share on other sites


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

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>
            <input type='submit' name='provaButton' value='Prova' />

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.


Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...