Symfony 使用prestashop中的自定义模块在客户视图细枝上添加自定义按钮?

Symfony 使用prestashop中的自定义模块在客户视图细枝上添加自定义按钮?,symfony,twig,prestashop,symfony4,prestashop-1.7,Symfony,Twig,Prestashop,Symfony4,Prestashop 1.7,首先,我尝试了所有与这个主题相关的问题和答案。此外,我尝试了相关的问题,并试图解决它,但没有成功。所以请仔细阅读我的问题 我想使用我的自定义模块在prestashop(1.7.6.1版)的客户视图页面上添加自定义按钮。 我找到了细枝文件:“personal\u information.html.twig” 文件位置:“prestashop/src/prestashopModule/Resources/views/Admin/shell/Customer/view/personal_informa

首先,我尝试了所有与这个主题相关的问题和答案。此外,我尝试了相关的问题,并试图解决它,但没有成功。所以请仔细阅读我的问题

我想使用我的自定义模块在prestashop(1.7.6.1版)的客户视图页面上添加自定义按钮。

我找到了细枝文件:“personal\u information.html.twig”

文件位置:“prestashop/src/prestashopModule/Resources/views/Admin/shell/Customer/view/personal_information.html.twig”

我附加了我想放置的短屏幕按钮。

自定义模块[myModule]

<?php


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

class MyCustomModule extends  PaymentModule
{
    public function __construct()
    {
        $this->name = 'MyCustomModule';
        $this->tab = 'payments XYZ';
        $this->version                = '1.0';
        $this->author                 = 'XYZ Technologies';
        $this->bootstrap              = true;
        $this->displayName            = 'XYZ';
        $this->description            = 'XYZ.';
        $this->confirmUninstall       = 'Are you sure you want to uninstall XYZ module?';
        $this->ps_versions_compliancy = array('min' => '1.7.0', 'max' => _PS_VERSION_);
        $this->allow_countries        = array('CH', 'LI', 'AT', 'DE');
        $this->allow_currencies       = array('CHF', 'EUR');

        parent::__construct();

    }

    /**
    * Install this module and register the following Hooks:
    *
    * @return bool
    */
    public function install()
    {
        if (Shop::isFeatureActive()) {
            Shop::setContext(Shop::CONTEXT_ALL);
        }

        Db::getInstance()->execute('
                CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'MyCustomModule` (
                `id` int(11) NOT NULL AUTO_INCREMENT,
                `customer_id` int(255) NOT NULL,
                `MyCustomModule` int(255) DEFAULT NULL,
                `lastcheck_date` date,
                `add_date` date,
                PRIMARY KEY (`id`)
        ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
        ');

        return parent::install() && $this->registerHook('Statusbtnoncustomerview');
    }
    /**
     * Uninstall this module and remove it from all hooks
     *
     * @return bool
     */
    public function uninstall()
    {
        return parent::uninstall() && $this->uninstallDb() && $this->unregisterHook('Statusbtnoncustomerview');
    }

    public function uninstallDb()
    {
        return Db::getInstance()->execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'MyCustomModule');
    }

    public function hookStatusbtnoncustomerview()
    {
        /**
         * Verify if this module is enabled
         */
        if (!$this->active) {
            return;
        }
        return $this->fetch('module:MyCustomModule/views/templates/hook/personal_information.html.twig');
    }
    /**
     * Returns a string containing the HTML necessary to
     * generate a configuration screen on the admin
     *
     * @return string
     */
    public function getContent()
    {
        $output = null;
        if (Tools::isSubmit('submit'.$this->name)) {

            // get configuration fields value
            $MyCustomModule_Account_Data = strval(Tools::getValue('MyCustomModule_Account_Data'));
            $credit_Checkbox =  strval(Tools::getValue('credit_Checkbox_1'));
            $interval_Month = strval(Tools::getValue('Interval_Month'));

            if (
                !$MyCustomModule_Account_Data ||
                empty($MyCustomModule_Account_Data) ||
                !Validate::isGenericName($MyCustomModule_Account_Data)
            ) {
                $output .= $this->displayError($this->l('Please Enter MyCustomModule Account Data.'));
            } else{

                // Update configuration fields value
                Configuration::updateValue('MyCustomModule_Account_Data', $MyCustomModule_Account_Data);
                Configuration::updateValue('credit_Checkbox_1', $credit_Checkbox);
                Configuration::updateValue('Interval_Month', $interval_Month);


                // Display message after successfully submit value
                $output .= $this->displayConfirmation($this->l('Settings updated'));
            }
        }

        return $output.$this->displayForm();
    }
    /**
     * Display a form
     *
     * @param array $params
     * @return form html using helper form
     */
    public function displayForm()
    {
        // Get default language
        $defaultLang = (int)Configuration::get('PS_LANG_DEFAULT');
        $credit_Checkbox = [
            [
                'id'=>1,
                'name'=>'',
                'val' => 1
            ]
        ];
        // Init Fields form array
        $fieldsForm[0]['form'] = [
            'legend' => [
                'title' => $this->l('Configuration'),
            ],
            'input' => [
                [
                    'type' => 'text',
                    'label' => $this->l('MyCustomModule Account Data'),
                    'name' => 'MyCustomModule_Account_Data',
                    'required' => true
                ],
                [

                    'type'=>'checkbox',
                    'label'=> $this->l('credit'),
                    'name'=>'credit_Checkbox',
                    'values'=>[
                        'query'=>$credit_Checkbox,
                        'id'=>'id',
                        'name'=>'name'
                    ]

                ],
                [
                    'type' => 'html',
                    'html_content' => '<input type="number" min="0" step="1" value="'.Configuration::get('Interval_Month').'" name="Interval_Month">',
                    'label' => $this->l('interval Month'),
                    'name' => 'Interval_Month',
                    'size' => 20
                ],
            ],
            'submit' => [
                '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
        $helper->default_form_language = $defaultLang;
        $helper->allow_employee_form_lang = $defaultLang;

        // Title and toolbar
        $helper->title = $this->displayName;
        $helper->show_toolbar = true;        // false -> remove toolbar
        $helper->toolbar_scroll = true;      // yes - > Toolbar is always visible on the top of the screen.
        $helper->submit_action = 'submit'.$this->name;
        $helper->toolbar_btn = [
            'save' => [
                'desc' => $this->l('Save'),
                'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.
                    '&token='.Tools::getAdminTokenLite('AdminModules'),
            ],
            'back' => [
                'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
                'desc' => $this->l('Back to list')
            ]
        ];

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


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


}

自Prestashop 1.7以来,您可以在自己的模块中覆盖后台视图

这意味着您只需要创建:

modules/mycustommodule/Admin/shell/Customer/view/personal_information.html.twig

然后您应该扩展原始模板以正确覆盖它。您可以复制整个模板,然后添加按钮所需的html。希望它能帮助您在这里找到所有文档:

谢谢您的回答。但是如何在我的模块中指出这个细枝文件呢?正如我说的,你需要创建这个文件并扩展原始文件,这样你就可以随心所欲地覆盖它。类似于:{%extends'PrestaShopBundle:Admin/shell/Customer/view/personal_-information.html.twig%%或{%extends'PrestaShopBundle:Admin/shell/Customer/view:personal_-information.html.twig%%的内容不确定哪一个会起作用,但请在我提供的链接上清楚解释,请务必仔细阅读