繁体   English   中英

管理员product_form中的opencart 2模块数据

[英]opencart 2 module data in admin product_form

我有一个带有基本vallues的模块。

 <?php
class ControllerModulemarginCosts extends Controller {      
    private $error = array();     
    public function uninstall() {
        $this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE code='margin'");
    }

    public function index() {

        $this->load->language('module/margincosts');

        $this->document->setTitle($this->language->get('heading_title_m'));

        $this->load->model('setting/setting');

        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
            $this->model_setting_setting->editSetting('margin', $this->request->post);              

            $this->session->data['success'] = $this->language->get('text_success');

            $this->response->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));

        }

        $text_array = array('heading_title','heading_title_m','text_module',
                            'text_success','text_enabled','text_disabled','text_edit',
                            'entry_margin_cal','entry_margin_def_margin','entry_margin_limit',
                            'entry_margin_limit_margin','entry_margin_tresh','entry_margin_tres_amount_cash','margin_tres_ceil','margin_tres_ceil_delim','margin_tres_ceil_trim',
                            'button_save','button_cancel','entry_margin_status',
                            'help_margin_cal','help_def_margin','help_margin_limit','help_margin_tresh','help_margin_tres_amount_cash','help_margin_limit_margin',
                            'entry_margin_tres_percentage','help_margin_tres_percentage','help_margin_tres_ceil',
                            'help_margin_tres_ceil_delim','help_margin_tres_ceil_trim','entry_margin_shipping', 'entry_margin_handling','entry_margin_packaging','entry_margin_cost2',
                            'help_margin_shipping', 'help_margin_handling','help_margin_packaging','help_margin_cost2',
                            );

        foreach($text_array as $key){
            $data[$key] = $this->language->get($key);
        }



        if (isset($this->error['warning'])) {
            $data['error_warning'] = $this->error['warning'];
        } else {
            $data['error_warning'] = '';
        }

        $data['breadcrumbs'] = array();

        $data['breadcrumbs'][] = array(
            'text'      => $this->language->get('text_home'),
            'href'      => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL')
        );

        $data['breadcrumbs'][] = array(
            'text'      => $this->language->get('text_module'),
            'href'      => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL')
        );

        $data['breadcrumbs'][] = array(
            'text'      => $this->language->get('heading_title_m'),
            'href'      => $this->url->link('module/margincosts', 'token=' . $this->session->data['token'], 'SSL')
        );

        $data['action'] = $this->url->link('module/margincosts', 'token=' . $this->session->data['token'], 'SSL');

        $data['cancel'] = $this->url->link('module/margincosts', 'token=' . $this->session->data['token'], 'SSL');


        $variables_array = array('margin_cal','margin_def_margin','margin_limit','margin_limit_margin','margin_tresh',
                                'margin_tres_amount_cash','margin_status','margin_tres_percentage','margin_tres_ceil',
                                'margin_tres_ceil_delim','margin_tres_ceil_trim','margin_shipping',
                                'margin_handling','margin_packaging','margin_cost2');

        foreach($variables_array as $key){

            if (isset($this->request->post[$key])) {
                $data[$key] = $this->request->post[$key];
            } else {
                $data[$key] = $this->config->get($key);
            }

        }


        $data['header'] = $this->load->controller('common/header');
        $data['column_left'] = $this->load->controller('common/column_left');
        $data['footer'] = $this->load->controller('common/footer');

        $this->response->setOutput($this->load->view('module/margincosts.tpl', $data));
    }

    private function validate() {
        if (!$this->user->hasPermission('modify', 'module/margincosts')) {
            $this->error['warning'] = $this->language->get('error_permission');
        }

        return !$this->error;

    }   
}
?>

我希望这些值在我的admin / product_form.php中使用

我将下一个代码添加到admin / product_form.php

$this->load->controller('catalog/module/margincosts');

$variables_array = array('margin_cal','margin_def_margin','margin_limit','margin_limit_margin','margin_tresh',
                            'margin_tres_amount_cash','margin_status','margin_tres_percentage','margin_tres_ceil',
                            'margin_tres_ceil_delim','margin_tres_ceil_trim','margin_shipping',
                            'margin_handling','margin_packaging','margin_cost2');

    foreach($variables_array as $key){

        if (isset($this->request->post[$key])) {
            $data[$key] = $this->request->post[$key];
        }
    }

没有错误但也没有价值。 如何将模块数据加载到admin / product_form.php中,以便可以将其用于计算。

更改
$this->response->setOutput($this->load->view('module/margincosts.tpl', $data));

return $this->load->view('module/margincosts.tpl', $data);

并在您的product_form.php添加

$data['anyname'] = $this->load->controller('module/margincosts');

暂无
暂无

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

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