OpenCart数据字段改造总结

添加数据库表字段

oc_address 添加字段

  • district
  • street_name
  • house_number

oc_order 添加字段

  • doc_type
  • doc_no
  • payment_district
  • payment_street_name
  • payment_house_number
  • shipping_district
  • shipping_street_name
  • shipping_house_number

oc_customer 添加字段

  • doc_type
  • doc_no

修改Model

catalog/model/account/address.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
public function addAddress($customer_id, $data) {
$this->db->query("INSERT INTO " . DB_PREFIX . "address SET customer_id = '" . (int)$customer_id . "', firstname = '" . $this->db->escape($data['firstname']) ... . "', district = '" . $this->db->escape($data['district']) . "', street_name = '" . $this->db->escape($data['street_name']) . "', house_number = '" . $this->db->escape($data['house_number']) ...);

...
}

public function editAddress($address_id, $data) {
$this->db->query("UPDATE " . DB_PREFIX . "address SET firstname = '" . $this->db->escape($data['firstname']) ... . "', district = '" . $this->db->escape($data['district']) . "', street_name = '" . $this->db->escape($data['street_name']) . "', house_number = '" . $this->db->escape($data['house_number']) ...);

...
}

public function getAddress($address_id) {
...

if ($address_query->num_rows) {
...

$address_data = array(
...
'district' => $address_query->row['district'],
'street_name' => $address_query->row['street_name'],
'house_number' => $address_query->row['house_number'],
...
}

public function getAddresses() {
...

foreach ($query->rows as $result) {
...

$address_data[$result['address_id']] = array(
...
'district' => $result['district'],
'street_name' => $result['street_name'],
'house_number' => $result['house_number'],
...
}

catalog/model/account/order.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public function getOrder($order_id) {
...

if ($order_query->num_rows) {
...

return array(
...
'doc_type' => $order_query->row['doc_type'],
'doc_no' => $order_query->row['doc_no'],
...
'payment_district' => $order_query->row['payment_district'],
'payment_street_name' => $order_query->row['payment_street_name'],
'payment_house_number' => $order_query->row['payment_house_number'],
...
'shipping_district' => $order_query->row['shipping_district'],
'shipping_street_name' => $order_query->row['shipping_street_name'],
'shipping_house_number' => $order_query->row['shipping_house_number'],
...
);

catalog/model/account/customer.php

1
2
3
public function editCustomer($customer_id, $data) {
$this->db->query("UPDATE " . DB_PREFIX . "customer SET firstname = '" . $this->db->escape($data['firstname']) ... . "', doc_type = '" . $this->db->escape($data['doc_type']) . "', doc_no = '" . $this->db->escape($data['doc_no']) ...);
}

opencart/catalog/model/checkout/order.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
public function addOrder($data) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "order` SET invoice_prefix = '" . $this->db->escape($data['invoice_prefix']) ... . "', doc_type = '" . $this->db->escape($data['doc_type']) . "', doc_no = '" . $this->db->escape($data['doc_no']) ... . "', payment_district = '" . $this->db->escape($data['payment_district']) . "', payment_street_name = '" . $this->db->escape($data['payment_street_name']) . "', payment_house_number = '" . $this->db->escape($data['payment_house_number']) ... . "', shipping_district = '" . $this->db->escape($data['shipping_district']) . "', shipping_street_name = '" . $this->db->escape($data['shipping_street_name']) . "', shipping_house_number = '" . $this->db->escape($data['shipping_house_number']) ....);

...
}

public function editOrder($order_id, $data) {
...
$this->db->query("UPDATE `" . DB_PREFIX . "order` SET invoice_prefix = '" . $this->db->escape($data['invoice_prefix']) ... . "', doc_type = '" . $this->db->escape($data['doc_type']) . "', doc_no = '" . $this->db->escape($data['doc_no']) ... . "', payment_district = '" . $this->db->escape($data['payment_district']) . "', payment_street_name = '" . $this->db->escape($data['payment_street_name']) . "', payment_house_number = '" . $this->db->escape($data['payment_house_number']) ... . "', shipping_district = '" . $this->db->escape($data['shipping_district']) . "', shipping_street_name = '" . $this->db->escape($data['shipping_street_name']) . "', shipping_house_number = '" . $this->db->escape($data['shipping_house_number']) ...);

...
}

public function getOrder($order_id) {
...

if ($order_query->num_rows) {
...

$order_products = $this->db->query("SELECT `name`,`quantity` as `qty`,`price` FROM `" . DB_PREFIX . "order_product` WHERE order_id = $order_id");

...

return array(
'order_id' => $order_query->row['order_id'],
'products' => $order_products->rows,
...
'doc_type' => $order_query->row['doc_type'],
'doc_no' => $order_query->row['doc_no'],
...
'payment_district' => $order_query->row['payment_district'],
'payment_street_name' => $order_query->row['payment_street_name'],
'payment_house_number' => $order_query->row['payment_house_number'],
...
'shipping_district' => $order_query->row['shipping_district'],
'shipping_street_name' => $order_query->row['shipping_street_name'],
'shipping_house_number' => $order_query->row['shipping_house_number'],
...
}

修改Language

catalog/language/en-gb/account/address.php
catalog/language/en-gb/checkout/checkout.php

修改Controller

catalog/controller/account/address.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
protected function getForm() {
...

if (isset($this->request->post['district'])) {
$data['district'] = $this->request->post['district'];
} elseif (!empty($address_info)) {
$data['district'] = $address_info['district'];
} else {
$data['district'] = '';
}

if (isset($this->request->post['city'])) {
$data['street_name'] = $this->request->post['street_name'];
} elseif (!empty($address_info)) {
$data['street_name'] = $address_info['street_name'];
} else {
$data['street_name'] = '';
}

if (isset($this->request->post['house_number'])) {
$data['house_number'] = $this->request->post['house_number'];
} elseif (!empty($address_info)) {
$data['house_number'] = $address_info['house_number'];
} else {
$data['house_number'] = '';
}

...
}

catalog/controller/account/edit.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
public function index() {
...

if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->model_account_customer->editCustomer($this->customer->getId(), $this->request->post);

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

$this->response->redirect($this->url->link('account/account', '', true));
}

...

if (isset($this->error['doc_type'])) {
$data['error_doc_type'] = $this->error['doc_type'];
} else {
$data['error_doc_type'] = '';
}

if (isset($this->error['doc_no'])) {
$data['error_doc_no'] = $this->error['doc_no'];
} else {
$data['error_doc_no'] = '';
}

...

if (isset($this->request->post['doc_type'])) {
$data['doc_type'] = $this->request->post['doc_type'];
} elseif (!empty($customer_info)) {
$data['doc_type'] = $customer_info['doc_type'];
} else {
$data['doc_type'] = '';
}

if (isset($this->request->post['doc_no'])) {
$data['doc_no'] = $this->request->post['doc_no'];
} elseif (!empty($customer_info)) {
$data['doc_no'] = $customer_info['doc_no'];
} else {
$data['doc_no'] = '';
}

...
}

catalog/controller/checkout/confirm.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
public function index() {
...

if (!$redirect) {
...

$this->load->model('account/customer');

if ($this->customer->isLogged()) {
$customer_info = $this->model_account_customer->getCustomer($this->customer->getId());

$order_data['customer_id'] = $this->customer->getId();
...

$order_data['doc_type'] = empty($customer_info['doc_type']) ? $this->session->data['doc_type'] : $customer_info['doc_type'];
$order_data['doc_no'] = empty($customer_info['doc_type']) ? $this->session->data['doc_no'] : $customer_info['doc_no'];
...

} elseif (isset($this->session->data['guest'])) {
$order_data['customer_id'] = 0;
...

$order_data['doc_type'] = $this->session->data['guest']['doc_type'];
$order_data['doc_no'] = $this->session->data['guest']['doc_no'];
...

}

...

$order_data['payment_district'] = $this->session->data['payment_address']['district'];
$order_data['payment_street_name'] = $this->session->data['payment_address']['street_name'];
$order_data['payment_house_number'] = $this->session->data['payment_address']['house_number'];

...

if ($this->cart->hasShipping()) {
...

$order_data['shipping_district'] = $this->session->data['shipping_address']['district'];
$order_data['shipping_street_name'] = $this->session->data['shipping_address']['street_name'];
$order_data['shipping_house_number'] = $this->session->data['shipping_address']['house_number'];
...

} else {
...

$order_data['shipping_district'] = '';
$order_data['shipping_street_name'] = '';
$order_data['shipping_house_number'] = '';
...
}

修改Twig模板

catalog/view/theme/default/template/account/address_form.twig
catalog/view/theme/default/template/account/edit.twig
catalog/view/theme/default/template/checkout/payment_address.twig

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :