Jump to content

Overrides - Replacing setMedia to include Google's CDN jQuery

Mark Hesketh

Recommended Posts

Hi all,

I'm just starting to get to grips with overrides in 1.4.

However, I'm trying to add Google's CDN jQuery (1.5) script to Presta, replacing Presta's local jQuery 1.4, as well as including Modernizr for HTML5 detection and all that good stuff.

I've created /override/classes/FrontController.php and included the following:

class FrontController extends FrontControllerCore
   public function setMedia(){
       global $cookie;


This works, sort of. It will add my 2 additional scripts to the $js_files variable and include them in the <head> as you'd expect. So now I have 2 versions of jQuery being loaded which isn't ideal!

Is there a way to have my setMedia method override the original, and not simply add to it?

I realise I could edit the setMedia method in the original /classes/FrontController.php, but I'd like to get into good practice of understanding 1.4's overrides and never actually have to edit the core files again.

Thanks in advance,


Link to comment
Share on other sites

Thanks for the reply Angora,

Unfortunately I couldn't quite get that working, what I've done however is copy the whole /classes/FrontController.php into override/classes/FrontController.php.


class FrontControllerCore


class FrontController extends FrontControllerCore

to get the override working correctly as a child, and the setMedia method used in my override is used instead of the original, as opposed to in addition to as it was previously.

I'm guessing this has something to do with this from the original:

public function run()

I'll look at trimming it down at a later date, but for now this will get me going!

BTW, are you confident that jquery 1.5.1 is a drop-in replacement, fully backward compatible?

I've no idea ;) But then I'm currently working on a set of PrestaShops across different domains that use the same backend, so i'm using a pretty heavily modified Presta.

Its been an ongoing project with my client for over a year now, adding more and more stores. Just trying to get the latest on 1.4 as these overrides would be an immense help!

Thanks again!

Link to comment
Share on other sites

  • 2 years later...

unfortunatelly this breaks CCC (combine, compress and cache) functionality for joining multiple .js files into one.


my solution was to:


1. delete default jquery invocation:


in override/classes/FrontController.php


class FrontController extends FrontControllerCore {
	public function setMedia() {

		global $js_files;

		$key = array_search(_PS_JS_DIR_ . 'jquery/jquery-1.4.4.min.js', $js_files);


2. insert CDN script in header.tpl:


<script type="http://cdn.jquerytools.org/1.2.7/full/jquery.tools.min.js"></script>

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...