OpenCart 3自定义模块不保存数据 [英] OpenCart 3 custom module doesn't save data
问题描述
我正在为OpenCart 3开发付款模块.由于没有更新程序文档,因此我的模块基于其他付款模块(例如支付宝,贝宝,按需现金等).
Im developing a payment module for OpenCart 3. Since there's no updater documentation my module is based on the others payment module (such as Alipay, paypal, cash on demand, etc....)
我已经在admin/view/template/extension/payment/mipago.twig上简单地创建了模块视图
I've created the module view on admin/view/template/extension/payment/mipago.twig as simply
{{ 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">×</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
And the controller 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和按需现金,但是即使使用相同的代码行(仅更改参数)也无法保存任何内容.
This is a mockup but the problem its present, I cannot save the data from the form on the view. My code is based on other payment modules such as G2APay and Cash on Demand but even using the same lines of code (only changing the parameters) it doesnt save anything.
推荐答案
已解决!
这只是模块名称,类型以及所有变量和字段之间的不匹配.
It was just a mismatch between the module name, it's type and all the variables and fields.
例如,我的插件需要是一个payment
模块,因此所有变量都应命名为payment_mipago_<field>
,而不是mipago_<field>
,包括opencart插入数据库的字段
For example, my plugin needs to be a payment
module, so all the variables should be be named payment_mipago_<field>
, instead of mipago_<field>
, including the fields that opencart inserts to the database
这篇关于OpenCart 3自定义模块不保存数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!