Marwen Posted June 18, 2016 Share Posted June 18, 2016 I am designing a web shop and would like to know if (and how) it is possible to redirect those who visit the website to the product page of the product that was added most recently. Does anyone know if that can be done (I do not want to redirect to a certain product ID but always to the newest product, whichever product id that might have). Thanks for your help! Marwen Link to comment Share on other sites More sharing options...
NemoPS Posted June 20, 2016 Share Posted June 20, 2016 You can try with a custom query in the front controller (init method)$last_id = Db::getInstance()->getValue('SELECT MAX(id_product) FROM '._DB_PREFIX_.'product');Tools:redirect($this->context->link->getProductLink($last_id));Didn't test it, but should work Link to comment Share on other sites More sharing options...
Marwen Posted June 27, 2016 Author Share Posted June 27, 2016 You can try with a custom query in the front controller (init method) $last_id = Db::getInstance()->getValue('SELECT MAX(id_product) FROM '._DB_PREFIX_.'product'); Tools:redirect($this->context->link->getProductLink($last_id)); Didn't test it, but should work Thank you for your answer. I have tried it, but it doesn't work. I'm sure I did something wrong. I am quite new at changing/adding code, so could you help me by explaining exactly where I should paste the code you provided? Thanks again! Link to comment Share on other sites More sharing options...
NemoPS Posted June 27, 2016 Share Posted June 27, 2016 What did you do, exactly? Link to comment Share on other sites More sharing options...
Marwen Posted June 27, 2016 Author Share Posted June 27, 2016 What did you do, exactly? I looked in the front controllers which file it should go in and finally added the code to the ïndexcontroller.php, but I am sure i missed something... Link to comment Share on other sites More sharing options...
NemoPS Posted June 29, 2016 Share Posted June 29, 2016 IndexController must extend IndexControllerCore, not the product one. After you fix it, clear cache, it will run Link to comment Share on other sites More sharing options...
Marwen Posted July 5, 2016 Author Share Posted July 5, 2016 IndexController must extend IndexControllerCore, not the product one. After you fix it, clear cache, it will run Thanks, I am getting closer to what I want. I get the newest product now, but I have trouble filtering the disabled products. Any idea what code to use to include only the Enabled products? So, the newest product that is active... I tried to include WHERE 'Active' = '1' , but could not get it to work. What I have now (without the conditional active) is: public function initContent() { parent::initContent(); $lastproduct_id=Db::getInstance()->getValue('SELECT MAX(id_product) FROM '._DB_PREFIX_.'product'); Tools::redirect('index.php?id_product='.$lastproduct_id.'&controller=product'); $this->context->smarty->assign('HOOK_HOME', Hook::exec('displayHome')); $this->setTemplate(_PS_THEME_DIR_.'index.tpl'); } } Thanks again! Link to comment Share on other sites More sharing options...
NemoPS Posted July 6, 2016 Share Posted July 6, 2016 the condition is really active = 1, you have no condition right now. active is all underscore 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