oct_deals_use_option_image.ocmod.xml
18.4 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<?xml version="1.0" encoding="utf-8"?>
<modification>
<code>oct_deals_use_option_image</code>
<name>Octemplates - Product main image option</name>
<version>1.0.0</version>
<author>Octemplates</author>
<link>https://octemplates.net/</link>
<file path="admin/controller/catalog/product.php">
<operation error="skip">
<search><![CDATA[protected function getForm() {]]></search>
<add position="after"><![CDATA[
$data['oct_product_main_image_option_status'] = $oct_product_main_image_option_status = $this->config->get('oct_product_main_image_option_status');
]]></add>
</operation>
<operation error="skip">
<search><![CDATA[foreach ($product_images as $product_image) {]]></search>
<add position="after"><![CDATA[
if (isset($oct_product_main_image_option_status) && $oct_product_main_image_option_status) {
@$image_by_option = $this->model_catalog_product->getProductOptionsToImage($this->request->get['product_id'], $product_image['product_image_id']);
} else {
$image_by_option = [];
}
]]></add>
</operation>
<operation error="skip">
<search><![CDATA[$data['product_options'] = array();]]></search>
<add position="before"><![CDATA[
$this->load->model('tool/image');
]]></add>
</operation>
<operation error="skip">
<search><![CDATA[if (isset($this->request->get['filter_name']) || isset($this->request->get['filter_model'])) {]]></search>
<add position="before"><![CDATA[
$this->load->model('tool/image');
]]></add>
</operation>
<operation error="skip">
<search><![CDATA['thumb' => $this->model_tool_image->resize($thumb, 100, 100),]]></search>
<add position="after"><![CDATA[
'image_by_option' => $image_by_option,
]]></add>
</operation>
<operation error="skip">
<search><![CDATA[$product_option_value_data[] = array(]]></search>
<add position="after"><![CDATA[
'image' => (isset($product_option_value['image'])) ? $product_option_value['image'] : '',
'thumb' => (isset($product_option_value['image']) && is_file(DIR_IMAGE.$product_option_value['image'])) ? $this->model_tool_image->resize($product_option_value['image'], 100, 100) : $this->model_tool_image->resize('no_image.png', 100, 100),
]]></add>
</operation>
</file>
<file path="admin/model/catalog/product.php">
<operation error="skip">
<search index="0"><![CDATA[$this->db->query("DELETE FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'");]]></search>
<add position="after"><![CDATA[
$oct_product_main_image_option_status = $this->config->get('oct_product_main_image_option_status');
if (isset($oct_product_main_image_option_status) && $oct_product_main_image_option_status) {
$this->db->query("DELETE FROM " . DB_PREFIX . "oct_product_image_by_option WHERE product_id = '" . (int)$product_id . "'");
}
]]></add>
</operation>
<operation error="skip">
<search index="1"><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = '" . $this->db->escape($product_image['image']) . "', sort_order = '" . (int)$product_image['sort_order'] . "'");]]></search>
<add position="after"><![CDATA[
if (isset($oct_product_main_image_option_status) && $oct_product_main_image_option_status) {
$product_image_id = $this->db->getLastId();
if (isset($product_image['image_by_option'])) {
foreach ($product_image['image_by_option'] as $option_value_id) {
$this->db->query("INSERT INTO " . DB_PREFIX . "oct_product_image_by_option SET product_id = '" . (int)$product_id . "', product_image_id = '" . (int)$product_image_id . "', option_value_id = '" . (int)$option_value_id . "'");
}
}
}
]]></add>
</operation>
<operation error="skip">
<search index="1"><![CDATA[$this->db->query("DELETE FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'");]]></search>
<add position="after"><![CDATA[
$oct_product_main_image_option_status = $this->config->get('oct_product_main_image_option_status');
if (isset($oct_product_main_image_option_status) && $oct_product_main_image_option_status) {
$this->db->query("DELETE FROM " . DB_PREFIX . "oct_product_image_by_option WHERE product_id = '" . (int)$product_id . "'");
}
]]></add>
</operation>
<operation error="skip">
<search><![CDATA[public function copyProduct($product_id) {]]></search>
<add position="before"><![CDATA[
public function getProductOptionsToImage($product_id, $product_image_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "oct_product_image_by_option WHERE product_id = '" . (int)$product_id . "' AND product_image_id = '" . (int)$product_image_id . "'");
$option_value_id_data = array();
if ($query->rows) {
foreach ($query->rows as $row) {
$option_value_id_data[] = $row['option_value_id'];
}
}
return $option_value_id_data;
}
]]></add>
</operation>
</file>
<file path="admin/view/template/catalog/product_form.twig">
<operation error="skip">
<search><![CDATA[<td class="text-left">{{ entry_additional_image }}</td>]]></search>
<add position="after"><![CDATA[
{% if oct_product_main_image_option_status is defined and oct_product_main_image_option_status %}
<td class="text-left">{{ entry_option_value }}</td>
{% endif %}
]]></add>
</operation>
<operation error="skip">
<search><![CDATA[<td class="text-left"><button type="button" onclick="addImage();" data-toggle="tooltip" title="{{ button_image_add }}" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button></td>]]></search>
<add position="before"><![CDATA[
<td></td>
]]></add>
</operation>
<operation error="skip">
<search><![CDATA[<td class="text-left"><button type="button" onclick="$('#image-row{{ image_row }}').remove();" data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>]]></search>
<add position="before" offset="1"><![CDATA[
{% if oct_product_main_image_option_status is defined and oct_product_main_image_option_status %}
<td class="text-right">
{% for product_option in product_options %}
{% if product_option.type == 'select' or product_option.type == 'radio' or product_option.type == 'checkbox' %}
<div class="col-sm-6 col-md-6 col-lg-6">
<div class="well well-sm" style="height: 130px; overflow: auto;text-align:left;margin-bottom:4px;">
{% if option_values[product_option.option_id] %}
{% for option_value in option_values[product_option.option_id] %}
<label>
{% if option_value.option_value_id in product_image.image_by_option %}
<input type="checkbox" name="product_image[{{ image_row }}][image_by_option][]" value="{{ option_value.option_value_id }}" checked="checked"/> {{ product_option.name }} > {{ option_value.name }}</label>
{% else %}
<input type="checkbox" name="product_image[{{ image_row }}][image_by_option][]" value="{{ option_value.option_value_id }}" /> {{ product_option.name }} > {{ option_value.name }}</label>
{% endif %}
<br/>
{% endfor %}
{% endif %}
</div>
</div>
{% endif %}
{% endfor %}
</td>
{% endif %}
]]></add>
</operation>
<operation error="skip">
<search><![CDATA[html += ' <td class="text-right"><input type="text" name="product_image[' + image_row + '][sort_order]" value="" placeholder="{{ entry_sort_order }}" class="form-control" /></td>';]]></search>
<add position="before"><![CDATA[
html += '{% if oct_product_main_image_option_status is defined and oct_product_main_image_option_status %}';
html += ' <td class="text-right">';
html += ' {% for product_option in product_options %}';
html += ' {% if product_option.type == "select" or product_option.type == "radio" or product_option.type == "checkbox" %}';
html += ' <div class="col-sm-6 col-md-6 col-lg-6">';
html += ' <div class="well well-sm" style="height: 130px; overflow: auto;text-align:left;margin-bottom:4px;">';
html += ' {% if option_values[product_option.option_id] %}';
html += ' {% for option_value in option_values[product_option.option_id] %}';
html += ' <label><input type="checkbox" name="product_image[' + image_row + '][image_by_option][]" value="{{ option_value.option_value_id }}" /> {{ product_option.name }} > {{ option_value.name }}</label><br/>';
html += ' {% endfor %}';
html += ' {% endif %}';
html += ' </div>';
html += ' </div>';
html += ' {% endif %}';
html += ' {% endfor %}';
html += ' </td>';
html += '{% endif %}';
]]></add>
</operation>
</file>
<file path="catalog/controller/product/product.php">
<operation error="skip">
<search><![CDATA[public function index() {]]></search>
<add position="after"><![CDATA[
$data['oct_product_main_image_option_status'] = $oct_product_main_image_option_status = $this->config->get('oct_product_main_image_option_status');
$data['oct_allow_autoselect_option'] = false;
$oct_product_main_image_option_data = $this->config->get('oct_product_main_image_option_data');
if (isset($oct_product_main_image_option_status) && $oct_product_main_image_option_status && isset($oct_product_main_image_option_data['allow_autoselect_option']) && $oct_product_main_image_option_data['allow_autoselect_option']) {
$data['oct_allow_autoselect_option'] = $oct_product_main_image_option_data['allow_autoselect_option'];
$allowed_options_ids = [];
if (isset($oct_product_main_image_option_data['allowed_options']) && !empty($oct_product_main_image_option_data['allowed_options'])) {
foreach ($oct_product_main_image_option_data['allowed_options'] as $allowed_option) {
array_push($allowed_options_ids, $allowed_option);
}
}
$data['allowed_options_ids'] = $allowed_options_ids;
}
]]></add>
</operation>
<operation error="skip">
<search><![CDATA[public function index() {]]></search>
<add position="before"><![CDATA[
public function getPImages() {
$json = array();
$this->load->model('catalog/product');
$this->load->model('tool/image');
if (isset($this->request->get['product_id'])) {
$product_id = $this->request->get['product_id'];
} else {
$product_id = 0;
}
$product_info = $this->model_catalog_product->getProduct($product_id);
if (isset($this->request->post['option'])) {
$opt_array = array();
foreach ($this->request->post['option'] as $value) {
if (is_array($value)) {
foreach ($value as $val) {
if ($val) {
$opt_array[] = $this->model_catalog_product->getProductOptionValueId($this->request->get['product_id'], $val);
}
}
} else {
if ($value) {
$opt_array[] = $this->model_catalog_product->getProductOptionValueId($this->request->get['product_id'], $value);
}
}
}
$results = $this->model_catalog_product->getProductImagesByOptionValueId($this->request->get['product_id'], $opt_array);
foreach ($results as $result) {
$json['images'][] = array(
'popup' => $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_height')),
'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_additional_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_additional_height')),
'thumb_slider' => $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_thumb_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_thumb_height')),
'width' => $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_width'),
'height' => $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_height'),
'thumb_height' => $this->config->get('theme_' . $this->config->get('config_theme') . '_image_additional_height'),
'thumb_width' => $this->config->get('theme_' . $this->config->get('config_theme') . '_image_additional_width')
);
}
} else {
$results = false;
}
if (!$results) {
$results = $this->model_catalog_product->getProductImages( $this->request->get['product_id'] );
$json['images'][] = array(
'popup' => $this->model_tool_image->resize($product_info['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_height')),
'thumb' => $this->model_tool_image->resize($product_info['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_additional_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_additional_height')),
'thumb_slider' => $this->model_tool_image->resize($product_info['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_thumb_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_thumb_height')),
'width' => $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_width'),
'height' => $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_height'),
'thumb_height' => $this->config->get('theme_' . $this->config->get('config_theme') . '_image_additional_height'),
'thumb_width' => $this->config->get('theme_' . $this->config->get('config_theme') . '_image_additional_width')
);
foreach ($results as $result) {
$json['images'][] = array(
'popup' => $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_height')),
'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_additional_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_additional_height')),
'thumb_slider' => $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_thumb_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_thumb_height')),
'width' => $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_width'),
'height' => $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_height'),
'thumb_height' => $this->config->get('theme_' . $this->config->get('config_theme') . '_image_additional_height'),
'thumb_width' => $this->config->get('theme_' . $this->config->get('config_theme') . '_image_additional_width')
);
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
]]></add>
</operation>
</file>
<file path="catalog/model/catalog/product.php">
<operation error="skip">
<search><![CDATA[public function getProductImages($product_id) {]]></search>
<add position="before"><![CDATA[
public function getProductImagesByOptionValueId($product_id, $options) {
$sql = "SELECT * FROM " . DB_PREFIX . "product_image pi LEFT JOIN " . DB_PREFIX . "oct_product_image_by_option pito ON (pi.product_image_id = pito.product_image_id) WHERE pi.product_id = '" . (int)$product_id . "'";
$implode = array();
foreach ($options as $option) {
if ($option) {
$implode[] = $option;
}
}
if (!empty($implode)) {
$sql .= " AND pito.option_value_id IN (" . implode(',', $implode) . ") GROUP BY pi.image ORDER BY pi.sort_order ASC";
} else {
$sql .= " GROUP BY pi.image ORDER BY pi.sort_order ASC";
}
$query = $this->db->query($sql);
return $query->rows;
}
public function getProductOptionValueId($product_id, $product_option_value_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value WHERE product_id = '" . (int)$product_id . "' AND product_option_value_id = '" . (int)$product_option_value_id . "'");
if ($query->row) {
return $query->row['option_value_id'];
}
}
]]></add>
</operation>
</file>
<file path="catalog/controller/checkout/cart.php">
<operation error="skip">
<search><![CDATA[
$option_data = array();
]]></search>
<add position="after"><![CDATA[
$this->load->model('catalog/product');
$options_arr = [];
foreach ($product['option'] as $value_opt) {
array_push($options_arr, $value_opt['product_option_value_id']);
}
if ($options_arr) {
$opt_array = [];
foreach ($options_arr as $value) {
if (is_array($value)) {
foreach ($value as $val) {
if ($val) {
$opt_array[] = $this->model_catalog_product->getProductOptionValueId($product['product_id'], $val);
}
}
} else {
if ($value) {
$opt_array[] = $this->model_catalog_product->getProductOptionValueId($product['product_id'], $value);
}
}
}
$results_opts = $this->model_catalog_product->getProductImagesByOptionValueId($product['product_id'], $opt_array);
if (isset($results_opts[0]['image']) AND $results_opts[0]['image']) {
$image = $this->model_tool_image->resize($results_opts[0]['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_cart_height'));
}
}
]]></add>
</operation>
</file>
</modification>