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 cm_pi_gtin { |
14
|
|
|
var $code; |
15
|
|
|
var $group; |
16
|
|
|
var $title; |
17
|
|
|
var $description; |
18
|
|
|
var $sort_order; |
19
|
|
|
var $enabled = false; |
20
|
|
|
|
21
|
|
|
function __construct() { |
22
|
|
|
$this->code = get_class($this); |
23
|
|
|
$this->group = basename(dirname(__FILE__)); |
24
|
|
|
|
25
|
|
|
$this->title = OSCOM::getDef('module_content_product_info_gtin_title'); |
26
|
|
|
$this->description = OSCOM::getDef('module_content_product_info_gtin_description'); |
27
|
|
|
$this->description .= '<div class="secWarning">' . OSCOM::getDef('module_content_bootstrap_row_description') . '</div>'; |
28
|
|
|
|
29
|
|
|
if ( defined('MODULE_CONTENT_PRODUCT_INFO_GTIN_STATUS') ) { |
30
|
|
|
$this->sort_order = MODULE_CONTENT_PRODUCT_INFO_GTIN_SORT_ORDER; |
31
|
|
|
$this->enabled = (MODULE_CONTENT_PRODUCT_INFO_GTIN_STATUS == 'True'); |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
function execute() { |
36
|
|
|
global $oscTemplate; |
37
|
|
|
|
38
|
|
|
$content_width = (int)MODULE_CONTENT_PRODUCT_INFO_GTIN_CONTENT_WIDTH; |
39
|
|
|
|
40
|
|
|
$OSCOM_Db = Registry::get('Db'); |
41
|
|
|
|
42
|
|
|
$Qgtin = $OSCOM_Db->prepare('select products_gtin from :table_products where products_id = :products_id'); |
43
|
|
|
$Qgtin->bindInt(':products_id', $_GET['products_id']); |
44
|
|
|
$Qgtin->execute(); |
45
|
|
|
|
46
|
|
|
if ($Qgtin->fetch() !== false) { |
47
|
|
|
$gtin = $Qgtin->value('products_gtin'); |
48
|
|
|
|
49
|
|
|
if (!empty($gtin)) { |
50
|
|
|
$gtin = substr($gtin, 0 - MODULE_CONTENT_PRODUCT_INFO_GTIN_LENGTH); |
51
|
|
|
|
52
|
|
View Code Duplication |
if (!empty($gtin)) { |
|
|
|
|
53
|
|
|
$gtin = HTML::outputProtected($gtin); |
54
|
|
|
|
55
|
|
|
ob_start(); |
56
|
|
|
include('includes/modules/content/' . $this->group . '/templates/gtin.php'); |
57
|
|
|
$template = ob_get_clean(); |
58
|
|
|
|
59
|
|
|
$oscTemplate->addContent($template, $this->group); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
function isEnabled() { |
66
|
|
|
return $this->enabled; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
function check() { |
70
|
|
|
return defined('MODULE_CONTENT_PRODUCT_INFO_GTIN_STATUS'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
function install() { |
74
|
|
|
$OSCOM_Db = Registry::get('Db'); |
75
|
|
|
|
76
|
|
|
$OSCOM_Db->save('configuration', [ |
77
|
|
|
'configuration_title' => 'Enable GTIN Module', |
78
|
|
|
'configuration_key' => 'MODULE_CONTENT_PRODUCT_INFO_GTIN_STATUS', |
79
|
|
|
'configuration_value' => 'True', |
80
|
|
|
'configuration_description' => 'Should this module be shown on the product info page?', |
81
|
|
|
'configuration_group_id' => '6', |
82
|
|
|
'sort_order' => '1', |
83
|
|
|
'set_function' => 'tep_cfg_select_option(array(\'True\', \'False\'), ', |
84
|
|
|
'date_added' => 'now()' |
85
|
|
|
]); |
86
|
|
|
|
87
|
|
|
$OSCOM_Db->save('configuration', [ |
88
|
|
|
'configuration_title' => 'Content Width', |
89
|
|
|
'configuration_key' => 'MODULE_CONTENT_PRODUCT_INFO_GTIN_CONTENT_WIDTH', |
90
|
|
|
'configuration_value' => '6', |
91
|
|
|
'configuration_description' => 'What width container should the content be shown in?', |
92
|
|
|
'configuration_group_id' => '6', |
93
|
|
|
'sort_order' => '1', |
94
|
|
|
'set_function' => 'tep_cfg_select_option(array(\'12\', \'11\', \'10\', \'9\', \'8\', \'7\', \'6\', \'5\', \'4\', \'3\', \'2\', \'1\'), ', |
95
|
|
|
'date_added' => 'now()' |
96
|
|
|
]); |
97
|
|
|
|
98
|
|
|
$OSCOM_Db->save('configuration', [ |
99
|
|
|
'configuration_title' => 'Length of GTIN', |
100
|
|
|
'configuration_key' => 'MODULE_CONTENT_PRODUCT_INFO_GTIN_LENGTH', |
101
|
|
|
'configuration_value' => '13', |
102
|
|
|
'configuration_description' => 'Length of GTIN. 14 (Industry Standard), 13 (eg ISBN codes and EAN UCC-13), 12 (UPC), 8 (EAN UCC-8)', |
103
|
|
|
'configuration_group_id' => '6', |
104
|
|
|
'sort_order' => '0', |
105
|
|
|
'set_function' => 'tep_cfg_select_option(array(\'14\', \'13\', \'12\', \'8\'), ', |
106
|
|
|
'date_added' => 'now()' |
107
|
|
|
]); |
108
|
|
|
|
109
|
|
|
$OSCOM_Db->save('configuration', [ |
110
|
|
|
'configuration_title' => 'Sort Order', |
111
|
|
|
'configuration_key' => 'MODULE_CONTENT_PRODUCT_INFO_GTIN_SORT_ORDER', |
112
|
|
|
'configuration_value' => '0', |
113
|
|
|
'configuration_description' => 'Sort order of display. Lowest is displayed first.', |
114
|
|
|
'configuration_group_id' => '6', |
115
|
|
|
'sort_order' => '0', |
116
|
|
|
'date_added' => 'now()' |
117
|
|
|
]); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
function remove() { |
121
|
|
|
return Registry::get('Db')->exec('delete from :table_configuration where configuration_key in ("' . implode('", "', $this->keys()) . '")'); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
function keys() { |
125
|
|
|
return array('MODULE_CONTENT_PRODUCT_INFO_GTIN_STATUS', 'MODULE_CONTENT_PRODUCT_INFO_GTIN_CONTENT_WIDTH', 'MODULE_CONTENT_PRODUCT_INFO_GTIN_LENGTH', 'MODULE_CONTENT_PRODUCT_INFO_GTIN_SORT_ORDER'); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
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.