-
Notifications
You must be signed in to change notification settings - Fork 1
/
Babyplants custom text on product page tab
135 lines (131 loc) · 5.04 KB
/
Babyplants custom text on product page tab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<modification>
<name>Babyplants custom text on product page tab</name>
<version>1.1</version>
<link>Babyplants</link>
<author>Babyplants</author>
<code>Babyplants customtext</code>
<file path="admin/controller/catalog/product.php">
<operation>
<search><![CDATA[if (isset($this->request->post['points'])) {]]>
</search>
<add position="before">
<![CDATA[
if ($this->db->query("SHOW TABLES LIKE '". DB_PREFIX ."product_customtext'")->num_rows == 0) {
$sql = "CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "product_customtext` (
`product_id` int(11) NOT NULL,
`language_id` int(11) NOT NULL,
`customtext`text NOT NULL
) ENGINE=MyISAM COLLATE=utf8mb3_general_ci";
$this->db->query($sql);
}
if (isset($this->request->post['product_customtext'])) {
$data['product_customtext'] = $this->request->post['product_customtext'];
} elseif (isset($this->request->get['product_id'])) {
$data['product_customtext'] = $this->model_catalog_product->getProductCustomText($this->request->get['product_id']);
} else {
$data['product_customtext'] = array();
}
]]></add>
</operation>
</file>
<file path="admin/model/catalog/product.php">
<operation>
<search><![CDATA[$data['product_description'] = $this->getProductDescriptions($product_id);]]>
</search>
<add position="before">
<![CDATA[
$data['product_customtext'] = $this->getProductCustomText($product_id);
]]></add>
</operation>
<operation>
<search><![CDATA[foreach ($data['product_description'] as $language_id => $value) {]]>
</search>
<add position="before">
<![CDATA[
$this->db->query("DELETE FROM " . DB_PREFIX . "product_customtext WHERE product_id = '" . (int)$product_id . "'");
if(isset($data['product_customtext'])) {
foreach ($data['product_customtext'] as $language_id => $value) {
$this->db->query("INSERT INTO " . DB_PREFIX . "product_customtext SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', customtext = '" . $this->db->escape($value['customtext']) . "'");
}
}
]]></add>
</operation>
<operation>
<search><![CDATA[public function getProductOptions($product_id) {]]>
</search>
<add position="before">
<![CDATA[
public function getProductCustomText($product_id) {
$product_customtext_data = array();
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_customtext WHERE product_id = '" . (int)$product_id . "'");
foreach ($query->rows as $result) {
$product_customtext_data[$result['language_id']] = array(
'customtext' => $result['customtext']
);
}
return $product_customtext_data;
}
]]></add>
</operation>
</file>
<file path="admin/view/template/catalog/product_form.twig">
<operation>
<search><![CDATA[<label class="col-sm-2 control-label" for="input-tag{{ language.language_id }}"><span data-toggle="tooltip" title="{{ help_tag }}">{{ entry_tag }}</span></label>]]>
</search>
<add position="before">
<![CDATA[
<label class="col-sm-2 control-label" for="input-customtext{{ language.language_id }}">Custom Text</label>
<div class="col-sm-10">
<textarea class="form-control" name="product_customtext[{{ language.language_id }}][customtext]" placeholder="Enter Your Custom Text" id="input-customtext{{ language['language_id'] }}">{{ (product_customtext[language.language_id]) ? product_customtext[language.language_id]['customtext'] : '' }}</textarea>
</div>
</div>
<div class="form-group">
]]></add>
</operation>
</file>
<file path="catalog/controller/product/product.php">
<operation>
<search><![CDATA[$data['points'] = $product_info['points'];]]>
</search>
<add position="before">
<![CDATA[
$data['customtext'] = html_entity_decode($product_info['customtext'], ENT_QUOTES, 'UTF-8');
]]></add>
</operation>
</file>
<file path="catalog/model/catalog/product.php">
<operation>
<search><![CDATA[return array(]]>
</search>
<add position="before">
<![CDATA[
$customtext_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_customtext WHERE product_id = '" . (int)$product_id . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");
if($customtext_query->num_rows) {
$customtext = $customtext_query->row['customtext'];
} else {
$customtext = "";
}
]]></add>
</operation>
<operation>
<search><![CDATA[return array(]]>
</search>
<add position="after">
<![CDATA[
'customtext' => $customtext,
]]></add>
</operation>
</file>
<file path="catalog/view/theme/*/template/product/product.twig">
<operation>
<search><![CDATA[{% if price %}]]>
</search>
<add position="before">
<![CDATA[
{% if customtext is defined and customtext %}
<span class="us-product-tags" style="">{{ customtext }}</span><br>
{% endif %}
]]></add>
</operation>
</file>
</modification>