I would like to disable the contact form in my prestashop installation but there is no plugin to do so. Any suggestions how to do that?
Depends what you mean by disabling contact form but here are few possibilities.
Open file controllers/front/ContactController.php
and add this code inside the ContactControllerCode
class.
public function init()
{
Tools::redirect('pagenotfound'); // redirect contact page to 404 page
}
Create a new file ContactController.php
and place it in folder overrides/controllers/front/
and add the following code
class ContactController extends ContactControllerCore {
public function init()
{
Tools::redirect('pagenotfound'); // redirect contact page to 404 page
}
}
Create a new directory contactpagedisabler
in folder modules
and inside create a file contactpagedisabler.php
and put this code in
class ContactPageDisabler extends Module
{
public function __construct()
{
$this->name = 'contactpagedisabler';
$this->tab = 'front_office_features';
$this->version = '1.0';
$this->author = 'whatever';
parent::__construct();
$this->displayName = $this->l('Contact page disabler');
$this->description = $this->l('Disables contact page.');
}
public function install()
{
return parent::install() && $this->registerHook('actionDispatcher');
}
// hook runs just after controller has been instantiated
public function hookActionDispatcher($params)
{
if ($params['controller_type'] === 1 && $params['controller_class'] === 'ContactController') {
Tools::redirect('pagenotfound'); // redirect contact page to 404 page
}
}
}
And then install this module from backoffice.
2nd option is simplest and it doesn't interfere with core files.
3rd option is probably overkill for such a small thing however it doesn't require overriding and if you or store manager ever needs the contact page back he can just disable the module from backoffice. The module could also be expanded/modified with configuration page where you could for example get a list of all pages in store and let user decide which ones to enable/disable etc.
Update April 2018
Forget first two options and use third. Always use a module (if possible) when modifying your shop.