1: | <?php
|
2: | namespace Opencart\Catalog\Model\Extension\Opencart\Total;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class Credit extends \Opencart\System\Engine\Model {
|
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: |
|
18: | public function getTotal(array &$totals, array &$taxes, float &$total): void {
|
19: | $this->load->language('extension/opencart/total/credit');
|
20: |
|
21: | $balance = $this->customer->getBalance();
|
22: |
|
23: | if ((float)$balance) {
|
24: | $credit = min($balance, $total);
|
25: |
|
26: | if ((float)$credit > 0) {
|
27: | $totals[] = [
|
28: | 'extension' => 'opencart',
|
29: | 'code' => 'credit',
|
30: | 'title' => $this->language->get('text_credit'),
|
31: | 'value' => -$credit,
|
32: | 'sort_order' => (int)$this->config->get('total_credit_sort_order')
|
33: | ];
|
34: |
|
35: | $total -= $credit;
|
36: | }
|
37: | }
|
38: | }
|
39: |
|
40: | |
41: | |
42: | |
43: | |
44: | |
45: | |
46: | |
47: |
|
48: | public function confirm(array $order_info, array $order_total): void {
|
49: | $this->load->language('extension/opencart/total/credit');
|
50: |
|
51: | if ($order_info['customer_id']) {
|
52: | $this->load->model('account/transaction');
|
53: |
|
54: | $this->model_account_transaction->addTransaction($order_info['customer_id'], $order_info['order_id'], sprintf($this->language->get('text_order_id'), (int)$order_info['order_id']), (float)$order_total['value']);
|
55: | }
|
56: | }
|
57: |
|
58: | |
59: | |
60: | |
61: | |
62: | |
63: | |
64: |
|
65: | public function unconfirm(array $order_info): void {
|
66: | $this->load->model('account/transaction');
|
67: |
|
68: | $this->model_account_transaction->deleteTransactionByOrderId($order_info['order_id']);
|
69: | }
|
70: | }
|
71: | |