Jump to content

Can't override PHP file module


Recommended Posts

I want to override this module file: /modules/ps_sharebuttons/ps_sharebuttons.php

I created a new file in my theme's directory: modules/ps_sharebuttons/override/ps_sharebuttons.php 

Original file has:

use PrestaShop\PrestaShop\Core\Module\WidgetInterface;

class Ps_Sharebuttons extends Module implements WidgetInterface
{
	...
	public function getWidgetVariables($hookName, array $params)
	{
		...

        if (Configuration::get('PS_SC_FACEBOOK')) {
            $social_share_links['facebook'] = array(
                'label' => $this->trans('Share', array(), 'Modules.Sharebuttons.Shop'),
                'class' => 'icon-h-58',
                'url' => 'http://www.facebook.com/sharer.php?u='.$sharing_url,
            );
        }
		...
	}
}

This is my code: (I want to change 'class' and 'url' values)

use PrestaShop\PrestaShop\Core\Module\WidgetInterface;

class Ps_SharebuttonsOverride extends Ps_Sharebuttons implements WidgetInterface
{	
	...
	public function getWidgetVariables($hookName, array $params)
    {   
		...
        if (Configuration::get('PS_SC_FACEBOOK')) {
            $social_share_links['facebook'] = array(
                'label' => $this->trans('Share', array(), 'Modules.Sharebuttons.Shop'),
                'class' => $myClass,
                'url' => $myUrl,
            );
        }
		...
	}
}

 

I deleted /cache/dev/class_index.php and /cache/prod/class_index.php files

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

Thanks, that helped.

Also when overwriting had to drop 'implements WidgetInterface' because it broke the code. 

But since these overwrittes are not in the theme folder, this means that when i will want export my theme to a new website, I will have to export these overwritten modules separately?

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