1: | <?php
|
2: | namespace Opencart\Catalog\Model\Checkout;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class Cart extends \Opencart\System\Engine\Model {
|
9: | |
10: | |
11: | |
12: | |
13: |
|
14: | public function getProducts(): array {
|
15: | $this->load->model('tool/image');
|
16: | $this->load->model('tool/upload');
|
17: |
|
18: |
|
19: | $product_data = [];
|
20: |
|
21: | $products = $this->cart->getProducts();
|
22: |
|
23: | foreach ($products as $product) {
|
24: | if ($product['image'] && is_file(DIR_IMAGE . html_entity_decode($product['image'], ENT_QUOTES, 'UTF-8'))) {
|
25: | $image = $product['image'];
|
26: | } else {
|
27: | $image = 'placeholder.png';
|
28: | }
|
29: |
|
30: | $option_data = [];
|
31: |
|
32: | foreach ($product['option'] as $option) {
|
33: | if ($option['type'] != 'file') {
|
34: | $value = $option['value'];
|
35: | } else {
|
36: | $upload_info = $this->model_tool_upload->getUploadByCode($option['value']);
|
37: |
|
38: | if ($upload_info) {
|
39: | $value = $upload_info['name'];
|
40: | } else {
|
41: | $value = '';
|
42: | }
|
43: | }
|
44: |
|
45: | $option_data[] = [
|
46: | 'product_option_id' => $option['product_option_id'],
|
47: | 'product_option_value_id' => $option['product_option_value_id'],
|
48: | 'option_id' => $option['option_id'],
|
49: | 'option_value_id' => $option['option_value_id'],
|
50: | 'name' => $option['name'],
|
51: | 'value' => $value,
|
52: | 'type' => $option['type']
|
53: | ];
|
54: | }
|
55: |
|
56: | $product_total = 0;
|
57: |
|
58: | foreach ($products as $product_2) {
|
59: | if ($product_2['product_id'] == $product['product_id']) {
|
60: | $product_total += $product_2['quantity'];
|
61: | }
|
62: | }
|
63: |
|
64: | if ($product['minimum'] > $product_total) {
|
65: | $minimum = false;
|
66: | } else {
|
67: | $minimum = true;
|
68: | }
|
69: |
|
70: | $product_data[] = [
|
71: | 'cart_id' => $product['cart_id'],
|
72: | 'product_id' => $product['product_id'],
|
73: | 'master_id' => $product['master_id'],
|
74: | 'image' => $this->model_tool_image->resize($image, $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height')),
|
75: | 'name' => $product['name'],
|
76: | 'model' => $product['model'],
|
77: | 'option' => $option_data,
|
78: | 'subscription' => $product['subscription'],
|
79: | 'download' => $product['download'],
|
80: | 'quantity' => $product['quantity'],
|
81: | 'stock' => $product['stock'],
|
82: | 'minimum' => $minimum,
|
83: | 'shipping' => $product['shipping'],
|
84: | 'subtract' => $product['subtract'],
|
85: | 'reward' => $product['reward'],
|
86: | 'tax_class_id' => $product['tax_class_id'],
|
87: | 'price' => $product['price'],
|
88: | 'total' => $product['total']
|
89: | ];
|
90: | }
|
91: |
|
92: | return $product_data;
|
93: | }
|
94: |
|
95: | |
96: | |
97: | |
98: | |
99: |
|
100: | public function getVouchers(): array {
|
101: | $voucher_data = [];
|
102: |
|
103: | if (!empty($this->session->data['vouchers'])) {
|
104: | foreach ($this->session->data['vouchers'] as $key => $voucher) {
|
105: | $voucher_data[$key] = [
|
106: | 'code' => $voucher['code'],
|
107: | 'description' => $voucher['description'],
|
108: | 'from_name' => $voucher['from_name'],
|
109: | 'from_email' => $voucher['from_email'],
|
110: | 'to_name' => $voucher['to_name'],
|
111: | 'to_email' => $voucher['to_email'],
|
112: | 'voucher_theme_id' => $voucher['voucher_theme_id'],
|
113: | 'message' => $voucher['message'],
|
114: | 'amount' => $voucher['amount']
|
115: | ];
|
116: | }
|
117: | }
|
118: |
|
119: | return $voucher_data;
|
120: | }
|
121: |
|
122: | |
123: | |
124: | |
125: | |
126: | |
127: | |
128: | |
129: | |
130: |
|
131: | public function getTotals(array &$totals, array &$taxes, int &$total): void {
|
132: | $sort_order = [];
|
133: |
|
134: | $this->load->model('setting/extension');
|
135: |
|
136: | $results = $this->model_setting_extension->getExtensionsByType('total');
|
137: |
|
138: | foreach ($results as $key => $value) {
|
139: | $sort_order[$key] = $this->config->get('total_' . $value['code'] . '_sort_order');
|
140: | }
|
141: |
|
142: | array_multisort($sort_order, SORT_ASC, $results);
|
143: |
|
144: | foreach ($results as $result) {
|
145: | if ($this->config->get('total_' . $result['code'] . '_status')) {
|
146: | $this->load->model('extension/' . $result['extension'] . '/total/' . $result['code']);
|
147: |
|
148: |
|
149: | ($this->{'model_extension_' . $result['extension'] . '_total_' . $result['code']}->getTotal)($totals, $taxes, $total);
|
150: | }
|
151: | }
|
152: |
|
153: | $sort_order = [];
|
154: |
|
155: | foreach ($totals as $key => $value) {
|
156: | $sort_order[$key] = $value['sort_order'];
|
157: | }
|
158: |
|
159: | array_multisort($sort_order, SORT_ASC, $totals);
|
160: | }
|
161: | }
|
162: | |