Ray UK Posted December 6, 2013 Share Posted December 6, 2013 (edited) Hi, The store locator currently makes the array and sorted by store ID ? I would like it sorted by storename. Does anybody know how to do this, or where the script is that builds the array. see here: http://www.no-match.co.uk/stores I can click "A-Z" to sort them, but would like the default to be sorted. Thanks Edited December 7, 2013 by vekia (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted December 6, 2013 Share Posted December 6, 2013 you can do everything in Stores Controller file (controllers/front/StoresController.php) there is a code: public function getStores() { $distanceUnit = Configuration::get('PS_DISTANCE_UNIT'); if (!in_array($distanceUnit, array('km', 'mi'))) $distanceUnit = 'km'; 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); } else add there ORDER BY clause ORDER BY s.name 1 Link to comment Share on other sites More sharing options...
Ray UK Posted December 7, 2013 Author Share Posted December 7, 2013 Cheers Vekia, Im not too good at sql queries yet. Ive tried this but its not sorting by store name public function getStores() { $distanceUnit = Configuration::get('PS_DISTANCE_UNIT'); if (!in_array($distanceUnit, array('km', 'mi'))) $distanceUnit = 'km'; 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'); } It cant be far off can it. Link to comment Share on other sites More sharing options...
vekia Posted December 7, 2013 Share Posted December 7, 2013 just use this query: $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'); instead query in function: protected function 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); foreach ($stores as &$store) { $store['has_picture'] = file_exists(_PS_STORE_IMG_DIR_.(int)($store['id_store']).'.jpg'); if ($working_hours = $this->renderStoreWorkingHours($store)) $store['working_hours'] = $working_hours; } $this->context->smarty->assign(array( 'simplifiedStoresDiplay' => true, 'stores' => $stores )); } Link to comment Share on other sites More sharing options...
Ray UK Posted December 7, 2013 Author Share Posted December 7, 2013 You da man. Its working http://www.no-match.co.uk/stores Thanks Vekia Link to comment Share on other sites More sharing options...
vekia Posted December 7, 2013 Share Posted December 7, 2013 you're welcome i marked this 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