简体   繁体   English

我的模块没有出现在已安装的挂钩中

[英]My module does not appear in the installed hooks

I have created a module to add an extra text for each product and that can be edited from the backoffice and its text saved in the database so that when it is updated it remains saved, etc.我已经创建了一个模块来为每个产品添加一个额外的文本,并且可以从后台进行编辑并将其文本保存在数据库中,以便在更新时保持保存状态,等等。

The question is that said form does not appear in any of the installed Hooks, any suggestions?问题是上述表格没有出现在任何已安装的挂钩中,有什么建议吗? Thanks!谢谢!

My php code:我的 php 代码:

<?php

if (!defined('_PS_VERSION_')) {
    exit;
}

class MyModuleText extends Module
{
    protected $config_form = false;

    public function __construct()
    {
        $this->name = 'mymoduletext';
        $this->tab = 'administration';
        $this->version = '1.0.0';
        $this->author = 'Jordi Comes';
        $this->need_instance = 0;

        /**
         * Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6)
         */
        $this->bootstrap = true;

        parent::__construct();

        $this->displayName = $this->l('My_Module_Text');
        $this->description = $this->l('Crea un texto editable desde el backoffice para cualquier producto de forma independiente');

        $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
    }

    /**
     * Don't forget to create update methods if needed:
     * http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update
     */
    public function install()
    {
        include(dirname(__FILE__).'/sql/install.php');

       // Register hooks
       $this->registerHook('displayProductTabContent');
       $this->registerHook('actionProductUpdate');
       $this->registerHook('displayProductAdditionalInfo');
       $this->registerHook('header');

       return parent::install()
           && Configuration::updateValue('MYMODULETEXT_MODULE_NAME', 'producttextmodule');
    }

    public function uninstall()
    {
        include(dirname(__FILE__).'/sql/uninstall.php');

        // Unregister hooks
        $this->unregisterHook('actionProductUpdate');
        $this->unregisterHook('displayProductAdditionalInfo');
        $this->unregisterHook('header');

        return parent::uninstall()
            && Configuration::deleteByName('MYMODULETEXT_MODULE_NAME');
    }

   
    public function hookDisplayProductTabContent($params)
    {
        $productText = $this->getProductText((int)$params['product']['id_product']);

        $this->smarty->assign(array(
            'productText' => $productText,
        ));

        return $this->context->smarty->fetch($this->local_path.'../producttabcontent.tpl');
    }

    

    public function hookActionProductUpdate($params)
    {
        // Save custom text for product
        if (Tools::isSubmit('submitProductTextModule')) {
            $id_product = (int)$params['id_product'];
            $text = pSQL(Tools::getValue('mymoduletext'));
            
            if (isset($text)) {
                $sql = 'REPLACE INTO `'._DB_PREFIX_.'mymoduletext` (`id_product`, `text`) 
                VALUES ('.$id_product.', "'.$text.'")';
    
                Db::getInstance()->execute($sql);
            }
        }
    }

    public function hookDisplayProductAdditionalInfo($params)
{
    // Get custom text for product
    $id_product = (int)$params['product']['id_product'];
    $sql = 'SELECT `text` FROM `'._DB_PREFIX_.'mymoduletext` WHERE `id_product` = '.(int)$id_product;
    $text = Db::getInstance()->getValue($sql);
    

    if ($text === false) {
        return '';
    }

    // Display custom text in product information block
    $this->context->smarty->assign(array(
        'mymoduletext' => $text,
    ));

    return $this->context->smarty->fetch($this->local_path.'../producttextmodule.tpl');
}

        
        public function hookHeader()
        {
            // Include CSS and JS files
            $this->context->controller->addCSS($this->_path.'views/css/producttextmodule.css');
            $this->context->controller->addJS($this->_path.'views/js/producttextmodule.js');
        }
        
        public function getContent()
        {
            // Handle form submission
            $output = '';
            if (Tools::isSubmit('submitProductTextModule')) {
                $my_module_name = strval(Tools::getValue('MYMODULETEXT_MODULE_NAME'));
                if (!$my_module_name
                    || empty($my_module_name)
                    || !Validate::isGenericName($my_module_name)
                ) {
                    $output .= $this->displayError($this->l('Invalid Configuration value'));
                } else {
                    Configuration::updateValue('MYMODULETEXT_MODULE_NAME', $my_module_name);
                    $output .= $this->displayConfirmation($this->l('Settings updated'));
                }
            }
        
            // Display form
            return $output.$this->displayForm();
        }
        
        public function displayForm()
        {
            // Get default language
            $default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
        
            // Init Fields form array
            $fields_form[0]['form'] = array(
                'legend' => array(
                    'title' => $this->l('Settings'),
                ),
                'input' => array(
                    array(
                        'type' => 'text',
                        'label' => $this->l('Configuration value'),
                        'name' => 'MYMODULETEXT_MODULE_NAME_MODULE_NAME',
                        'size' => 20,
                        'required' => true
                    )
                ),
                'submit' => array(
                    'title' => $this->l('Save'),
                    'class' => 'btn btn-default pull-right'
                )
            );
        
            $helper = new HelperForm();
        
            // Module, token and currentIndex
            $helper->module = $this;
            $helper->name_controller = $this->name;
            $helper->token = Tools::getAdminTokenLite('AdminModules');
            $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
        
            
            // Language
        
        $languages = Language::getLanguages(false);
        $helper->default_form_language = $default_lang;
        $helper->allow_employee_form_lang = $default_lang;
        $helper->languages = $languages;

            // Title and toolbar
    $helper->title = $this->displayName;
    $helper->show_toolbar = true;       
    $helper->toolbar_scroll = true;      
    $helper->submit_action = 'submitProductTextModule';
    $helper->toolbar_btn = array(
        'save' =>
            array(
                'desc' => $this->l('Save'),
                'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.
                    '&token='.Tools::getAdminTokenLite('AdminModules'),
            ),
        'back' => array(
            'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
            'desc' => $this->l('Back to list')
        )
    );

    // Load current value
    $helper->fields_value['MYMODULETEXT_MODULE_NAME'] = Configuration::get('MYMODULETEXT_MODULE_NAME');

    return $helper->generateForm($fields_form);
}
}

?>


<div class="product-text-module">
    <form action="{$link->getAdminLink('AdminProducts')}&id_product={$product.id_product}&updateproduct" method="post">
        <textarea name="mymoduletext" id="mymoduletext">{$productText}</textarea>
        <button type="submit" name="submitProductTextModule" class="btn btn-default">{l s='Save'}</button>
    </form>
</div>

{literal}
<style>

.product-text-module {
    padding: 20px;
    background-color: #f5f5f5;
    border-radius: 5px;
    margin-bottom: 20px;
}
</style>
{/literal}




<div class="product-text-module">
    <p>{$mymoduletext}</p>
</div>

{literal}
<style>

.product-text-module {
    padding: 20px;
    background-color: #f5f5f5;
    border-radius: 5px;
    margin-bottom: 20px;
}

</style>
{/literal}




All sugestions accepted

If your module installed correctly in the hook, Try this:如果您的模块正确安装在挂钩中,请尝试以下操作:

$this->fetch('module:producttextmodule/producttextmodule.tpl');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM