Jump to content

How do I sort ps_store to show on site?


rialni

Recommended Posts

Hi,

 

I'm almost done with a new ps, but just at the finish line I'm running into an issue that I didn't think about from the beginning.

 

If you look here: http://byboysen.dk/prestashop/index.php?controller=stores you see a list of stores.

 

I would like this list to be sorted, first by country, second by post code. I'm trying to do it by phpmyadmin, but it's not reflected on the site how I sort the table directly in the database.

 

Does anyone know how I can do this?

 

Do you also know if it's possible for me to add a heading for each country section, when the above has been done? - if not it doesn't matter, the above is more essential for the shop :)

 

Thanks in advance

Link to comment
Share on other sites

Hi Rialni,

 

In storesController.php you have

 

if (Tools::getValue('all') == 1)
        {
            $stores = Db::getInstance()->executeS('
            SELECT s.*, cl.name country, st.iso_code state
            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);
        }

 

Modify it to

 

if (Tools::getValue('all') == 1)
        {
            $stores = Db::getInstance()->executeS('
            SELECT s.*, cl.name country, st.iso_code state
            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).' ORDER BY s.name' ;
        }

 

You can do this or make the same in a controller storesController.php override.

Best regards.

Link to comment
Share on other sites

Oops, yes quick fix without testing.

 

Then the good way is still in the same file but in protected function assignStoresSimplified() :

 

 

WHERE s.active = 1 AND cl.id_lang = '.(int)$this->context->language->id);

 

have to be modified to

 

WHERE s.active = 1 AND cl.id_lang = '.(int)$this->context->language->id.' ORDER BY s.name');
Link to comment
Share on other sites

I'm sorry to say, I still can't get it to work. I feel quite stupid right now. Why can't I Work this out? ;)

 

This is what my code looks like right now:

if (Tools::getValue('all') == 1)        
		{   
		$stores = Db::getInstance()->executeS('            
		SELECT s.*, cl.name country, st.iso_code state            
		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.' ORDER BY s.country, s.postcode');						        }

and thank you both for looking at this with me, by the way :) I really appreciate it :)

Link to comment
Share on other sites

It is ok,

Undo what you have done.

 

Search assignStoresSimplified()

 

 

$stores = Db::getInstance()->executeS('
        SELECT s.*, cl.name country, st.iso_code state
        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);

 

Then modify :)

 

$stores = Db::getInstance()->executeS('
        SELECT s.*, cl.name country, st.iso_code state
        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  .' ORDER BY country, s.postcode');
Link to comment
Share on other sites

I'm sorry to say, I still can't get it to work. I feel quite stupid right now. Why can't I Work this out? ;)

 

This is what my code looks like right now:

 

if (Tools::getValue('all') == 1)        
		{   
		$stores = Db::getInstance()->executeS('            
		SELECT s.*, cl.name country, st.iso_code state            
		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.' ORDER BY s.country, s.postcode');						        }
and thank you both for looking at this with me, by the way :) I really appreciate it :)

 

Ohhh, you were so close! See, only you had s.country instead of country :-)

 

Nice that it works!!

 

Happy selling,

pascal

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...