sipdorus Posted September 17, 2016 Share Posted September 17, 2016 Hello, I want to random change home slider images order. So everytime store opened sorting will be changed. I tried to edit code at modules/homeslider/homeslide.php like this public function reOrderPositions() { $id_slide = $this->id; $context = Context::getContext(); $id_shop = $context->shop->id; $max = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT MAX(hss.`position`) as position FROM `'._DB_PREFIX_.'homeslider_slides` hss, `'._DB_PREFIX_.'homeslider` hs WHERE hss.`id_homeslider_slides` = hs.`id_homeslider_slides` AND hs.`id_shop` = '.(int)$id_shop.' order by rand()' ); if ((int)$max == (int)$id_slide) return true; $rows = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT hss.`position` as position, hss.`id_homeslider_slides` as id_slide FROM `'._DB_PREFIX_.'homeslider_slides` hss LEFT JOIN `'._DB_PREFIX_.'homeslider` hs ON (hss.`id_homeslider_slides` = hs.`id_homeslider_slides`) WHERE hs.`id_shop` = '.(int)$id_shop.' AND hss.`position` > '.(int)$this->position.' order by rand()' ); foreach ($rows as $row) { $current_slide = new HomeSlide($row['id_slide']); --$current_slide->position; $current_slide->update(); unset($current_slide); } return true; } public static function getAssociatedIdsShop($id_slide) { $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT hs.`id_shop` FROM `'._DB_PREFIX_.'homeslider` hs WHERE hs.`id_homeslider_slides` = '.(int)$id_slide.' order by rand()' ); but nothing changed. How can I do this? Link to comment Share on other sites More sharing options...
rictools Posted September 17, 2016 Share Posted September 17, 2016 There's no bracket at the end, only here or in the original file too? Link to comment Share on other sites More sharing options...
sipdorus Posted September 17, 2016 Author Share Posted September 17, 2016 final bracket is at the line below. I only added .' order by rand()' to the code Link to comment Share on other sites More sharing options...
rocky Posted September 18, 2016 Share Posted September 18, 2016 You're changing the wrong function. You should undo your changes. It's the following on line 700 (in PrestaShop v1.6.1.7) of modules/homeslider/homeslider.php that you should change: ORDER BY hss.position' to: ORDER BY rand()' 1 Link to comment Share on other sites More sharing options...
sipdorus Posted September 18, 2016 Author Share Posted September 18, 2016 thanks rocky, it works great 1 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