Prestashop 1.7 - 覆盖模块类

时间:2017-07-12 10:00:56

标签: module override prestashop-1.7

我尝试覆盖我的自定义主题中的模块,因此我复制了原始文件夹(来自我的主题中的模块文件夹> themename> modules文件夹) 但它不起作用

我的模块文件夹中有我的主题:

ps_sharebuttons>意见 和 ps_sharebuttons> ps_sharebuttons.php 其中包含

<?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,
    );
}

}

但prestashop仍然使用orignal文件模块,因为我收到此错误:

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

我已经清除了缓存

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

好吧我很蠢,覆盖视图转到主题&gt;模块文件夹,但该类应该覆盖&gt;模块文件夹