dpcdpc11 Posted March 16, 2015 Share Posted March 16, 2015 (edited) In this tutorial I'll show you how to fix one of the features missing in PS. The problem: Every time I develop an online store, at some point the client wants a custom Contact page that they can easily edit whether they need to change the address or add a new phone number or edit the business hours. Unfortunately PS doesn't come with such an option out of the box which I personally find pretty weird! The solution: Adding in the contact-form.tpl the content of a CMS Page which can easily be edited in the back office. Steps: - create a CMS Page in the back office and fill it with everything you want to be displayed on the Contact page - write down the page ID (for example: 5) - override the ContactController, mainly overriding the initContent() function. - to override the ContactController create a new file called ContactController.php and copy it to root\override\controllers\front\ - paste the code from the attached file in the new ContactController.php: - as you can see, just before: $this->setTemplate(_PS_THEME_DIR_.'contact-form.tpl');I've added:global $cookie;$cms = new CMS(5, intval($cookie->id_lang));if (Validate::isLoadedObject($cms))$this->context->smarty->assign('content', $cms->content);where the 5 is the ID of the CMS Page created in the Back Office.- now go in your theme folder and edit contact-form.tpl by adding {$content}where ever you want the CMS's page content to show up.- if you want to split the Contact content in half then I suggest something like this: <div class="contact_page_left">{$content}</div><div class="contact_page_right">the whole code related to the contact form</div>- then style the 2 css classes however you like. I hope this helps! CREDITS: goes out to rocky of course, the PS Legend for pointing out the solution here: https://www.prestashop.com/forums/topic/79566-solved-include-a-cms-page-into-the-template/?p=446547 contactController.php Edited November 1, 2015 by dpcdpc11 (see edit history) 9 Link to comment Share on other sites More sharing options...
Cesar Machado Posted June 29, 2015 Share Posted June 29, 2015 Congratulations, this change is very helpful, and very easy to adapt CMS to other locations. Thank you. Link to comment Share on other sites More sharing options...
dpcdpc11 Posted July 6, 2015 Author Share Posted July 6, 2015 You're welcome! Glad I could help! Link to comment Share on other sites More sharing options...
koyocik Posted August 13, 2015 Share Posted August 13, 2015 (edited) (...) - paste the following code in the new ContactController.php: CODE - as you can see, just before: $this->setTemplate(_PS_THEME_DIR_.'contact-form.tpl'); I've added: global $cookie; $cms = new CMS(5, intval($cookie->id_lang)); if (Validate::isLoadedObject($cms)) $this->context->smarty->assign('content', $cms->content); where the 5 is the ID of the CMS Page created in the Back Office.(...) Hmm, can you please paste all the code again? Its quite not visible, thanks. Edited August 13, 2015 by koyocik (see edit history) Link to comment Share on other sites More sharing options...
dpcdpc11 Posted August 13, 2015 Author Share Posted August 13, 2015 What exactly is it not visible? I can clearly see all the code. Link to comment Share on other sites More sharing options...
koyocik Posted August 13, 2015 Share Posted August 13, 2015 Probably I'm not getting something.. Link to comment Share on other sites More sharing options...
Eutanasio Posted November 1, 2015 Share Posted November 1, 2015 Just what I was looking for! but @koyocik is right, where's the code? Link to comment Share on other sites More sharing options...
dpcdpc11 Posted November 1, 2015 Author Share Posted November 1, 2015 (edited) Just what I was looking for! but @koyocik is right, where's the code? I've edited the first post. For some reason the original code was removed. Maybe it was too much code... Dunno. Use the php file attached to the first post and let me know if it works. Btw are you Romanian? You're username looks familiar. Edited November 1, 2015 by dpcdpc11 (see edit history) Link to comment Share on other sites More sharing options...
Eutanasio Posted November 1, 2015 Share Posted November 1, 2015 I've edited the first post. For some reason the original code was removed. Maybe it was too much code... Dunno. Use the php file attached to the first post and let me know if it works. Btw are you Romanian? You're username looks familiar. Great! thanks for sharing. And not, I'm spanish Link to comment Share on other sites More sharing options...
dpcdpc11 Posted November 1, 2015 Author Share Posted November 1, 2015 You're welcome my friend! Link to comment Share on other sites More sharing options...
Eutanasio Posted November 1, 2015 Share Posted November 1, 2015 Unfortunately, as I see in the code, I'm not sure it will be compatible with PS 1.6.1. The original code of the controller may have changed since you did this override Link to comment Share on other sites More sharing options...
dpcdpc11 Posted November 1, 2015 Author Share Posted November 1, 2015 That's why I explained what I did so people could take the principle and adapt it to their needs. If you know a bit about prestashop than you should know how to overwrite a core controller and add the code I mentioned above, that starts with global $cookie etc. Do some thinking my friend and try to figure out what to do. It's not hard since I've explained the logic. 1 Link to comment Share on other sites More sharing options...
Eutanasio Posted November 1, 2015 Share Posted November 1, 2015 Great! you were just RIGHT! I just felt overwhelmed with all that code, but it was quiet an easy hack to do. Thank you! Link to comment Share on other sites More sharing options...
nt2015 Posted December 27, 2015 Share Posted December 27, 2015 Hi, I need some help.. i have followed your instructions, I am using Prestashop 1.6.1.3, and very new to this coding.. I went to public_html -> controllers -> front -> ContactController.php and added: global $cookie;$cms = new CMS(6, intval($cookie->id_lang));if (Validate::isLoadedObject($cms))$this->context->smarty->assign('content', $cms->content); and then to public_html ->themes -> defaultbootstrap->ContactForm.tpl and added: {$content} When i go to contacts page, only the contact form shows no sign of cms page. Do I need to add anything else in {$Content}? Am i adding the codes in the right file? I do apologize in advance for the trouble but if you have the time can you please help me? Link to comment Share on other sites More sharing options...
yaniv14 Posted December 27, 2015 Share Posted December 27, 2015 Try deleting class_index.php in cache folder 1 Link to comment Share on other sites More sharing options...
NielsTy Posted February 26, 2016 Share Posted February 26, 2016 (edited) Works for 1.6.1.4 dpcdpc11, you are a hero! Thanks for this wonderful guide!yaniv14, you are a hero too for adding that last hint!!! Edited February 26, 2016 by NielsTy (see edit history) Link to comment Share on other sites More sharing options...
dpcdpc11 Posted February 26, 2016 Author Share Posted February 26, 2016 You're welcome Niels! Link to comment Share on other sites More sharing options...
David S Johnston Posted March 2, 2016 Share Posted March 2, 2016 Works for 1.6.1.4 dpcdpc11, you are a hero! Thanks for this wonderful guide! yaniv14, you are a hero too for adding that last hint!!! NielsTy, did you follow dpcdpc11's instuctions to the letter or did you have to change anything for it to work in 1.6.1.4? I have followed the instuctions, but when I put contactcontroller.php in the overrides folder, my contact page is completely blank. I saw dpcdpc11's comment that it might need to be changed, but alas, this is beyond me. I consider this to be a very interesting hack, and I would love to use it, but no joy so far... Regards, Dave. Link to comment Share on other sites More sharing options...
NielsTy Posted March 11, 2016 Share Posted March 11, 2016 David, I followed the instructions from dpcdpc11, and it didn't work for me in the beginning.However, yaniv14's suggestion about removing the class_index.php in the cache folder, made it work! So, try that! Link to comment Share on other sites More sharing options...
David S Johnston Posted March 11, 2016 Share Posted March 11, 2016 Thanks Niels, I'll give it another try! I'll let you all know if it worked or not. Link to comment Share on other sites More sharing options...
David S Johnston Posted March 11, 2016 Share Posted March 11, 2016 Hi all, - I pasted dpcdpc11 's code into /overides/controllers/front and made the change necessary, i.e. changed 5 to 22, as this is the index of my cms page. - I then added {content} to the contact-form.tpl in my themes folder - I deleted class-index.php from the cache folder. but... when I now go to look at the contact page (where the form is located) All I get is a blank screen. Is it possible that I am putting {content} in the wrong place in the contact-form.tpl?? Any help appreciated Dave. Link to comment Share on other sites More sharing options...
NielsTy Posted March 11, 2016 Share Posted March 11, 2016 (edited) I put that in the top of the contact-form.tpl, right after </h1>: {capture name=path}{l s='Contact'}{/capture} <h1 class="page-heading bottom-indent"> {l s='Customer service'} - {if isset($customerThread) && $customerThread}{l s='Your reply'}{else}{l s='Contact us'}{/if} </h1> {$content} Edited March 11, 2016 by NielsTy (see edit history) Link to comment Share on other sites More sharing options...
David S Johnston Posted March 11, 2016 Share Posted March 11, 2016 Hi, The only way to get rid of the blank page is when I rename/remove the new contactcontroller.php in override/controllers/front file. So as far as I can see it just doens't work for me, for some reason. Are there any other prerequisites? Dave. Link to comment Share on other sites More sharing options...
David S Johnston Posted March 11, 2016 Share Posted March 11, 2016 Thanks Niels, That is where I put it too, but no joy! Dave. Link to comment Share on other sites More sharing options...
NielsTy Posted March 11, 2016 Share Posted March 11, 2016 (edited) Did you use the attached file from dpcdpc11, or did you create a copy of your own? (ContactController.php)I created a copy, as the attachment is for earlier version of PS... Edited March 11, 2016 by NielsTy (see edit history) Link to comment Share on other sites More sharing options...
David S Johnston Posted March 11, 2016 Share Posted March 11, 2016 Niels, I was just looking at the two files when your reply came in. I see that they are indeed very different (the default theme contactcontroller.php) and the one dpcdpc11 posted. I wouldn't have a clue as to where to start looking to modify the current one to include dpcdpc11's modifications. Regards, and thanks for your input, Dave. Link to comment Share on other sites More sharing options...
NielsTy Posted March 11, 2016 Share Posted March 11, 2016 As you also uses PS 1.6.1.4, i guess you can use the file I have... however, i have no clue how to attach a file here Do you know? You can also send me your email address in private message, and i will send you ContactController.php Niels Link to comment Share on other sites More sharing options...
David S Johnston Posted March 11, 2016 Share Posted March 11, 2016 Much appreciated Niels, PM sent as I can also can't find how to add an attachment. dave. Link to comment Share on other sites More sharing options...
David S Johnston Posted March 11, 2016 Share Posted March 11, 2016 Niels, it works a treat. Although I just spent the last hour and a half in despair that it wasn't working........apparently I was making changes on the test site, but viewing the live site front end......:-( Thanks a million my friend! Dave. Link to comment Share on other sites More sharing options...
NielsTy Posted March 11, 2016 Share Posted March 11, 2016 Hahaha... what a bummer !Glad it worked out for you in the end, and glad to help Niels Link to comment Share on other sites More sharing options...
Guest locen Posted April 1, 2016 Share Posted April 1, 2016 Hi, I have problems when i add image in cms page. i can't add image by click but i should follow these passages to insert images. can someone help me? Link to comment Share on other sites More sharing options...
kupisait Posted May 10, 2016 Share Posted May 10, 2016 Works like a charm! Thank you! Link to comment Share on other sites More sharing options...
dpcdpc11 Posted May 10, 2016 Author Share Posted May 10, 2016 Works like a charm! Thank you! You're welcome my friend! Link to comment Share on other sites More sharing options...
hotekern Posted May 13, 2016 Share Posted May 13, 2016 I'm using Prestashop 1.6.1.5 but I'm getting a white screen on the contact page. Link to comment Share on other sites More sharing options...
vekia Posted May 14, 2016 Share Posted May 14, 2016 I'm using Prestashop 1.6.1.5 but I'm getting a white screen on the contact page. and what you exactly did? Link to comment Share on other sites More sharing options...
akps1234 Posted June 6, 2016 Share Posted June 6, 2016 Great Tutorial ! Very Helpful. Thanks a lot. Cheers. Link to comment Share on other sites More sharing options...
aleXoid Posted July 29, 2016 Share Posted July 29, 2016 I'm using Prestashop 1.6.1.5 but I'm getting a white screen on the contact page. Just rename contactController.php to СontactController.php Link to comment Share on other sites More sharing options...
hay706 Posted October 7, 2016 Share Posted October 7, 2016 - I pasted dpcdpc11 's code into /overides/controllers/front and made the change necessary, i.e. changed 5 to 22, as this is the index of my cms page. - I then added {content} to the contact-form.tpl in my themes folder - I deleted class-index.php from the cache folder. Did exactly the same as this user although my cms content does not load on the contact page. Any ideas? Link to comment Share on other sites More sharing options...
milanleft Posted December 31, 2016 Share Posted December 31, 2016 (edited) It works for me on http://aranciaonline.it! Thank you so much! Edited December 31, 2016 by milanleft (see edit history) Link to comment Share on other sites More sharing options...
Blessy_Preferred Posted June 8, 2017 Share Posted June 8, 2017 It works! Thank you so much! Using PS 1.6.1.11 Link to comment Share on other sites More sharing options...
Sharak Posted October 27, 2017 Share Posted October 27, 2017 Overriding whole core controllers may cause many problems. It should only override specific actions. Here's much simpler and much safer solution: 1. File /override/controllers/front/ContactController.php should have this content only : <?php class ContactController extends ContactControllerCore { public function initContent() { parent::initContent(); $this->context->smarty->assign(array( 'cms' => CMS::getCMSContent('7', $this->context->language->id), // where 7 is ID of CMS page )); } } 2. In /themes/<your_theme>/contact-form.tpl add wherever you want your cms content: <div class="rte">{$cms.content}</div> Link to comment Share on other sites More sharing options...
Sharak Posted February 22, 2018 Share Posted February 22, 2018 (edited) My previous solution works in every other page, but stopped working with ContactController.php on presta 1.6.1.18. It works if I add 'cms' => CMS::getCMSContent('7', $this->context->language->id) directly in /controllers/front/ContactController.php. It looks like overriding of this controller is impossible now. Can anyone confirm or have a fix for this? E: The solution is to force compilation and clear cache once Edited December 1, 2018 by Sharak (see edit history) 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