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\HTML; |
10
|
|
|
use OSC\OM\OSCOM; |
11
|
|
|
use OSC\OM\Registry; |
12
|
|
|
|
13
|
|
|
class flat { |
14
|
|
|
var $code, $title, $description, $icon, $enabled; |
15
|
|
|
|
16
|
|
|
// class constructor |
17
|
|
View Code Duplication |
function __construct() { |
|
|
|
|
18
|
|
|
global $order; |
19
|
|
|
|
20
|
|
|
$OSCOM_Db = Registry::get('Db'); |
21
|
|
|
|
22
|
|
|
$this->code = 'flat'; |
23
|
|
|
$this->title = OSCOM::getDef('module_shipping_flat_text_title'); |
24
|
|
|
$this->description = OSCOM::getDef('module_shipping_flat_text_description'); |
25
|
|
|
$this->sort_order = defined('MODULE_SHIPPING_FLAT_SORT_ORDER') ? (int)MODULE_SHIPPING_FLAT_SORT_ORDER : 0; |
|
|
|
|
26
|
|
|
$this->icon = ''; |
27
|
|
|
$this->tax_class = defined('MODULE_SHIPPING_FLAT_TAX_CLASS') ? MODULE_SHIPPING_FLAT_TAX_CLASS : 0; |
|
|
|
|
28
|
|
|
$this->enabled = (defined('MODULE_SHIPPING_FLAT_STATUS') && (MODULE_SHIPPING_FLAT_STATUS == 'True') ? true : false); |
29
|
|
|
|
30
|
|
|
if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FLAT_ZONE > 0) ) { |
|
|
|
|
31
|
|
|
$check_flag = false; |
32
|
|
|
$Qcheck = $OSCOM_Db->get('zones_to_geo_zones', 'zone_id', ['geo_zone_id' => MODULE_SHIPPING_FLAT_ZONE, 'zone_country_id' => $order->delivery['country']['id']], 'zone_id'); |
33
|
|
|
while ($Qcheck->fetch()) { |
34
|
|
|
if ($Qcheck->valueInt('zone_id') < 1) { |
35
|
|
|
$check_flag = true; |
36
|
|
|
break; |
37
|
|
|
} elseif ($Qcheck->valueInt('zone_id') == $order->delivery['zone_id']) { |
38
|
|
|
$check_flag = true; |
39
|
|
|
break; |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
if ($check_flag == false) { |
|
|
|
|
44
|
|
|
$this->enabled = false; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
// class methods |
50
|
|
|
function quote($method = '') { |
|
|
|
|
51
|
|
|
global $order; |
52
|
|
|
|
53
|
|
|
$this->quotes = array('id' => $this->code, |
|
|
|
|
54
|
|
|
'module' => OSCOM::getDef('module_shipping_flat_text_title'), |
55
|
|
|
'methods' => array(array('id' => $this->code, |
56
|
|
|
'title' => OSCOM::getDef('module_shipping_flat_text_way'), |
57
|
|
|
'cost' => MODULE_SHIPPING_FLAT_COST))); |
58
|
|
|
|
59
|
|
View Code Duplication |
if ($this->tax_class > 0) { |
|
|
|
|
60
|
|
|
$this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
View Code Duplication |
if (tep_not_null($this->icon)) $this->quotes['icon'] = HTML::image($this->icon, $this->title); |
|
|
|
|
64
|
|
|
|
65
|
|
|
return $this->quotes; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
function check() { |
69
|
|
|
return defined('MODULE_SHIPPING_FLAT_STATUS'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
View Code Duplication |
function install() { |
|
|
|
|
73
|
|
|
$OSCOM_Db = Registry::get('Db'); |
74
|
|
|
|
75
|
|
|
$OSCOM_Db->save('configuration', [ |
76
|
|
|
'configuration_title' => 'Enable Flat Shipping', |
77
|
|
|
'configuration_key' => 'MODULE_SHIPPING_FLAT_STATUS', |
78
|
|
|
'configuration_value' => 'True', |
79
|
|
|
'configuration_description' => 'Do you want to offer flat rate shipping?', |
80
|
|
|
'configuration_group_id' => '6', |
81
|
|
|
'sort_order' => '1', |
82
|
|
|
'set_function' => 'tep_cfg_select_option(array(\'True\', \'False\'), ', |
83
|
|
|
'date_added' => 'now()' |
84
|
|
|
]); |
85
|
|
|
|
86
|
|
|
$OSCOM_Db->save('configuration', [ |
87
|
|
|
'configuration_title' => 'Shipping Cost', |
88
|
|
|
'configuration_key' => 'MODULE_SHIPPING_FLAT_COST', |
89
|
|
|
'configuration_value' => '5.00', |
90
|
|
|
'configuration_description' => 'The shipping cost for all orders using this shipping method.', |
91
|
|
|
'configuration_group_id' => '6', |
92
|
|
|
'sort_order' => '1', |
93
|
|
|
'date_added' => 'now()' |
94
|
|
|
]); |
95
|
|
|
|
96
|
|
|
$OSCOM_Db->save('configuration', [ |
97
|
|
|
'configuration_title' => 'Tax Class', |
98
|
|
|
'configuration_key' => 'MODULE_SHIPPING_FLAT_TAX_CLASS', |
99
|
|
|
'configuration_value' => '0', |
100
|
|
|
'configuration_description' => 'Use the following tax class on the shipping fee.', |
101
|
|
|
'configuration_group_id' => '6', |
102
|
|
|
'sort_order' => '1', |
103
|
|
|
'use_function' => 'tep_get_tax_class_title', |
104
|
|
|
'set_function' => 'tep_cfg_pull_down_tax_classes(', |
105
|
|
|
'date_added' => 'now()' |
106
|
|
|
]); |
107
|
|
|
|
108
|
|
|
$OSCOM_Db->save('configuration', [ |
109
|
|
|
'configuration_title' => 'Shipping Zone', |
110
|
|
|
'configuration_key' => 'MODULE_SHIPPING_FLAT_ZONE', |
111
|
|
|
'configuration_value' => '0', |
112
|
|
|
'configuration_description' => 'If a zone is selected, only enable this shipping method for that zone.', |
113
|
|
|
'configuration_group_id' => '6', |
114
|
|
|
'sort_order' => '1', |
115
|
|
|
'use_function' => 'tep_get_zone_class_title', |
116
|
|
|
'set_function' => 'tep_cfg_pull_down_zone_classes(', |
117
|
|
|
'date_added' => 'now()' |
118
|
|
|
]); |
119
|
|
|
|
120
|
|
|
$OSCOM_Db->save('configuration', [ |
121
|
|
|
'configuration_title' => 'Sort Order', |
122
|
|
|
'configuration_key' => 'MODULE_SHIPPING_FLAT_SORT_ORDER', |
123
|
|
|
'configuration_value' => '0', |
124
|
|
|
'configuration_description' => 'Sort order of display. Lowest is displayed first.', |
125
|
|
|
'configuration_group_id' => '6', |
126
|
|
|
'sort_order' => '0', |
127
|
|
|
'date_added' => 'now()' |
128
|
|
|
]); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
function remove() { |
132
|
|
|
return Registry::get('Db')->exec('delete from :table_configuration where configuration_key in ("' . implode('", "', $this->keys()) . '")'); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
function keys() { |
136
|
|
|
return array('MODULE_SHIPPING_FLAT_STATUS', 'MODULE_SHIPPING_FLAT_COST', 'MODULE_SHIPPING_FLAT_TAX_CLASS', 'MODULE_SHIPPING_FLAT_ZONE', 'MODULE_SHIPPING_FLAT_SORT_ORDER'); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
?> |
|
|
|
|
140
|
|
|
|
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.