0

我正在为 OpenCart 3 开发支付模块。由于没有更新程序文档,我的模块基于其他支付模块(例如支付宝、贝宝、按需现金等....)

我已经在 admin/view/template/extension/payment/mipago.twig 上简单地创建了模块视图

{{ header }}{{ column_left }}
{% if error_warning %}
    {{ error_warning }}
{% endif %}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="pull-right">
        <button type="submit" form="form-mipago" data-toggle="tooltip" title={{ button_save }} class="btn btn-primary"><i class="fa fa-save"></i></button>
        <a href={{ cancel }} data-toggle="tooltip" title={{ button_cancel }} class="btn btn-default"><i class="fa fa-reply"></i></a></div>
      <h1>{{ heading_title }}</h1>
      <ul class="breadcrumb">
        {% for breadcrumb in breadcrumbs %}
            <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
        {% endfor %}
      </ul>
    </div>
  </div>
  <div class="container-fluid">
    {% if error_warning %}
    <div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i>{{ error_warning }}
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    {% endif %}
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-pencil"></i>{{ text_edit }}</h3>
      </div>
      <div class="panel-body">
        <form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-mipago" class="form-horizontal">


               <div class="form-group">
                    <label class="col-sm-2 control-label" for="input-status">{{ entry_status }}</label>
                    <div class="col-sm-10">
                        <select name="mipago_status" id="input-status" class="form-control">
                            {% if paygol_status %}
                            <option value="1" selected="selected">{{ text_enabled }}</option>
                            <option value="0">{{ text_disabled }}</option>
                            {% else %}
                            <option value="1">{{ text_enabled}}</option>
                            <option value="0" selected="selected">{{ text_disabled }}</option>
                            {% endif %}
                        </select>
                    </div>
              </div>
        </form>
      </div>
    </div>
  </div>
</div>
{{ footer }}

和控制器 admin/controller/extension/payment/mipago.php

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

    public function index() {
        $this->document->setTitle('Mi Pago');

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

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

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

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

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

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

        $data['breadcrumbs'][] = array(
            'text' => 'Inicio',
            'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
        );

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

        $data['breadcrumbs'][] = array(
            'text' => 'Mi Pago',
            'href' => $this->url->link('extension/payment/mipago', 'user_token=' . $this->session->data['user_token'], true)
        );

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

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

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

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

        $this->load->model('localisation/order_status');
        $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();

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

        $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/payment/mipago', $data));
    }

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

这是一个模型,但存在的问题是,我无法将表单中的数据保存在视图上。我的代码基于其他支付模块,例如 G2APay 和 Cash on Demand,但即使使用相同的代码行(仅更改参数)它也不会保存任何内容。

4

2 回答 2

1

解决了!

这只是模块名称、类型以及所有变量和字段之间的不匹配。

比如我的插件需要是一个payment模块,所以所有的变量都应该命名为payment_mipago_<field>,而不是mipago_<field>,包括opencart插入数据库的字段

于 2017-10-31T20:26:33.833 回答
0

对于 OC3.0 应该是:

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

对于所有变量,您必须添加payment

于 2018-12-17T10:18:12.540 回答