0
我目前正在为新的支付网关构建OpenCart支付扩展。现在,我可以成功进行付款并重定向到商户网站,但我不知道如何编写代码,以便它也更新订单状态。如何在OpenCart中更新订单状态
我所有的订单现在都显示在遗漏的订单下,我觉得是因为这个原因。我没有回调函数,我不知道如何去做。我想更新代码,以便它可以在付款成功时更新我的订单状态,或者在付款失败时重新导向结帐,但仍会更新订单状态。
这是我下面的代码:
<?php
class ControllerExtensionPaymentSCPAY extends Controller {
public function index() {
$this->load->language('extension/payment/sc_pay');
$data['button_confirm'] = $this->language->get('button_confirm');
$data['testmode'] = $this->config->get('sc_pay_test');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$total = $order_info['total'];
$newbutton = str_replace("50", $total, $this->config->get('sc_pay_button_link'));
$newbutton = $newbutton . "&redirect_url=" .$this->url->link('checkout/success');
if (!$this->config->get('sc_pay_test')) {
$data['action'] = $newbutton;
}
else {
$data['action'] = '';
}
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
if ($order_info) {
$data['business'] = $this->config->get('sc_pay_email');
$data['item_name'] = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$data['products'] = array();
foreach ($this->cart->getProducts() as $product) {
$option_data = array();
foreach ($product['option'] as $option) {
if ($option['type'] != 'file') {
$value = $option['value'];
}
else {
$upload_info = $this->model_tool_upload->getUploadByCode($option['value']);
if ($upload_info) {
$value = $upload_info['name'];
}
else {
$value = '';
}
}
$option_data[] = array(
'name' => $option['name'],
'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
);
}
$data['products'][] = array(
'name' => htmlspecialchars($product['name']),
'model' => htmlspecialchars($product['model']),
'price' => $this->currency->format($product['price'], $order_info['currency_code'], false, false),
'quantity' => $product['quantity'],
'option' => $option_data,
'weight' => $product['weight']
);
}
$data['discount_amount_cart'] = 0;
$total = $this->currency->format($order_info['total'] - $this->cart->getSubTotal(), $order_info['currency_code'], false, false);
if ($total > 0) {
$data['products'][] = array(
'name' => $this->language->get('text_total'),
'model' => '',
'price' => $total,
'quantity' => 1,
'option' => array(),
'weight' => 0
);
}
else {
$data['discount_amount_cart'] -= $total;
}
$data['currency_code'] = $order_info['currency_code'];
$data['first_name'] = html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8');
$data['last_name'] = html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');
$data['address1'] = html_entity_decode($order_info['payment_address_1'], ENT_QUOTES, 'UTF-8');
$data['address2'] = html_entity_decode($order_info['payment_address_2'], ENT_QUOTES, 'UTF-8');
$data['city'] = html_entity_decode($order_info['payment_city'], ENT_QUOTES, 'UTF-8');
$data['zip'] = html_entity_decode($order_info['payment_postcode'], ENT_QUOTES, 'UTF-8');
$data['country'] = $order_info['payment_iso_code_2'];
$data['email'] = $order_info['email'];
$data['invoice'] = $this->session->data['order_id'] . ' - ' . html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8') . ' ' . html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');
$data['lc'] = $this->session->data['language'];
$data['return'] = $this->url->link('checkout/success');
$data['notify_url'] = $this->url->link('extension/payment/sc_pay/callback', '', true);
$data['cancel_return'] = $this->url->link('checkout/checkout', '', true);
$data['custom'] = $this->session->data['order_id'];
return $this->load->view('extension/payment/sc_pay', $data);
}
}
enter code here
我应该在哪一行添加代码?我对Opencart非常陌生 – oriolowonancy
我已经尝试过了,但仍然缺少订单。你的代码提到哪个回调函数? @trinkal – oriolowonancy
你需要创建回调函数,检查其他支付网关的控制器文件,你会得到帮助。 –