Chetanilead Posted June 4, 2014 Share Posted June 4, 2014 Hello All, I want to display all the categories added from the admin section on a front CMS page. Can anyone help me ? Its urgent. Thanks in advance. Link to comment Share on other sites More sharing options...
NemoPS Posted June 4, 2014 Share Posted June 4, 2014 I believe the only way to do it is by editing the cms controller, and if the cms page id matches the one you need, you can use Category::getCategories($id_lang) to get all of them. Assign to the tpl, and display inside cms.tpl is that smarty variable has been assigned Link to comment Share on other sites More sharing options...
Chetanilead Posted June 4, 2014 Author Share Posted June 4, 2014 Hi nemo1, Thanks for the quick reply . I am new to prestashop. Could you please clarify more? The Changes which U have suggested my affect the core files of prestashop right? If yes then is there any other way to implement it without modifying core scripts. Thanks Link to comment Share on other sites More sharing options...
NemoPS Posted June 4, 2014 Share Posted June 4, 2014 Well you can use override, it's a bit complex to explain in a forum topic, if you don't feel confident you may hire someone to do it for you from the paid jobs section Link to comment Share on other sites More sharing options...
Chetanilead Posted June 4, 2014 Author Share Posted June 4, 2014 If you can provide me some sample knowledge I am capable in doing that I have knowledge of other PHP frameworks and CMS. But I am new in prestashop Link to comment Share on other sites More sharing options...
vekia Posted June 4, 2014 Share Posted June 4, 2014 getCategories() function is static function so in .tpl file you can use foreach loop on Category::getCategories() something like: {foreach from=Category::getCategories() item=category} {$category.name}<br/> {/foreach} Link to comment Share on other sites More sharing options...
NemoPS Posted June 4, 2014 Share Posted June 4, 2014 Sure! check out this tut on overrides: http://doc.prestashop.com/display/PS15/Overriding+default+behaviors#Overridingdefaultbehaviors-Overridingacontroller You have to override the CMSController.php file, in override/controllers/front In the initContent method, check if Tools::getValue('id_cms') equals the id of the cms page you want the list to appear. If it does use Category::getCategories($id_lang) To get categories, then $this->context->smarty->assign('thevariablenameinsmarty',$categories_variable_name); Finally, inside cms.tpl (template folder) if $thevariablenameinsmarty is assigned, display categories Link to comment Share on other sites More sharing options...
Chetanilead Posted June 4, 2014 Author Share Posted June 4, 2014 (edited) I have studies and created a sample code in my_module\override\controllers\front\CmsController.php In which I have written following code <?phpclass MycmsController extends CmsControllerCore{ public function init() { $id_cms = (int)Tools::getValue('id_cms'); echo $id_cms; die; } public function initContent() { $id_cms = (int)Tools::getValue('id_cms'); echo $id_cms; die; } } I have also deleted the class_index.php file from cache folder but still not getting cms page id and it not event die(stops) the execution. Help me please Edited June 4, 2014 by Chetanilead (see edit history) Link to comment Share on other sites More sharing options...
NemoPS Posted June 5, 2014 Share Posted June 5, 2014 it has to be called cmsController, without "my" Link to comment Share on other sites More sharing options...
Chetanilead Posted June 5, 2014 Author Share Posted June 5, 2014 Thanks for the reply but it still not working for me <?phpclass cmsController extends CmsControllerCore{ public function init() { $id_cms = (int)Tools::getValue('id_cms'); echo $id_cms; die; } public function initContent() { $id_cms = (int)Tools::getValue('id_cms'); echo $id_cms; die; } } Link to comment Share on other sites More sharing options...
NemoPS Posted June 6, 2014 Share Posted June 6, 2014 Can you check if the override has been moved to main the override/controllers/front folder after installing the module? Link to comment Share on other sites More sharing options...
Chetanilead Posted June 6, 2014 Author Share Posted June 6, 2014 I have checked that and it is not moved into that folder . It contains only a single file index.php :( Link to comment Share on other sites More sharing options...
NemoPS Posted June 6, 2014 Share Posted June 6, 2014 Try reinstalling the module. If it doesn't move yet, move it manually and clear the class index Link to comment Share on other sites More sharing options...
Chetanilead Posted June 20, 2014 Author Share Posted June 20, 2014 Hi Nemo thanks for your reply it worked for me but I forgot to thank you. I have a new query in this How can I load a tpl or php file when my CMS page is called. Thanks in advance Link to comment Share on other sites More sharing options...
Chetanilead Posted June 23, 2014 Author Share Posted June 23, 2014 Hi I have used $categories = Category::getCategories(); to get all categories it is working fine for me but I didn't get category image on the tpl file can you please let me know how can I get that image. I am also not getting $category.id_image parameter to get image I got this array for each category : [infos] => Array([id_category] => 13[id_parent] => 2[id_shop_default] => 1[level_depth] => 2[nleft] => 3[nright] => 4[active] => 1[date_add] => 2014-05-23 01:58:27[date_upd] => 2014-05-28 02:30:24[position] => 1[is_root_category] => 0[id_shop] => 1[id_lang] => 1[name] => Appearance Protection Packages[description] =>[link_rewrite] => appearance-protection-packages[meta_title] =>[meta_keywords] =>[meta_description] =>) How can I get image for this category please help. Link to comment Share on other sites More sharing options...
NemoPS Posted June 24, 2014 Share Posted June 24, 2014 Like this: {$link->getCatImageLink($category->link_rewrite, $category->id_image, 'category')} Link to comment Share on other sites More sharing options...
godlo Posted November 23, 2016 Share Posted November 23, 2016 getCategories() function is static function so in .tpl file you can use foreach loop on Category::getCategories() something like: {foreach from=Category::getCategories() item=category} {$category.name}<br/> {/foreach} in this way the only thing to override is the .tpl and not the cmsController.php? Link to comment Share on other sites More sharing options...
NemoPS Posted November 23, 2016 Share Posted November 23, 2016 Correct, but I would not use logic in templates like that honestly 1 Link to comment Share on other sites More sharing options...
mhdcasa Posted July 14, 2017 Share Posted July 14, 2017 hello ALL i want disppaly all parent category in cms pge and i did all step before but i cant see an result can you help me ? Link to comment Share on other sites More sharing options...
zenerry Posted September 29, 2019 Share Posted September 29, 2019 On 7/14/2017 at 11:23 AM, mhdcasa said: hello ALL i want disppaly all parent category in cms pge and i did all step before but i cant see an result can you help me ? Hello did you solve that? I know it's been a long time ago but, I'm trying to do the same now in prestashop 1.7.5.1. @Chetanilead would it be possible to get the module you developed? Thanks. 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