1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* osCommerce Online Merchant |
4
|
|
|
* |
5
|
|
|
* @copyright (c) 2016 osCommerce; https://www.oscommerce.com |
6
|
|
|
* @license MIT; https://www.oscommerce.com/license/mit.txt |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
use OSC\OM\Apps; |
10
|
|
|
use OSC\OM\Registry; |
11
|
|
|
|
12
|
|
|
class order_total { |
13
|
|
|
var $modules; |
14
|
|
|
|
15
|
|
|
protected $lang; |
16
|
|
|
|
17
|
|
|
// class constructor |
18
|
|
|
function __construct() { |
19
|
|
|
$this->lang = Registry::get('Language'); |
20
|
|
|
|
21
|
|
|
if (defined('MODULE_ORDER_TOTAL_INSTALLED') && tep_not_null(MODULE_ORDER_TOTAL_INSTALLED)) { |
22
|
|
|
$this->modules = explode(';', MODULE_ORDER_TOTAL_INSTALLED); |
23
|
|
|
|
24
|
|
|
foreach($this->modules as $value) { |
25
|
|
|
if (strpos($value, '\\') !== false) { |
26
|
|
|
$class = Apps::getModuleClass($value, 'OrderTotal'); |
27
|
|
|
|
28
|
|
|
Registry::set('OrderTotal_' . str_replace('\\', '_', $value), new $class); |
29
|
|
|
} else { |
30
|
|
|
$this->lang->loadDefinitions('modules/order_total/' . pathinfo($value, PATHINFO_FILENAME)); |
31
|
|
|
include('includes/modules/order_total/' . $value); |
32
|
|
|
|
33
|
|
|
$class = substr($value, 0, strrpos($value, '.')); |
34
|
|
|
$GLOBALS[$class] = new $class; |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
function process() { |
41
|
|
|
$order_total_array = array(); |
42
|
|
|
if (is_array($this->modules)) { |
43
|
|
|
foreach($this->modules as $value) { |
44
|
|
View Code Duplication |
if (strpos($value, '\\') !== false) { |
|
|
|
|
45
|
|
|
$OSCOM_OTM = Registry::get('OrderTotal_' . str_replace('\\', '_', $value)); |
46
|
|
|
} else { |
47
|
|
|
$class = substr($value, 0, strrpos($value, '.')); |
48
|
|
|
|
49
|
|
|
$OSCOM_OTM = $GLOBALS[$class]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if ($OSCOM_OTM->enabled) { |
53
|
|
|
$OSCOM_OTM->output = array(); |
54
|
|
|
$OSCOM_OTM->process(); |
55
|
|
|
|
56
|
|
|
for ($i=0, $n=sizeof($OSCOM_OTM->output); $i<$n; $i++) { |
57
|
|
|
if (tep_not_null($OSCOM_OTM->output[$i]['title']) && tep_not_null($OSCOM_OTM->output[$i]['text'])) { |
58
|
|
|
$order_total_array[] = [ |
59
|
|
|
'code' => $OSCOM_OTM->code, |
60
|
|
|
'title' => $OSCOM_OTM->output[$i]['title'], |
61
|
|
|
'text' => $OSCOM_OTM->output[$i]['text'], |
62
|
|
|
'value' => $OSCOM_OTM->output[$i]['value'], |
63
|
|
|
'sort_order' => $OSCOM_OTM->sort_order |
64
|
|
|
]; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $order_total_array; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
function output() { |
75
|
|
|
$output_string = ''; |
76
|
|
|
if (is_array($this->modules)) { |
77
|
|
|
foreach($this->modules as $value) { |
78
|
|
View Code Duplication |
if (strpos($value, '\\') !== false) { |
|
|
|
|
79
|
|
|
$OSCOM_OTM = Registry::get('OrderTotal_' . str_replace('\\', '_', $value)); |
80
|
|
|
} else { |
81
|
|
|
$class = substr($value, 0, strrpos($value, '.')); |
82
|
|
|
|
83
|
|
|
$OSCOM_OTM = $GLOBALS[$class]; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
if ($OSCOM_OTM->enabled) { |
87
|
|
|
$size = sizeof($OSCOM_OTM->output); |
88
|
|
View Code Duplication |
for ($i=0; $i<$size; $i++) { |
|
|
|
|
89
|
|
|
$output_string .= ' <tr>' . "\n" . |
90
|
|
|
' <td align="right" class="main">' . $OSCOM_OTM->output[$i]['title'] . '</td>' . "\n" . |
91
|
|
|
' <td align="right" class="main">' . $OSCOM_OTM->output[$i]['text'] . '</td>' . "\n" . |
92
|
|
|
' </tr>'; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $output_string; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
?> |
|
|
|
|
102
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.