добавить пользовательскую кнопку на ветке просмотра клиента, используя пользовательский модуль в prestashop? - PullRequest
0 голосов
/ 12 октября 2019

Во-первых, я перепробовал все вопросы и ответы, связанные с этой темой. Кроме того, я попробовал связанные вопросы и попытался решить их, но безуспешно. Поэтому, пожалуйста, внимательно прочитайте мой вопрос.

Я хочу добавить пользовательскую кнопку на странице просмотра клиентов в prestashop (версия 1.7.6.1), используя мой пользовательский модуль.

я нашел файл ветки:"personal_information.html.twig"

файл расположен:"prestashop / src / prestashopModule / Resources / views / Admin / shell / Customer / view /personal_information.html.twig "

Я прикрепляю экран коротким, я хочу поставить кнопку.

enter image description here

Пользовательский модуль [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);
    }


}

1 Ответ

1 голос
/ 12 октября 2019

Начиная с Prestashop 1.7, вы можете переопределить виды Back Office из своего собственного модуля.

Это означает, что вам нужно только создать:

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

Затем вам следует расширить исходный шаблон в следующем порядке:переопределить это правильно. Вы можете скопировать весь шаблон и после этого просто добавить HTML, необходимый для вашей кнопки. Надеюсь, это поможет вам найти всю документацию здесь: https://devdocs.prestashop.com/1.7/modules/concepts/templating/admin-views/

...