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 item { |
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 = 'item'; |
23
|
|
|
$this->title = OSCOM::getDef('module_shipping_item_text_title'); |
24
|
|
|
$this->description = OSCOM::getDef('module_shipping_item_text_description'); |
25
|
|
|
$this->sort_order = defined('MODULE_SHIPPING_ITEM_SORT_ORDER') ? (int)MODULE_SHIPPING_ITEM_SORT_ORDER : 0; |
|
|
|
|
26
|
|
|
$this->icon = ''; |
27
|
|
|
$this->tax_class = defined('MODULE_SHIPPING_ITEM_TAX_CLASS') ? MODULE_SHIPPING_ITEM_TAX_CLASS : 0; |
|
|
|
|
28
|
|
|
$this->enabled = (defined('MODULE_SHIPPING_ITEM_STATUS') && (MODULE_SHIPPING_ITEM_STATUS == 'True') ? true : false); |
29
|
|
|
|
30
|
|
|
if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_ITEM_ZONE > 0) ) { |
|
|
|
|
31
|
|
|
$check_flag = false; |
32
|
|
|
$Qcheck = $OSCOM_Db->get('zones_to_geo_zones', 'zone_id', ['geo_zone_id' => MODULE_SHIPPING_ITEM_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
|
|
|
$number_of_items = $this->getNumberOfItems(); |
54
|
|
|
|
55
|
|
|
$this->quotes = array('id' => $this->code, |
|
|
|
|
56
|
|
|
'module' => OSCOM::getDef('module_shipping_item_text_title'), |
57
|
|
|
'methods' => array(array('id' => $this->code, |
58
|
|
|
'title' => OSCOM::getDef('module_shipping_item_text_way'), |
59
|
|
|
'cost' => (MODULE_SHIPPING_ITEM_COST * $number_of_items) + MODULE_SHIPPING_ITEM_HANDLING))); |
60
|
|
|
|
61
|
|
View Code Duplication |
if ($this->tax_class > 0) { |
|
|
|
|
62
|
|
|
$this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
View Code Duplication |
if (tep_not_null($this->icon)) $this->quotes['icon'] = HTML::image($this->icon, $this->title); |
|
|
|
|
66
|
|
|
|
67
|
|
|
return $this->quotes; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
function check() { |
71
|
|
|
return defined('MODULE_SHIPPING_ITEM_STATUS'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
View Code Duplication |
function install() { |
|
|
|
|
75
|
|
|
$OSCOM_Db = Registry::get('Db'); |
76
|
|
|
|
77
|
|
|
$OSCOM_Db->save('configuration', [ |
78
|
|
|
'configuration_title' => 'Enable Item Shipping', |
79
|
|
|
'configuration_key' => 'MODULE_SHIPPING_ITEM_STATUS', |
80
|
|
|
'configuration_value' => 'True', |
81
|
|
|
'configuration_description' => 'Do you want to offer per item rate shipping?', |
82
|
|
|
'configuration_group_id' => '6', |
83
|
|
|
'sort_order' => '1', |
84
|
|
|
'set_function' => 'tep_cfg_select_option(array(\'True\', \'False\'), ', |
85
|
|
|
'date_added' => 'now()' |
86
|
|
|
]); |
87
|
|
|
|
88
|
|
|
$OSCOM_Db->save('configuration', [ |
89
|
|
|
'configuration_title' => 'Shipping Cost', |
90
|
|
|
'configuration_key' => 'MODULE_SHIPPING_ITEM_COST', |
91
|
|
|
'configuration_value' => '2.50', |
92
|
|
|
'configuration_description' => 'The shipping cost will be multiplied by the number of items in an order that uses this shipping method.', |
93
|
|
|
'configuration_group_id' => '6', |
94
|
|
|
'sort_order' => '1', |
95
|
|
|
'date_added' => 'now()' |
96
|
|
|
]); |
97
|
|
|
|
98
|
|
|
$OSCOM_Db->save('configuration', [ |
99
|
|
|
'configuration_title' => 'Handling Fee', |
100
|
|
|
'configuration_key' => 'MODULE_SHIPPING_ITEM_HANDLING', |
101
|
|
|
'configuration_value' => '0', |
102
|
|
|
'configuration_description' => 'Handling fee for this shipping method.', |
103
|
|
|
'configuration_group_id' => '6', |
104
|
|
|
'sort_order' => '1', |
105
|
|
|
'date_added' => 'now()' |
106
|
|
|
]); |
107
|
|
|
|
108
|
|
|
$OSCOM_Db->save('configuration', [ |
109
|
|
|
'configuration_title' => 'Tax Class', |
110
|
|
|
'configuration_key' => 'MODULE_SHIPPING_ITEM_TAX_CLASS', |
111
|
|
|
'configuration_value' => '0', |
112
|
|
|
'configuration_description' => 'Use the following tax class on the shipping fee.', |
113
|
|
|
'configuration_group_id' => '6', |
114
|
|
|
'sort_order' => '1', |
115
|
|
|
'use_function' => 'tep_get_tax_class_title', |
116
|
|
|
'set_function' => 'tep_cfg_pull_down_tax_classes(', |
117
|
|
|
'date_added' => 'now()' |
118
|
|
|
]); |
119
|
|
|
|
120
|
|
|
$OSCOM_Db->save('configuration', [ |
121
|
|
|
'configuration_title' => 'Shipping Zone', |
122
|
|
|
'configuration_key' => 'MODULE_SHIPPING_ITEM_ZONE', |
123
|
|
|
'configuration_value' => '0', |
124
|
|
|
'configuration_description' => 'If a zone is selected, only enable this shipping method for that zone.', |
125
|
|
|
'configuration_group_id' => '6', |
126
|
|
|
'sort_order' => '1', |
127
|
|
|
'use_function' => 'tep_get_zone_class_title', |
128
|
|
|
'set_function' => 'tep_cfg_pull_down_zone_classes(', |
129
|
|
|
'date_added' => 'now()' |
130
|
|
|
]); |
131
|
|
|
|
132
|
|
|
$OSCOM_Db->save('configuration', [ |
133
|
|
|
'configuration_title' => 'Sort Order', |
134
|
|
|
'configuration_key' => 'MODULE_SHIPPING_ITEM_SORT_ORDER', |
135
|
|
|
'configuration_value' => '0', |
136
|
|
|
'configuration_description' => 'Sort order of display. Lowest is displayed first.', |
137
|
|
|
'configuration_group_id' => '6', |
138
|
|
|
'sort_order' => '0', |
139
|
|
|
'date_added' => 'now()' |
140
|
|
|
]); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
function remove() { |
144
|
|
|
return Registry::get('Db')->exec('delete from :table_configuration where configuration_key in ("' . implode('", "', $this->keys()) . '")'); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
function keys() { |
148
|
|
|
return array('MODULE_SHIPPING_ITEM_STATUS', 'MODULE_SHIPPING_ITEM_COST', 'MODULE_SHIPPING_ITEM_HANDLING', 'MODULE_SHIPPING_ITEM_TAX_CLASS', 'MODULE_SHIPPING_ITEM_ZONE', 'MODULE_SHIPPING_ITEM_SORT_ORDER'); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
function getNumberOfItems() { |
152
|
|
|
global $order, $total_count; |
153
|
|
|
|
154
|
|
|
$OSCOM_Db = Registry::get('Db'); |
155
|
|
|
|
156
|
|
|
$number_of_items = $total_count; |
157
|
|
|
|
158
|
|
|
if ($order->content_type == 'mixed') { |
159
|
|
|
$number_of_items = 0; |
160
|
|
|
|
161
|
|
|
for ($i=0, $n=sizeof($order->products); $i<$n; $i++) { |
162
|
|
|
$number_of_items += $order->products[$i]['qty']; |
163
|
|
|
|
164
|
|
|
if (isset($order->products[$i]['attributes'])) { |
165
|
|
|
foreach ( $order->products[$i]['attributes'] as $option => $value ) { |
166
|
|
|
$Qcheck = $OSCOM_Db->prepare('select pa.products_id from :table_products_attributes pa, :table_products_attributes_download pad where pa.products_id = :products_id and pa.options_values_id = :options_values_id and pa.products_attributes_id = pad.products_attributes_id'); |
167
|
|
|
$Qcheck->bindInt(':products_id', $order->products[$i]['id']); |
168
|
|
|
$Qcheck->bindInt(':options_values_id', $value['value_id']); |
169
|
|
|
$Qcheck->execute(); |
170
|
|
|
|
171
|
|
|
if ($Qcheck->fetch() !== false) { |
172
|
|
|
$number_of_items -= $order->products[$i]['qty']; |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
return $number_of_items; |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
?> |
|
|
|
|
183
|
|
|
|
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.