Jump to content

[solved] setMedia override to remove scripts not working


Recommended Posts

i try to remove certain scripts i don't need in my shop (e.g. serialScroll, fancybox) from the controller files. for example, i made an override on ParentOrderController.php like this:

 

<?php

class ParentOrderController extends ParentOrderControllerCore
{

public function setMedia()
{
	parent::setMedia();

	if ($this->context->getMobileDevice() === false)
		// Adding CSS style sheet
		//$this->addCSS(_THEME_CSS_DIR_.'addresses.css');

	// Adding JS files
	$this->addJS(_THEME_JS_DIR_.'tools.js');
	if ((Configuration::get('PS_ORDER_PROCESS_TYPE') == 0 && Tools::getValue('step') == 1) || Configuration::get('PS_ORDER_PROCESS_TYPE') == 1)
		$this->addJS(_THEME_JS_DIR_.'order-address.js');
		//$this->addJqueryPlugin('fancybox');
	if ((int)(Configuration::get('PS_BLOCK_CART_AJAX')) || Configuration::get('PS_ORDER_PROCESS_TYPE') == 1)
	{
		$this->addJS(_THEME_JS_DIR_.'cart-summary.js');
		$this->addJqueryPlugin('typewatch');
	}
}
}

 

so i simply commented the scripts/css i don't need (in this case fancybox and addresses.css). however, this does not work. the script is still included on the page. if i also comment out

parent::setMedia()

then fancybox gets removed, but not only fancybox, also global.css for example. what am i doing wrong?

 

thanks for any help!

Link to comment
Share on other sites

parent::anything call the original function, which basically means you are adding to it, not replacing it.

 

If you remove the parent:: then you are truly replacing it, and should keep everything that was in the original function, except the parts you want to disable.

Link to comment
Share on other sites

I thought so too, but then why is global.css removed as soon as I remove the call to parent::setMedia()?

 

If I change the following line from

$this->addCSS(_THEME_CSS_DIR_.'addresses.css');

to

$this->addCSS(_THEME_CSS_DIR_.'global.css');

it obviously gets included again.

 

Do I have to override all controller files' setMedia functions when I don't use css files like addresses.css or product.css and replace them with global.css?

Edited by leeego (see edit history)
Link to comment
Share on other sites

It's a bit like a chicken and egg.

 

If you do not call parent::setMedia() then global.css will not be added (as the parent calls setMedia from FrontController).

 

You should be able to replace parent::setMedia with FrontController::setMedia(), that would bypass the setmedia from parentOrderController, but would still call the setmedia that loads global.css (as well as other files).

Link to comment
Share on other sites

×
×
  • Create New...