我正在开发OpenCart 3的支付模块。由于没有更新程序文档,我的模块基于其他支付模块(例如支付宝,PayPal,按需现金等等)
我已经在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">×</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 }}
控制器管理员/ 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,但即使使用相同的代码行(只更改参数),它也不会保存任何内容。
答案 0 :(得分:1)
解决!
这只是模块名称,类型和所有变量和字段之间的不匹配。
例如,我的插件需要是whale_variations = get_all_variations("whale")
for whale_varitaion in whale_variations:
count = text1.count(whale_varitaion)
if count > 0:
print(whale_varitaion, count)
模块,因此所有变量都应该命名为payment
,而不是payment_mipago_<field>
,包括opencart插入数据库的字段
答案 1 :(得分: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