不删除保存数据。如果,我在 Opencart 3 中卸载模块

Does not remove save data. if, I do uninstall module in Opencart 3

我已经为 OpenCart 3.0.2.0 更新了我的主题模块。通常这工作正常。但是,确实会造成一个小问题。

如果,我确实从管理员中卸载了我的自定义主题模块(扩展>扩展>模块)。但是,不会从前端和管理端删除保存的数据。 什么时候,我会再次安装和编辑模块。所以,不会删除上面保存的数据。此外,保存的数据设置不会从前面删除。它仍然保存数据。

这在旧版 (2.3.0.2) 中运行良好。但是,在这里,我无法判断。为什么在最新版本中会发生这种情况。 你能提出什么建议吗?下面是我们文件的代码。

mytheme.php (admin\controller\extension\module)

<?php
class ControllerExtensionModuleMytheme extends Controller {

    private $error = array(); 

    public function index() {   

        $language = $this->load->language('extension/module/mytheme');
        $data = array_merge($language);

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

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

        $this->load->model('tool/image');  

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

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

            if(isset($this->request->post['save_stay']) and $this->request->post['save_stay']=1)
            $this->response->redirect($this->url->link('extension/module/mytheme', 'user_token=' . $this->session->data['user_token'], true));
            else
            $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true));

        }

            $data['text_image_manager'] = 'Image manager';
            $data['user_token'] = $this->session->data['user_token'];       

        if (isset($this->session->data['success'])) {
            $data['success'] = $this->session->data['success'];
            unset($this->session->data['success']);
        } else {
            $data['success'] = '';
        }

        // store config data

        $config_data = array(

        'mytheme_background_color',
        'mytheme_button_color',
        'mytheme_powered_text',

        );

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


        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/dashboard', 'user_token=' . $this->session->data['user_token'], true)
        );

        $data['breadcrumbs'][] = array(
            'text' => $this->language->get('text_extension'),
            'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)
        );

        $data['breadcrumbs'][] = array(
            'text'      => $this->language->get('heading_title'),
            'href'      => $this->url->link('extension/module/mytheme', 'user_token=' . $this->session->data['user_token'], true)
        );


        $data['action'] = $this->url->link('extension/module/mytheme', 'user_token=' . $this->session->data['user_token'], true);

        $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true);

        if (isset($this->request->post['mytheme_module'])) {
            $modules = explode(',', $this->request->post['mytheme_module']);
        } elseif ($this->config->get('mytheme_module') != '') {
            $modules = explode(',', $this->config->get('mytheme_module'));
        } else {
            $modules = array();
        }           

        $this->load->model('localisation/language');

        $data['languages'] = $this->model_localisation_language->getLanguages();

        $data['modules'] = $modules;

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

        }

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

        $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('extension/module/mytheme', $data));
    }

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

        return !$this->error;
    }
}

您可以在控制器中创建卸载功能。

public function uninstall() {
      $this->load->model('setting/setting');
      $this->model_setting_setting->deleteSetting('mytheme');

}

您不需要调用此函数。卸载模块时会自动调用

祝你好运。 :)