Child pages
  • Overriding default behaviors

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In order to override the Product class, your file needs to be called Product.php and must feature a Product class that the then extends ProductCore class.

The file can be placed in either of these locations:

...

In order to override the ProductController class, your file needs to be called ProductController.php and must feature a ProductController class that the then extends ProductControllerCore class.

...

PrestaShop has certain files you can use to override elements such as displaying redirections (Tools.php) and measuring hook execution time (_Module.php), etc. you can enable them by removing the "_" prefix. For sintanceinstance, rename _Tools.php into Tools.php. If there already exists a Tools.php override, you will have to merge it with yours.

...

Code Block
/*
 * Create a cron task to make periodical database backup
*/
class AdminTab extends AdminTabCore{
	public function ajaxProcess()
	{			 
		// Here we call the same thing as if we did the old way
		// + with "if": maybe we want to limit its use to only adding backup
		// note: find yourself a way to get the file link if you want to send it by mail!
		if (isset($_REQUEST['addbackup']))
			return $this->postProcess();
	} 

	public function displayAjax()
	{
		if (sizeof($this->_errors) > 0)
		{
			// handle errors 
			// for example, send mail with all error msg
			$content = '';
			foreach($this->_errors as $errorMsg)
			 $content .= $errorMsg;

			 $lang = Configuration::get('PS_LANG_DEFAULT');
			 // here we send a mail to give the result of the process
			 // notice: you have to create template mails files
			 Mail::Send($lang, 'backuptaskdone', '[autobackup] report backup error', array('backup_link'=>)), $to); 
		}
		else
		{
			// no error, but maybe we want a mail ?
			if(Configuration::get('PS_NOTICE_SUCCEED_BACKUP')) 
			{
				// fileAttachment available, see 9th param of Send() method in classes/Mail.php
				// + we can add a condition "if (Configuration::get('PS_AUTOBACKUP_SEND_FILE'))"
				Mail::Send($lang, 'backuptaskerror', '[autobackup] report backup error', array('vars to use in tpl'), $to); 
			}
		}
	return true;
	}
}

...