1
votes

i try to overriding a module in my custom themes, so I have copy past the original folder (from module folder in my themes > themename > modules folder) but its not working

I have in my module folder from my theme :

ps_sharebuttons > views and ps_sharebuttons > ps_sharebuttons.php which contains

<?php
if (!defined('_PS_VERSION_')) {
    exit;
}

class Ps_SharebuttonsOverride extends Ps_Sharebuttons
{
public function renderWidget($hookName, array $params)
{
    var_dump($params);
    exit;
    $key = 'ps_sharebuttons|' . $params['product']['id_product'];
    if (!empty($params['product']['id_product_attribute'])) {
        $key .= '|' . $params['product']['id_product_attribute'];
    }

    if (!$this->isCached($this->templateFile, $this->getCacheId($key))) {
        $this->smarty->assign($this->getWidgetVariables($hookName, $params));
    }

    return $this->fetch($this->templateFile, $this->getCacheId($key));
}

public function getWidgetVariables($hookName, array $params)
{
    if (!isset($this->context->controller->php_self) || $this->context->controller->php_self != 'product') {
        return;
    }

    $product = $this->context->controller->getProduct();

    if (!Validate::isLoadedObject($product)) {
        return;
    }

    $social_share_links = [];
    $sharing_url = addcslashes($this->context->link->getProductLink($product), "'");
    $sharing_name = addcslashes($product->name, "'");

    $image_cover_id = $product->getCover($product->id);
    if (is_array($image_cover_id) && isset($image_cover_id['id_image'])) {
        $image_cover_id = (int)$image_cover_id['id_image'];
    } else {
        $image_cover_id = 0;
    }

    $sharing_img = addcslashes($this->context->link->getImageLink($product->link_rewrite, $image_cover_id), "'");

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

    if (Configuration::get('PS_SC_TWITTER')) {
        $social_share_links['twitter'] = array(
            'label' => $this->trans('Tweet', array(), 'Modules.Sharebuttons.Shop'),
            'class' => 'twitter',
            'url' => 'https://twitter.com/intent/tweet?text='.$sharing_name.' '.$sharing_url,
        );
    }

    if (Configuration::get('PS_SC_GOOGLE')) {
        $social_share_links['googleplus'] = array(
            'label' => $this->trans('Google+', array(), 'Modules.Sharebuttons.Shop'),
            'class' => 'googleplus',
            'url' => 'https://plus.google.com/share?url='.$sharing_url,
        );
    }

    if (Configuration::get('PS_SC_PINTEREST')) {
        $social_share_links['pinterest'] = array(
            'label' => $this->trans('Pinterest', array(), 'Modules.Sharebuttons.Shop'),
            'class' => 'pinterest',
            'url' => 'http://www.pinterest.com/pin/create/button/?media='.$sharing_img.'&url='.$sharing_url,
        );
    }

    return array(
        'social_share_links' => $social_share_links,
    );
}

}

But prestashop still use the orignal file module because i get this error :

 'Undefined index: product', '/home/xxxxxxxx/www/modules/ps_sharebuttons/ps_sharebuttons.php',

I've already clear cache

Thanks for help

1

1 Answers

0
votes

Ok im stupid, the override view goes to theme > module folder but the class should be in override > module folder