簡體   English   中英

如何在 prestashop 中移動鈎子?

[英]How to move a hook in prestashop?

我需要在產品描述和購物車添加按鈕之間移動我的掛鈎,在我在照片中標記的區域

在此處輸入圖片說明

到目前為止,我只能將它放在使用管理員的社交網絡按鈕之前和之后,但我需要將我的模塊放在按鈕之前。

這就是我創建鈎子的方式:

public function install()
    {
        if (!parent::install() || !$this->registerHook('displayProductAdditionalInfo'))
            return false;
        return true;
    }

public function uninstall()
    {
        if (!parent::uninstall() || !$this->unregisterHook('displayProductAdditionalInfo'))
            return false;
        return true;
    }

public function hookDisplayProductAdditionalInfo($params)
    {
        return $this->runnable();
    }

這是我的文件,其中包含我想顯示的 iframe

{block name='product_description_short' prepend}
    <style type='text/css'> 
        .products { border: none; width: 100%; height: {$height}px;  } 
    </style>
    <iframe class='products' src='{$iframe}{$token}'></iframe>
{/block}

如何將鈎子移動到我需要的地方,而不必接觸主題的源代碼?

這正是widget的概念所針對的。 Widgets 是 PS 1.7 中引入的一項高級功能,它擴展了 hooks 功能。

文檔

使用小部件,模塊開發人員可以在要求模塊這樣做的任何地方顯示內容。 當模塊在其代碼中實現小部件時,它允許:

1 使用{widget name="module_name"} 直接調用模塊的主題

2 如果注冊的鈎子被調用但它的方法 hook() 不存在,則回退到它的核心。

通過遵循相同的鏈接,您可以使模塊小部件兼容,然后在您想要的位置調用templates/catalog/product.tpl中的小部件。

在 1.7.5.0 的經典主題中,您可以在<div class="product-actions">之前調用第98行中的小部件。

希望它有所幫助。

編輯

假設您的模塊名稱是“my_module”,而您的自定義鈎子名稱是“myCustomHook”,模塊類應如下所示:

class MyModule extends Module implements WidgetInterface
{

    public function __construct()
    {
        $this->name = 'my_module';
        $this->version = '1.0.0';
        $this->author = 'me';
        $this->tab = 'front_office_features';
        $this->need_instance = 0;
        $this->bootstrap = true;

        parent::__construct();

        $this->description = ...
        $this->displayName = ...
        $this->confirmUninstall = ...
    }



    public function install()
    {
        if(!parent::install())
        {
            return false;
        }

        return true;
    }


    public function uninstall()
    {
        return(parent::uninstall());
    }

    public function renderWidget($hookName = null, array $configuration = [])
    {

        $this->smarty->assign($this->getWidgetVariables($hookName, $configuration));

        return $this->display(__FILE__, 'views/templates/widget/my_template.tpl');

    }

    public function getWidgetVariables($hookName = null, array $configuration = [])
    {
            if($hookName === 'MyCustomHook')
            {
                $your_height_value, $your_iframe_value, $your_token_value... //  Get the values depending on your logic

                return [
                    'token' => $your_token_value;
                    'height' => $your_height_value;
                    'iframe' => $your__iframe_value;
                ];

            }
    }

在模板文件中,只需調用小部件,如:

{widget module='my_module' hook='myCustomHook'}

這是一個內置的 Prestashop 鈎子,它必須留在那里。

你可以做的是注冊一個你自己的自定義鈎子,比如 displayMyHookHere,這里是如何在 PS 1.7+ 中鈎子的指南

將您的模塊掛在它上面並在您頁面上的任何位置顯示它,例如 {hook h='displayMyHookHere'}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM