0

I'm trying to create module. I have language, controller an view files in admin and category modules. I copied admin part from default category module, module installation from admin looks fine, i'm adding it to my page and can't see it on actual page.

What did i forgot to do or to check?

/catalog/controller/module/product_list.php

<?php
class ControllerModuleProductsList extends Controller {

    public function index($setting) {
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/products_list.tpl')) {
            return $this->load->view($this->config->get('config_template') . '/template/module/products_list.tpl' $data);
        } else {
            return $this->load->view('default/template/error/not_found.tpl', $data);
        }
    }
}

/catalog/controller/module/products_list.tpl =)

   <h1>test</h1>

/admin/controller/module/product_list.php

    <?php
class ControllerModuleProductsList extends Controller {
    private $error = array();

    public function index() {
        $this->load->language('module/products_list');

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

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

        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
            $this->model_setting_setting->editSetting('products_list', $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'));
        }

        $data['heading_title'] = $this->language->get('heading_title');

        $data['text_edit'] = $this->language->get('text_edit');
        $data['text_enabled'] = $this->language->get('text_enabled');
        $data['text_disabled'] = $this->language->get('text_disabled');

        $data['entry_status'] = $this->language->get('entry_status');

        $data['button_save'] = $this->language->get('button_save');
        $data['button_cancel'] = $this->language->get('button_cancel');

        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', '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'),
            'href' => $this->url->link('module/products_list', 'token=' . $this->session->data['token'], 'SSL')
        );

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

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

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

        $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/products_list.tpl', $data));
    }

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

        return !$this->error;
    }
}

/admin/controller/module/products_list.tpl

<?php echo $header; ?><?php echo $column_left; ?>
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="pull-right">
        <button type="submit" form="form-category" data-toggle="tooltip" title="<?php echo $button_save; ?>" class="btn btn-primary"><i class="fa fa-save"></i></button>
        <a href="<?php echo $cancel; ?>" data-toggle="tooltip" title="<?php echo $button_cancel; ?>" class="btn btn-default"><i class="fa fa-reply"></i></a></div>
      <h1><?php echo $heading_title; ?></h1>
      <ul class="breadcrumb">
        <?php foreach ($breadcrumbs as $breadcrumb) { ?>
        <li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
        <?php } ?>
      </ul>
    </div>
  </div>
  <div class="container-fluid">
    <?php if ($error_warning) { ?>
    <div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    <?php } ?>
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-pencil"></i> <?php echo $text_edit; ?></h3>
      </div>
      <div class="panel-body">
        <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-category" class="form-horizontal">
          <div class="form-group">
            <label class="col-sm-2 control-label" for="input-status"><?php echo $entry_status; ?></label>
            <div class="col-sm-10">
              <select name="products_list" id="input-status" class="form-control">
                <?php if ($products_list) { ?>
                <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                <option value="0"><?php echo $text_disabled; ?></option>
                <?php } else { ?>
                <option value="1"><?php echo $text_enabled; ?></option>
                <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                <?php } ?>
              </select>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
<?php echo $footer; ?>
shadyyx
  • 15,825
  • 6
  • 60
  • 95
arkhy
  • 447
  • 6
  • 18

1 Answers1

0

The problem is in your admin module controller when saving the module settings.

You should be saving the settings for your new products_list module, but instead (because of copying and not paying enough of attention) you are still saving it for category module.

In your admin/controller/module/products_list.php find this line:

$this->model_setting_setting->editSetting('category', $this->request->post);

and change category for products_list, so it is

$this->model_setting_setting->editSetting('products_list', $this->request->post);

Additionally pay attention to this block of code in your controller:

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

and make sure that in your template file (for this module) you also have form field with name category_status (should be a <select> form element for setting Enabled/Disabled status).

shadyyx
  • 15,825
  • 6
  • 60
  • 95
  • Yes, thank you, i was really inattentive. But i changed this parts and it still doesn't work. – arkhy Nov 05 '14 at 06:37
  • OK, now what you need to do is go to layout and design (somewhere in administration), pick up the desired layout (e.g. category page, homepage, etc.) and assign that module to this layout. After saving it should be displayed on your frontend. I didn't realize we are talking about OC 2.0 before. – shadyyx Nov 05 '14 at 08:16
  • In `/catalog/controller/module/product_list.php` $data is undefined, so if you had error checking on, and accessed the page via `index.php?route=module/product_list` you will get an error message as such. Looks like your TPL file is also in the wrong folder. (should be under `view`. – Gavin Simpson Nov 05 '14 at 17:27