Jump to content

Adding to FrontController.php


Recommended Posts

So I need to install a maintenance module but it has a conflict with my themes override frontcontroller.php. After deleting the front controller I was able to install the maint module but it still brings up the default prestashop maint page when I check. Even after putting back the override frontcontroller.php from my theme its the same outcome. So I assumed that I had to somehow embed the code for my maint modules frontcontroller to the themes frontcontroller, since they both are going to override the default prestashop frontcontroller. I went ahead and found this page for prestashops override information http://doc.prestashop.com/display/PS15/Overriding+default+behaviors

 

But even after reading that and attempting it my self I still haven't managed to make the maint page come up. Anybody got any ideas?

 

Maintenance Module FrontController.php overrride file is here.

<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <contact@prestashop.com>
*  @copyright  2007-2013 PrestaShop SA
*  @licensehttp://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/

class FrontController extends FrontControllerCore {
	
    public $shortname = "spmt";
    public $contact_success;
    public $error, $success;
    function __construct() {
        parent::__construct();
    }
    function init() {
        parent::init();
    }
    protected function displayMaintenancePage() {
          if (Tools::getValue('action')=='0' && Tools::isSubmit('action')){
             $this->newsletterRegistration();
          }else if (Tools::getValue('contact-frm')=='1' && Tools::isSubmit('contact-frm')) {
                $this->sendMail();
          }
        $msg = count($this->success);
        if ($this->maintenance == true || !(int) Configuration::get('PS_SHOP_ENABLE')) {
            $this->maintenance = true;
            if (!in_array(Tools::getRemoteAddr(), explode(',', Configuration::get('PS_MAINTENANCE_IP')))) {
                $default_lang = (int) $this->context->language->id;
                $sds_pm_news = Db::getInstance()->ExecuteS('SELECT * FROM  `' . _DB_PREFIX_ . 'smartmaintanacenews` AS main
                    INNER JOIN  `' . _DB_PREFIX_ . 'smartmaintanacenews_lang` AS main_ln ON
                        main.`id_smartmaintanacenews` = main_ln.`id_smartmaintanacenews` and main_ln.id_lang = ' . $default_lang.'
                        INNER JOIN  `' . _DB_PREFIX_ . 'smartmaintanacenews_shop` AS main_sp ON main_sp.id_smartmaintanacenews = main.id_smartmaintanacenews and main_sp.id_shop = '.(int) Context::getContext()->shop->id.'');
                $sds_presta_maintanace_secure_key = Configuration::get($this->shortname . 'secure_key');
                $sds_presta_maintanace_launch_flickr_url = Configuration::get($this->shortname . 'launch_flickr_url');
                $sds_presta_maintanace_launch_facebook_url = Configuration::get($this->shortname . 'launch_facebook_url');
                $sds_presta_maintanace_launch_twitter_url = Configuration::get($this->shortname . 'launch_twitter_url');
                $sds_presta_maintanace_launch_rss_url = Configuration::get($this->shortname . 'launch_rss_url');
                $sds_presta_maintanace_launch_google_analytics = Configuration::get($this->shortname . 'launch_google_analytics');
                $sds_presta_maintanace_launch_show_timer = Configuration::get($this->shortname . 'launch_show_timer');
                $sds_presta_maintanace_launch_date = Configuration::get($this->shortname . 'launch_date');
                $sds_presta_maintanace_launch_info_heading = Configuration::get($this->shortname . 'launch_info_heading');
                $sds_presta_maintanace_launch_info_text = Configuration::get($this->shortname . 'launch_info_text');
                $sds_presta_maintanace_launch_subscribe_url = Configuration::get($this->shortname . 'launch_subscribe_url');
                $sds_presta_maintanace_launch_subscribe_email_name = Configuration::get($this->shortname . 'launch_subscribe_email_name');
                $sds_presta_maintanace_launch_twitter_heading = Configuration::get($this->shortname . 'launch_twitter_heading');
                $sds_presta_maintanace_launch_twitter_username = Configuration::get($this->shortname . 'launch_twitter_username');
                $sds_presta_maintanace_launch_news_title = Configuration::get($this->shortname . 'launch_news_title');
                $sds_presta_maintanace_launch_contact_title = Configuration::get($this->shortname . 'launch_contact_title');
                $sds_presta_maintanace_launch_company_name = Configuration::get($this->shortname . 'launch_company_name');
                $sds_presta_maintanace_launch_address = Configuration::get($this->shortname . 'launch_address');
                $sds_presta_maintanace_launch_contact_email = Configuration::get($this->shortname . 'launch_contact_email');
                $sds_presta_maintanace_launch_phone = Configuration::get($this->shortname . 'launch_phone');
                $sds_presta_maintanace_launch_copyright_text = Configuration::get($this->shortname . 'launch_copyright_text');
                $sds_presta_maintanace_bgslider_enable = Configuration::get($this->shortname . 'bgslider_enable');
                $sds_presta_maintanace_bgslider_img1 = Configuration::get($this->shortname . 'bgslider_img1');
                $sds_presta_maintanace_bgslider_img2 = Configuration::get($this->shortname . 'bgslider_img2');
                $sds_presta_maintanace_bgslider_img3 = Configuration::get($this->shortname . 'bgslider_img3');
                $sds_presta_maintanace_bgslider_img4 = Configuration::get($this->shortname . 'bgslider_img4');
                $sds_presta_maintanace_speed = Configuration::get($this->shortname . 'speed');
                $sds_presta_maintanace__slider_style = Configuration::get($this->shortname . '_slider_style');
                $sds_presta_maintanace_interval = Configuration::get($this->shortname . 'interval');
                $this->context->smarty->assign('contact_success', $this->contact_success);
                $this->context->smarty->assign('sds_presta_maintanace_secure_key', $sds_presta_maintanace_secure_key);
                $this->context->smarty->assign('sds_presta_maintanace_launch_flickr_url', $sds_presta_maintanace_launch_flickr_url);
                $this->context->smarty->assign('sds_presta_maintanace_launch_facebook_url', $sds_presta_maintanace_launch_facebook_url);
                $this->context->smarty->assign('sds_presta_maintanace_launch_twitter_url', $sds_presta_maintanace_launch_twitter_url);
                $this->context->smarty->assign('sds_presta_maintanace_launch_rss_url', $sds_presta_maintanace_launch_rss_url);
                $this->context->smarty->assign('sds_presta_maintanace_launch_google_analytics', $sds_presta_maintanace_launch_google_analytics);
                $this->context->smarty->assign('sds_presta_maintanace_launch_show_timer', $sds_presta_maintanace_launch_show_timer);
                $this->context->smarty->assign('sds_presta_maintanace_launch_date', $sds_presta_maintanace_launch_date);
                $this->context->smarty->assign('sds_presta_maintanace_launch_info_heading', $sds_presta_maintanace_launch_info_heading);
                $this->context->smarty->assign('sds_presta_maintanace_launch_info_text', $sds_presta_maintanace_launch_info_text);
                $this->context->smarty->assign('sds_presta_maintanace_launch_subscribe_url', $sds_presta_maintanace_launch_subscribe_url);
                $this->context->smarty->assign('sds_presta_maintanace_launch_subscribe_success_message', $this->success);
                $this->context->smarty->assign('sds_presta_maintanace_launch_subscribe_error_message', $this->error);
                $this->context->smarty->assign('sds_presta_maintanace_launch_subscribe_email_name', $sds_presta_maintanace_launch_subscribe_email_name);
                $this->context->smarty->assign('sds_presta_maintanace_launch_twitter_heading', $sds_presta_maintanace_launch_twitter_heading);
                $this->context->smarty->assign('sds_presta_maintanace_launch_twitter_username', $sds_presta_maintanace_launch_twitter_username);
                $this->context->smarty->assign('sds_presta_maintanace_launch_news_title', $sds_presta_maintanace_launch_news_title);
                $this->context->smarty->assign('sds_presta_maintanace_launch_contact_title', $sds_presta_maintanace_launch_contact_title);
                $this->context->smarty->assign('sds_presta_maintanace_launch_company_name', $sds_presta_maintanace_launch_company_name);
                $this->context->smarty->assign('sds_presta_maintanace_launch_address', $sds_presta_maintanace_launch_address);
                $this->context->smarty->assign('sds_presta_maintanace_launch_contact_email', $sds_presta_maintanace_launch_contact_email);
                $this->context->smarty->assign('sds_presta_maintanace_launch_phone', $sds_presta_maintanace_launch_phone);
                $this->context->smarty->assign('sds_presta_maintanace_launch_copyright_text', $sds_presta_maintanace_launch_copyright_text);
                $this->context->smarty->assign('sds_presta_maintanace_bgslider_enable', $sds_presta_maintanace_bgslider_enable);
                $this->context->smarty->assign('sds_presta_maintanace_bgslider_img1', $sds_presta_maintanace_bgslider_img1);
                $this->context->smarty->assign('sds_presta_maintanace_bgslider_img2', $sds_presta_maintanace_bgslider_img2);
                $this->context->smarty->assign('sds_presta_maintanace_bgslider_img3', $sds_presta_maintanace_bgslider_img3);
                $this->context->smarty->assign('sds_presta_maintanace_bgslider_img4', $sds_presta_maintanace_bgslider_img4);
                $this->context->smarty->assign('sds_presta_maintanace_speed', $sds_presta_maintanace_speed);
                $this->context->smarty->assign('sds_presta_maintanace__slider_style', $sds_presta_maintanace__slider_style);
                $this->context->smarty->assign('sds_presta_maintanace_interval', $sds_presta_maintanace_interval);
                $this->context->smarty->assign('sds_presta_maintanace_launch_info', Configuration::get($this->shortname . 'launch_info_enable'));
                $this->context->smarty->assign('sds_presta_maintanace_launch_twitter_feed', Configuration::get($this->shortname . 'twitter_feed_enable'));
                $this->context->smarty->assign('sds_presta_maintanace_launch_news_updates', Configuration::get($this->shortname . 'news_and_updates_enable'));
                $this->context->smarty->assign('sds_presta_maintanace_launch_contact_enable', Configuration::get($this->shortname . 'contact_enable'));
                $this->context->smarty->assign('sds_presta_maintanace_slider_wrap', Configuration::get($this->shortname . 'slider_wrap'));
                $logo = _PS_IMG_ . Configuration::get('PS_LOGO') . '?' . Configuration::get('PS_IMG_UPDATE_TIME');
                $this->context->smarty->assign('favicon_url', _PS_IMG_ . Configuration::get('PS_FAVICON'));
                $this->context->smarty->assign('logo_url', $logo);
                $this->context->smarty->assign('sds_pm_news', $sds_pm_news);
                self:: $this->context->smarty->display(_PS_MODULE_DIR_ . 'smartmaintanacemode/views/templates/front/maintenance.tpl');
                exit;
            }
        }
    }
    private function isNewsletterRegistered($customerEmail) {
        if (Db::getInstance()->getRow('SELECT `email` FROM ' . _DB_PREFIX_ . 'newsletter WHERE `email` = \'' . pSQL($customerEmail) . '\''))
            return 1;
        if (!$registered = Db::getInstance()->getRow('SELECT `newsletter` FROM ' . _DB_PREFIX_ . 'customer WHERE `email` = \'' . pSQL($customerEmail) . '\''))
            return -1;
        if ($registered['newsletter'] == '1')
            return 2;
        return 0;
    }
    private function newsletterRegistration() {
       if (Tools::getValue('action')=='0' && Tools::isSubmit('action')){
            $register_status = $this->isNewsletterRegistered(Tools::getValue('EMAIL'));
            $email = pSQL(Tools::isSubmit('EMAIL'));
            if ($register_status > 0)
                $this->error = 'E-mail address already registered';
            elseif ($register_status == -1) {
                if (version_compare(_PS_VERSION_, '1.5', '<')) {
                    if (!Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'newsletter (email, newsletter_date_add, ip_registration_newsletter, http_referer) VALUES (\'' . pSQL(Tools::getValue('EMAIL')) . '\', NOW(), \'' . pSQL(Tools::getRemoteAddr()) . '\',
					    (SELECT c.http_referer FROM ' . _DB_PREFIX_ . 'connections c WHERE c.id_guest = ' . (int) ($this->context->cookie->id_guest) . ' ORDER BY c.date_add DESC LIMIT 1))'))
                        $this->error = 'Error during subscription';
                }else {
                    if (!Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'newsletter (email, newsletter_date_add, ip_registration_newsletter, http_referer, active) VALUES (\'' . pSQL(Tools::getValue('EMAIL')) . '\', NOW(), \'' . pSQL(Tools::getRemoteAddr()) . '\',
					    (SELECT c.http_referer FROM ' . _DB_PREFIX_ . 'connections c WHERE c.id_guest = ' . (int) ($this->context->cookie->id_guest) . ' ORDER BY c.date_add DESC LIMIT 1), 1)'))
                        $this->error = 'Error during subscription';
                }
                $this->success = "Subscription successful";
            }
        }
    }
       private function sendMail()
        {
        if (Tools::getValue('contact-frm')=='1' && Tools::isSubmit('contact-frm'))
         {

	

	$name =  Tools::stripslashes(Tools::getValue('name'));
	 $e_body ='You have Received a Message From '. $name . ' their additional message is as follows.';
	$emailAddr =  Tools::stripslashes(Tools::getValue('email'));
	$comment =  Tools::stripslashes(Tools::getValue('message'));
	$subject =  Tools::stripslashes($e_body);
	$id_lang =$this->context->language->id;	
	$to =  Tools::getValue('address')==""?Configuration::get('PS_SHOP_EMAIL'): Tools::getValue('address');
	 
	$contactMessage =  
		"
		$comment 

		Name: $name

		IP: ".((version_compare(_PS_VERSION_, '1.3.0.0', '<'))?$_SERVER['REMOTE_ADDR']:Tools::getRemoteAddr());
		
		//send the email 
		if(Mail::Send($id_lang,
			'contact',
			$subject,
			array(
				'{message}' => nl2br($contactMessage),
				'{email}' =>  $emailAddr,
			),
			$to,
			null,
			$emailAddr,
			$name
		))
		 $this->contact_success = 'Message Sent Successfully!';; //return success callback
			
 
       //      else
           //   $this->contact_success = 'Server Error: Mailing Method Failed!';
                
        }
        }
}
?>

Themes FrontController.php override file is here.

<?php

class FrontController extends FrontControllerCore
{

	/*
	* module: belvg_staticblocks
	* date: 2015-02-07 23:17:09
	* version: 2.0.0
	*/
    public function init()
    {
       require_once _PS_MODULE_DIR_ . 'belvg_staticblocks/classes/BelvgStaticBlocks.php';
        if (!self::$initialized) {
            global $smarty;
            smartyRegisterFunction($smarty, 'function', 'getBelvgBlockContent', array('BelvgStaticBlocks', 'getBlockContent'));
            smartyRegisterFunction($smarty, 'function', 'getBelvgBlockTitle', array('BelvgStaticBlocks', 'getBlockTitle'));
        } 
        parent::init();
    }
}
Link to comment
Share on other sites

  On 2/8/2015 at 10:33 AM, funstad said:

 

Since your are developing you could try this to see the instant result of your work.

 

1. Hover on Advanced Parameters

2. Click on Performance

3. set "Cache" to no

 

This will allow you to see all changes you make instant

put it back on when your site is back online.

 

I'm not sure what thats supposed to do because nothing really happened after turning catch to no. I just need to know how to make my modules frontcontroller.php override work with my themes frontcontroller.php overrride.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...