1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* Divine CMS - Open source CMS for widespread use. |
4
|
|
|
Copyright (c) 2019 Mykola Burakov ([email protected]) |
5
|
|
|
|
6
|
|
|
See SOURCE.txt for other and additional information. |
7
|
|
|
|
8
|
|
|
This file is part of Divine CMS. |
9
|
|
|
|
10
|
|
|
This program is free software: you can redistribute it and/or modify |
11
|
|
|
it under the terms of the GNU General Public License as published by |
12
|
|
|
the Free Software Foundation, either version 3 of the License, or |
13
|
|
|
(at your option) any later version. |
14
|
|
|
|
15
|
|
|
This program is distributed in the hope that it will be useful, |
16
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
GNU General Public License for more details. |
19
|
|
|
|
20
|
|
|
You should have received a copy of the GNU General Public License |
21
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
22
|
|
|
|
23
|
|
|
class ModelCatalogProduct extends \Divine\Engine\Core\Model |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
public function addProduct($data) |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$this->db->query(" |
28
|
|
|
INSERT INTO product |
29
|
|
|
SET model = '" . $this->db->escape($data['model']) . "', |
30
|
|
|
sku = '" . $this->db->escape($data['sku']) . "', |
31
|
|
|
upc = '" . $this->db->escape($data['upc']) . "', |
32
|
|
|
ean = '" . $this->db->escape($data['ean']) . "', |
33
|
|
|
jan = '" . $this->db->escape($data['jan']) . "', |
34
|
|
|
isbn = '" . $this->db->escape($data['isbn']) . "', |
35
|
|
|
mpn = '" . $this->db->escape($data['mpn']) . "', |
36
|
|
|
location = '" . $this->db->escape($data['location']) . "', |
37
|
|
|
quantity = '" . (int)$data['quantity'] . "', |
38
|
|
|
minimum = '" . (int)$data['minimum'] . "', |
39
|
|
|
subtract = '" . (int)$data['subtract'] . "', |
40
|
|
|
stock_status_id = '" . (int)$data['stock_status_id'] . "', |
41
|
|
|
manufacturer_id = '" . (int)$data['manufacturer_id'] . "', |
42
|
|
|
shipping = '" . (int)$data['shipping'] . "', |
43
|
|
|
price = '" . (float)$data['price'] . "', |
44
|
|
|
points = '" . (int)$data['points'] . "', |
45
|
|
|
width = '" . (float)$data['width'] . "', |
46
|
|
|
height = '" . (float)$data['height'] . "', |
47
|
|
|
status = '" . (int)$data['status'] . "', |
48
|
|
|
noindex = '" . (int)$data['noindex'] . "', |
49
|
|
|
sort_order = '" . (int)$data['sort_order'] . "', |
50
|
|
|
date_added = NOW() |
51
|
|
|
"); |
52
|
|
|
|
53
|
|
|
$product_id = $this->db->getLastId(); |
54
|
|
|
|
55
|
|
|
if (isset($data['product_tab'])) { |
56
|
|
|
foreach ($data['product_tab'] as $tabdata) { |
57
|
|
|
$this->db->query(" |
58
|
|
|
INSERT INTO product_tab |
59
|
|
|
SET product_id = '".(int)$product_id."', |
60
|
|
|
status = '".(int)$tabdata['status']."', |
61
|
|
|
sort_order='".(int)$tabdata['sort_order']."' |
62
|
|
|
"); |
63
|
|
|
|
64
|
|
|
$product_tab_id = $this->db->getLastId(); |
65
|
|
|
foreach ($tabdata['description'] as $language_id => $value) { |
66
|
|
|
$this->db->query(" |
67
|
|
|
INSERT INTO product_tab_desc |
68
|
|
|
SET product_tab_id = '".(int)$product_tab_id."', |
69
|
|
|
heading = '".$this->db->escape($value['heading'])."', |
70
|
|
|
description = '".$this->db->escape($value['description'])."', |
71
|
|
|
product_id = '".(int)$product_id."', |
72
|
|
|
language_id = '".(int)$language_id."' |
73
|
|
|
"); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
if (isset($data['image'])) { |
79
|
|
|
$this->db->query(" |
80
|
|
|
UPDATE product |
81
|
|
|
SET image = '" . $this->db->escape($data['image']) . "' |
82
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
83
|
|
|
"); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
foreach ($data['product_description'] as $language_id => $value) { |
87
|
|
|
$this->db->query(" |
88
|
|
|
INSERT INTO product_description |
89
|
|
|
SET product_id = '" . (int)$product_id . "', |
90
|
|
|
language_id = '" . (int)$language_id . "', |
91
|
|
|
name = '" . $this->db->escape($value['name']) . "', |
92
|
|
|
description = '" . $this->db->escape($value['description']) . "', |
93
|
|
|
description_mini = '" . $this->db->escape($value['description_mini']) . "', |
94
|
|
|
tag = '" . $this->db->escape($value['tag']) . "', |
95
|
|
|
meta_title = '" . $this->db->escape($value['meta_title']) . "', |
96
|
|
|
meta_h1 = '" . $this->db->escape($value['meta_h1']) . "', |
97
|
|
|
meta_description = '" . $this->db->escape($value['meta_description']) . "' |
98
|
|
|
"); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
if (isset($data['product_attribute'])) { |
102
|
|
|
foreach ($data['product_attribute'] as $product_attribute) { |
103
|
|
|
if ($product_attribute['attribute_id']) { |
104
|
|
|
// Removes duplicates |
105
|
|
|
$this->db->query(" |
106
|
|
|
DELETE |
107
|
|
|
FROM product_attribute |
108
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
109
|
|
|
AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "' |
110
|
|
|
"); |
111
|
|
|
|
112
|
|
|
foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) { |
113
|
|
|
$this->db->query(" |
114
|
|
|
DELETE |
115
|
|
|
FROM product_attribute |
116
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
117
|
|
|
AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "' |
118
|
|
|
AND language_id = '" . (int)$language_id . "' |
119
|
|
|
"); |
120
|
|
|
|
121
|
|
|
$this->db->query(" |
122
|
|
|
INSERT INTO product_attribute |
123
|
|
|
SET product_id = '" . (int)$product_id . "', |
124
|
|
|
attribute_id = '" . (int)$product_attribute['attribute_id'] . "', |
125
|
|
|
language_id = '" . (int)$language_id . "', |
126
|
|
|
text = '" . $this->db->escape($product_attribute_description['text']) . "' |
127
|
|
|
"); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
if (isset($data['product_option'])) { |
134
|
|
|
foreach ($data['product_option'] as $product_option) { |
135
|
|
|
if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox' || $product_option['type'] == 'image') { |
136
|
|
|
if (isset($product_option['product_option_value'])) { |
137
|
|
|
$this->db->query(" |
138
|
|
|
INSERT INTO product_option |
139
|
|
|
SET product_id = '" . (int)$product_id . "', |
140
|
|
|
option_id = '" . (int)$product_option['option_id'] . "', |
141
|
|
|
required = '" . (int)$product_option['required'] . "' |
142
|
|
|
"); |
143
|
|
|
|
144
|
|
|
$product_option_id = $this->db->getLastId(); |
145
|
|
|
|
146
|
|
|
foreach ($product_option['product_option_value'] as $product_option_value) { |
147
|
|
|
$this->db->query(" |
148
|
|
|
INSERT INTO product_option_value |
149
|
|
|
SET product_option_id = '" . (int)$product_option_id . "', |
150
|
|
|
product_id = '" . (int)$product_id . "', |
151
|
|
|
option_id = '" . (int)$product_option['option_id'] . "', |
152
|
|
|
option_value_id = '" . (int)$product_option_value['option_value_id'] . "', |
153
|
|
|
quantity = '" . (int)$product_option_value['quantity'] . "', |
154
|
|
|
subtract = '" . (int)$product_option_value['subtract'] . "', |
155
|
|
|
price = '" . (float)$product_option_value['price'] . "', |
156
|
|
|
price_prefix = '" . $this->db->escape($product_option_value['price_prefix']) . "', |
157
|
|
|
points = '" . (int)$product_option_value['points'] . "', |
158
|
|
|
points_prefix = '" . $this->db->escape($product_option_value['points_prefix']) . "' |
159
|
|
|
"); |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
} else { |
163
|
|
|
$this->db->query(" |
164
|
|
|
INSERT INTO product_option |
165
|
|
|
SET product_id = '" . (int)$product_id . "', |
166
|
|
|
option_id = '" . (int)$product_option['option_id'] . "', |
167
|
|
|
value = '" . $this->db->escape($product_option['value']) . "', |
168
|
|
|
required = '" . (int)$product_option['required'] . "' |
169
|
|
|
"); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
if (isset($data['product_discount'])) { |
175
|
|
|
foreach ($data['product_discount'] as $product_discount) { |
176
|
|
|
$this->db->query(" |
177
|
|
|
INSERT INTO product_discount |
178
|
|
|
SET product_id = '" . (int)$product_id . "', |
179
|
|
|
customer_group_id = '" . (int)$product_discount['customer_group_id'] . "', |
180
|
|
|
quantity = '" . (int)$product_discount['quantity'] . "', |
181
|
|
|
priority = '" . (int)$product_discount['priority'] . "', |
182
|
|
|
price = '" . (float)$product_discount['price'] . "', |
183
|
|
|
date_start = '" . $this->db->escape($product_discount['date_start']) . "', |
184
|
|
|
date_end = '" . $this->db->escape($product_discount['date_end']) . "' |
185
|
|
|
"); |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
if (isset($data['product_special'])) { |
190
|
|
|
foreach ($data['product_special'] as $product_special) { |
191
|
|
|
$this->db->query(" |
192
|
|
|
INSERT INTO product_special |
193
|
|
|
SET product_id = '" . (int)$product_id . "', |
194
|
|
|
customer_group_id = '" . (int)$product_special['customer_group_id'] . "', |
195
|
|
|
priority = '" . (int)$product_special['priority'] . "', |
196
|
|
|
price = '" . (float)$product_special['price'] . "', |
197
|
|
|
date_start = '" . $this->db->escape($product_special['date_start']) . "', |
198
|
|
|
date_end = '" . $this->db->escape($product_special['date_end']) . "' |
199
|
|
|
"); |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
if (isset($data['product_image'])) { |
204
|
|
|
foreach ($data['product_image'] as $product_image) { |
205
|
|
|
$this->db->query(" |
206
|
|
|
INSERT INTO product_image |
207
|
|
|
SET product_id = '" . (int)$product_id . "', |
208
|
|
|
image = '" . $this->db->escape($product_image['image']) . "', |
209
|
|
|
sort_order = '" . (int)$product_image['sort_order'] . "' |
210
|
|
|
"); |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
if (isset($data['product_download'])) { |
215
|
|
|
foreach ($data['product_download'] as $download_id) { |
216
|
|
|
$this->db->query(" |
217
|
|
|
INSERT INTO product_to_download |
218
|
|
|
SET product_id = '" . (int)$product_id . "', |
219
|
|
|
download_id = '" . (int)$download_id . "' |
220
|
|
|
"); |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
if (isset($data['product_category'])) { |
225
|
|
|
foreach ($data['product_category'] as $category_id) { |
226
|
|
|
$this->db->query(" |
227
|
|
|
INSERT INTO product_to_category |
228
|
|
|
SET product_id = '" . (int)$product_id . "', |
229
|
|
|
category_id = '" . (int)$category_id . "' |
230
|
|
|
"); |
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
if (isset($data['main_category_id']) && $data['main_category_id'] > 0) { |
235
|
|
|
$this->db->query(" |
236
|
|
|
DELETE |
237
|
|
|
FROM product_to_category |
238
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
239
|
|
|
AND category_id = '" . (int)$data['main_category_id'] . "' |
240
|
|
|
"); |
241
|
|
|
$this->db->query(" |
242
|
|
|
INSERT INTO product_to_category |
243
|
|
|
SET product_id = '" . (int)$product_id . "', |
244
|
|
|
category_id = '" . (int)$data['main_category_id'] . "', |
245
|
|
|
main_category = 1 |
246
|
|
|
"); |
247
|
|
|
} elseif (isset($data['product_category'][0])) { |
248
|
|
|
$this->db->query(" |
249
|
|
|
UPDATE product_to_category |
250
|
|
|
SET main_category = 1 |
251
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
252
|
|
|
AND category_id = '" . (int)$data['product_category'][0] . "' |
253
|
|
|
"); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
if (isset($data['product_filter'])) { |
257
|
|
|
foreach ($data['product_filter'] as $filter_id) { |
258
|
|
|
$this->db->query(" |
259
|
|
|
INSERT INTO product_filter |
260
|
|
|
SET product_id = '" . (int)$product_id . "', |
261
|
|
|
filter_id = '" . (int)$filter_id . "' |
262
|
|
|
"); |
263
|
|
|
} |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
if (isset($data['product_related'])) { |
267
|
|
|
foreach ($data['product_related'] as $related_id) { |
268
|
|
|
$this->db->query(" |
269
|
|
|
DELETE |
270
|
|
|
FROM product_related |
271
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
272
|
|
|
AND related_id = '" . (int)$related_id . "' |
273
|
|
|
"); |
274
|
|
|
$this->db->query(" |
275
|
|
|
INSERT INTO product_related |
276
|
|
|
SET product_id = '" . (int)$product_id . "', |
277
|
|
|
related_id = '" . (int)$related_id . "' |
278
|
|
|
"); |
279
|
|
|
$this->db->query(" |
280
|
|
|
DELETE |
281
|
|
|
FROM product_related |
282
|
|
|
WHERE product_id = '" . (int)$related_id . "' |
283
|
|
|
AND related_id = '" . (int)$product_id . "' |
284
|
|
|
"); |
285
|
|
|
$this->db->query(" |
286
|
|
|
INSERT INTO product_related |
287
|
|
|
SET product_id = '" . (int)$related_id . "', |
288
|
|
|
related_id = '" . (int)$product_id . "' |
289
|
|
|
"); |
290
|
|
|
} |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
if (isset($data['product_related_article'])) { |
294
|
|
|
foreach ($data['product_related_article'] as $article_id) { |
295
|
|
|
$this->db->query(" |
296
|
|
|
DELETE |
297
|
|
|
FROM product_related_article |
298
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
299
|
|
|
AND article_id = '" . (int)$article_id . "' |
300
|
|
|
"); |
301
|
|
|
$this->db->query(" |
302
|
|
|
INSERT INTO product_related_article |
303
|
|
|
SET product_id = '" . (int)$product_id . "', |
304
|
|
|
article_id = '" . (int)$article_id . "' |
305
|
|
|
"); |
306
|
|
|
} |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
if (isset($data['product_reward'])) { |
310
|
|
|
foreach ($data['product_reward'] as $customer_group_id => $product_reward) { |
311
|
|
|
if ((int)$product_reward['points'] > 0) { |
312
|
|
|
$this->db->query(" |
313
|
|
|
INSERT INTO product_reward |
314
|
|
|
SET product_id = '" . (int)$product_id . "', |
315
|
|
|
customer_group_id = '" . (int)$customer_group_id . "', |
316
|
|
|
points = '" . (int)$product_reward['points'] . "' |
317
|
|
|
"); |
318
|
|
|
} |
319
|
|
|
} |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
if (isset($data['product_benefits'])) { |
323
|
|
|
foreach ($data['product_benefits'] as $benefit_id) { |
324
|
|
|
$this->db->query(" |
325
|
|
|
INSERT INTO product_to_benefit |
326
|
|
|
SET product_id = '" . (int)$product_id . "', |
327
|
|
|
benefit_id = '" . (int)$benefit_id . "' |
328
|
|
|
"); |
329
|
|
|
} |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
if (isset($data['product_stickers'])) { |
333
|
|
|
foreach ($data['product_stickers'] as $key => $sticker_id) { |
334
|
|
|
if ($sticker_id) { |
335
|
|
|
$this->db->query(" |
336
|
|
|
INSERT INTO product_to_sticker |
337
|
|
|
SET product_id = '" . (int)$product_id . "', |
338
|
|
|
position = '" . (int)$key . "', |
339
|
|
|
sticker_id = '" . (int)$sticker_id . "' |
340
|
|
|
"); |
341
|
|
|
} |
342
|
|
|
} |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
if (isset($data['product_layout'])) { |
346
|
|
|
foreach ($data['product_layout'] as $store_id => $layout_id) { |
347
|
|
|
$this->db->query(" |
348
|
|
|
INSERT INTO product_to_layout |
349
|
|
|
SET product_id = '" . (int)$product_id . "', |
350
|
|
|
layout_id = '" . (int)$layout_id . "' |
351
|
|
|
"); |
352
|
|
|
} |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
$this->cache->delete('url_formatter'); |
356
|
|
|
|
357
|
|
|
|
358
|
|
|
if ($data['keyword']) { |
359
|
|
|
$this->db->query(" |
360
|
|
|
INSERT INTO url_alias |
361
|
|
|
SET query = 'product_id=" . (int)$product_id . "', |
362
|
|
|
keyword = '" . $this->db->escape($data['keyword']) . "' |
363
|
|
|
"); |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
$this->cache->delete('product'); |
367
|
|
|
|
368
|
|
|
return $product_id; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
public function editProduct($product_id, $data) |
372
|
|
|
{ |
373
|
|
|
$this->db->query(" |
374
|
|
|
UPDATE product |
375
|
|
|
SET model = '" . $this->db->escape($data['model']) . "', |
376
|
|
|
sku = '" . $this->db->escape($data['sku']) . "', |
377
|
|
|
upc = '" . $this->db->escape($data['upc']) . "', |
378
|
|
|
ean = '" . $this->db->escape($data['ean']) . "', |
379
|
|
|
jan = '" . $this->db->escape($data['jan']) . "', |
380
|
|
|
isbn = '" . $this->db->escape($data['isbn']) . "', |
381
|
|
|
mpn = '" . $this->db->escape($data['mpn']) . "', |
382
|
|
|
location = '" . $this->db->escape($data['location']) . "', |
383
|
|
|
quantity = '" . (int)$data['quantity'] . "', |
384
|
|
|
minimum = '" . (int)$data['minimum'] . "', |
385
|
|
|
subtract = '" . (int)$data['subtract'] . "', |
386
|
|
|
stock_status_id = '" . (int)$data['stock_status_id'] . "', |
387
|
|
|
manufacturer_id = '" . (int)$data['manufacturer_id'] . "', |
388
|
|
|
shipping = '" . (int)$data['shipping'] . "', |
389
|
|
|
price = '" . (float)$data['price'] . "', |
390
|
|
|
points = '" . (int)$data['points'] . "', |
391
|
|
|
status = '" . (int)$data['status'] . "', |
392
|
|
|
noindex = '" . (int)$data['noindex'] . "', |
393
|
|
|
sort_order = '" . (int)$data['sort_order'] . "', |
394
|
|
|
date_modified = NOW() |
395
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
396
|
|
|
"); |
397
|
|
|
|
398
|
|
|
$this->db->query(" |
399
|
|
|
DELETE |
400
|
|
|
FROM product_tab |
401
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
402
|
|
|
"); |
403
|
|
|
$this->db->query(" |
404
|
|
|
DELETE |
405
|
|
|
FROM product_tab_desc |
406
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
407
|
|
|
"); |
408
|
|
|
|
409
|
|
|
if (isset($data['product_tab'])) { |
410
|
|
|
foreach ($data['product_tab'] as $tabdata) { |
411
|
|
|
$this->db->query(" |
412
|
|
|
INSERT INTO product_tab |
413
|
|
|
SET product_id = '".(int)$product_id."', |
414
|
|
|
status = '". (int)$tabdata['status']."', |
415
|
|
|
sort_order='". (int)$tabdata['sort_order']."' |
416
|
|
|
"); |
417
|
|
|
|
418
|
|
|
$product_tab_id = $this->db->getLastId(); |
419
|
|
|
|
420
|
|
|
foreach ($tabdata['description'] as $language_id => $value) { |
421
|
|
|
$this->db->query(" |
422
|
|
|
INSERT INTO product_tab_desc |
423
|
|
|
SET product_tab_id = '".(int)$product_tab_id."', |
424
|
|
|
heading = '".$this->db->escape($value['heading'])."', |
425
|
|
|
description = '".$this->db->escape($value['description'])."', |
426
|
|
|
product_id = '".(int)$product_id."', |
427
|
|
|
language_id = '".(int)$language_id."' |
428
|
|
|
"); |
429
|
|
|
} |
430
|
|
|
} |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
if (isset($data['image'])) { |
434
|
|
|
$this->db->query(" |
435
|
|
|
UPDATE product |
436
|
|
|
SET image = '" . $this->db->escape($data['image']) . "' |
437
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
438
|
|
|
"); |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
$this->db->query(" |
442
|
|
|
DELETE |
443
|
|
|
FROM product_description |
444
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
445
|
|
|
"); |
446
|
|
|
|
447
|
|
|
foreach ($data['product_description'] as $language_id => $value) { |
448
|
|
|
$this->db->query(" |
449
|
|
|
INSERT INTO product_description |
450
|
|
|
SET product_id = '" . (int)$product_id . "', |
451
|
|
|
language_id = '" . (int)$language_id . "', |
452
|
|
|
name = '" . $this->db->escape($value['name']) . "', |
453
|
|
|
description = '" . $this->db->escape($value['description']) . "', |
454
|
|
|
description_mini = '" . $this->db->escape($value['description_mini']) . "', |
455
|
|
|
tag = '" . $this->db->escape($value['tag']) . "', |
456
|
|
|
meta_title = '" . $this->db->escape($value['meta_title']) . "', |
457
|
|
|
meta_h1 = '" . $this->db->escape($value['meta_h1']) . "', |
458
|
|
|
meta_description = '" . $this->db->escape($value['meta_description']) . "' |
459
|
|
|
"); |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
$this->db->query(" |
463
|
|
|
DELETE |
464
|
|
|
FROM product_attribute |
465
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
466
|
|
|
"); |
467
|
|
|
|
468
|
|
|
if (!empty($data['product_attribute'])) { |
469
|
|
|
foreach ($data['product_attribute'] as $product_attribute) { |
470
|
|
|
if ($product_attribute['attribute_id']) { |
471
|
|
|
// Removes duplicates |
472
|
|
|
$this->db->query(" |
473
|
|
|
DELETE |
474
|
|
|
FROM product_attribute |
475
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
476
|
|
|
AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "' |
477
|
|
|
"); |
478
|
|
|
|
479
|
|
|
foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) { |
480
|
|
|
$this->db->query(" |
481
|
|
|
INSERT INTO product_attribute |
482
|
|
|
SET product_id = '" . (int)$product_id . "', |
483
|
|
|
attribute_id = '" . (int)$product_attribute['attribute_id'] . "', |
484
|
|
|
language_id = '" . (int)$language_id . "', |
485
|
|
|
text = '" . $this->db->escape($product_attribute_description['text']) . "' |
486
|
|
|
"); |
487
|
|
|
} |
488
|
|
|
} |
489
|
|
|
} |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
$this->db->query(" |
493
|
|
|
DELETE |
494
|
|
|
FROM product_option |
495
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
496
|
|
|
"); |
497
|
|
|
$this->db->query(" |
498
|
|
|
DELETE |
499
|
|
|
FROM product_option_value |
500
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
501
|
|
|
"); |
502
|
|
|
|
503
|
|
|
if (isset($data['product_option'])) { |
504
|
|
|
foreach ($data['product_option'] as $product_option) { |
505
|
|
|
if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox' || $product_option['type'] == 'image') { |
506
|
|
|
if (isset($product_option['product_option_value'])) { |
507
|
|
|
$this->db->query(" |
508
|
|
|
INSERT INTO product_option |
509
|
|
|
SET product_option_id = '" . (int)$product_option['product_option_id'] . "', |
510
|
|
|
product_id = '" . (int)$product_id . "', |
511
|
|
|
option_id = '" . (int)$product_option['option_id'] . "', |
512
|
|
|
required = '" . (int)$product_option['required'] . "' |
513
|
|
|
"); |
514
|
|
|
|
515
|
|
|
$product_option_id = $this->db->getLastId(); |
516
|
|
|
|
517
|
|
|
foreach ($product_option['product_option_value'] as $product_option_value) { |
518
|
|
|
$this->db->query(" |
519
|
|
|
INSERT INTO product_option_value |
520
|
|
|
SET product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "', |
521
|
|
|
product_option_id = '" . (int)$product_option_id . "', |
522
|
|
|
product_id = '" . (int)$product_id . "', |
523
|
|
|
option_id = '" . (int)$product_option['option_id'] . "', |
524
|
|
|
option_value_id = '" . (int)$product_option_value['option_value_id'] . "', |
525
|
|
|
quantity = '" . (int)$product_option_value['quantity'] . "', |
526
|
|
|
subtract = '" . (int)$product_option_value['subtract'] . "', |
527
|
|
|
price = '" . (float)$product_option_value['price'] . "', |
528
|
|
|
price_prefix = '" . $this->db->escape($product_option_value['price_prefix']) . "', |
529
|
|
|
points = '" . (int)$product_option_value['points'] . "', |
530
|
|
|
points_prefix = '" . $this->db->escape($product_option_value['points_prefix']) . "' |
531
|
|
|
"); |
532
|
|
|
} |
533
|
|
|
} |
534
|
|
|
} else { |
535
|
|
|
$this->db->query(" |
536
|
|
|
INSERT INTO product_option |
537
|
|
|
SET product_option_id = '" . (int)$product_option['product_option_id'] . "', |
538
|
|
|
product_id = '" . (int)$product_id . "', |
539
|
|
|
option_id = '" . (int)$product_option['option_id'] . "', |
540
|
|
|
value = '" . $this->db->escape($product_option['value']) . "', |
541
|
|
|
required = '" . (int)$product_option['required'] . "' |
542
|
|
|
"); |
543
|
|
|
} |
544
|
|
|
} |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
$this->db->query(" |
548
|
|
|
DELETE |
549
|
|
|
FROM product_discount |
550
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
551
|
|
|
"); |
552
|
|
|
|
553
|
|
|
if (isset($data['product_discount'])) { |
554
|
|
|
foreach ($data['product_discount'] as $product_discount) { |
555
|
|
|
$this->db->query(" |
556
|
|
|
INSERT INTO product_discount |
557
|
|
|
SET product_id = '" . (int)$product_id . "', |
558
|
|
|
customer_group_id = '" . (int)$product_discount['customer_group_id'] . "', |
559
|
|
|
quantity = '" . (int)$product_discount['quantity'] . "', |
560
|
|
|
priority = '" . (int)$product_discount['priority'] . "', |
561
|
|
|
price = '" . (float)$product_discount['price'] . "', |
562
|
|
|
date_start = '" . $this->db->escape($product_discount['date_start']) . "', |
563
|
|
|
date_end = '" . $this->db->escape($product_discount['date_end']) . "' |
564
|
|
|
"); |
565
|
|
|
} |
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
$this->db->query(" |
569
|
|
|
DELETE |
570
|
|
|
FROM product_special |
571
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
572
|
|
|
"); |
573
|
|
|
|
574
|
|
|
if (isset($data['product_special'])) { |
575
|
|
|
foreach ($data['product_special'] as $product_special) { |
576
|
|
|
$this->db->query(" |
577
|
|
|
INSERT INTO product_special |
578
|
|
|
SET product_id = '" . (int)$product_id . "', |
579
|
|
|
customer_group_id = '" . (int)$product_special['customer_group_id'] . "', |
580
|
|
|
priority = '" . (int)$product_special['priority'] . "', |
581
|
|
|
price = '" . (float)$product_special['price'] . "', |
582
|
|
|
date_start = '" . $this->db->escape($product_special['date_start']) . "', |
583
|
|
|
date_end = '" . $this->db->escape($product_special['date_end']) . "' |
584
|
|
|
"); |
585
|
|
|
} |
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
$this->db->query(" |
589
|
|
|
DELETE |
590
|
|
|
FROM product_image |
591
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
592
|
|
|
"); |
593
|
|
|
|
594
|
|
|
if (isset($data['product_image'])) { |
595
|
|
|
foreach ($data['product_image'] as $product_image) { |
596
|
|
|
$this->db->query(" |
597
|
|
|
INSERT INTO product_image |
598
|
|
|
SET product_id = '" . (int)$product_id . "', |
599
|
|
|
image = '" . $this->db->escape($product_image['image']) . "', |
600
|
|
|
sort_order = '" . (int)$product_image['sort_order'] . "' |
601
|
|
|
"); |
602
|
|
|
} |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
$this->db->query(" |
606
|
|
|
DELETE |
607
|
|
|
FROM product_to_download |
608
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
609
|
|
|
"); |
610
|
|
|
|
611
|
|
|
if (isset($data['product_download'])) { |
612
|
|
|
foreach ($data['product_download'] as $download_id) { |
613
|
|
|
$this->db->query(" |
614
|
|
|
INSERT INTO product_to_download |
615
|
|
|
SET product_id = '" . (int)$product_id . "', |
616
|
|
|
download_id = '" . (int)$download_id . "' |
617
|
|
|
"); |
618
|
|
|
} |
619
|
|
|
} |
620
|
|
|
|
621
|
|
|
$this->db->query(" |
622
|
|
|
DELETE |
623
|
|
|
FROM product_to_category |
624
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
625
|
|
|
"); |
626
|
|
|
|
627
|
|
|
if (isset($data['product_category'])) { |
628
|
|
|
foreach ($data['product_category'] as $category_id) { |
629
|
|
|
$this->db->query(" |
630
|
|
|
INSERT INTO product_to_category |
631
|
|
|
SET product_id = '" . (int)$product_id . "', |
632
|
|
|
category_id = '" . (int)$category_id . "' |
633
|
|
|
"); |
634
|
|
|
} |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
if (isset($data['main_category_id']) && $data['main_category_id'] > 0) { |
638
|
|
|
$this->db->query(" |
639
|
|
|
DELETE |
640
|
|
|
FROM product_to_category |
641
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
642
|
|
|
AND category_id = '" . (int)$data['main_category_id'] . "' |
643
|
|
|
"); |
644
|
|
|
$this->db->query(" |
645
|
|
|
INSERT INTO product_to_category |
646
|
|
|
SET product_id = '" . (int)$product_id . "', |
647
|
|
|
category_id = '" . (int)$data['main_category_id'] . "', |
648
|
|
|
main_category = 1 |
649
|
|
|
"); |
650
|
|
|
} elseif (isset($data['product_category'])) { |
651
|
|
|
$this->db->query(" |
652
|
|
|
UPDATE product_to_category |
653
|
|
|
SET main_category = 1 |
654
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
655
|
|
|
AND category_id = '" . (int)$data['product_category'][0] . "' |
656
|
|
|
"); |
657
|
|
|
} |
658
|
|
|
|
659
|
|
|
$this->db->query(" |
660
|
|
|
DELETE |
661
|
|
|
FROM product_filter |
662
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
663
|
|
|
"); |
664
|
|
|
|
665
|
|
|
if (isset($data['product_filter'])) { |
666
|
|
|
foreach ($data['product_filter'] as $filter_id) { |
667
|
|
|
$this->db->query(" |
668
|
|
|
INSERT INTO product_filter |
669
|
|
|
SET product_id = '" . (int)$product_id . "', |
670
|
|
|
filter_id = '" . (int)$filter_id . "' |
671
|
|
|
"); |
672
|
|
|
} |
673
|
|
|
} |
674
|
|
|
|
675
|
|
|
$this->db->query(" |
676
|
|
|
DELETE |
677
|
|
|
FROM product_related |
678
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
679
|
|
|
"); |
680
|
|
|
$this->db->query(" |
681
|
|
|
DELETE |
682
|
|
|
FROM product_related |
683
|
|
|
WHERE related_id = '" . (int)$product_id . "' |
684
|
|
|
"); |
685
|
|
|
|
686
|
|
|
if (isset($data['product_related'])) { |
687
|
|
|
foreach ($data['product_related'] as $related_id) { |
688
|
|
|
$this->db->query(" |
689
|
|
|
DELETE |
690
|
|
|
FROM product_related |
691
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
692
|
|
|
AND related_id = '" . (int)$related_id . "' |
693
|
|
|
"); |
694
|
|
|
$this->db->query(" |
695
|
|
|
INSERT INTO product_related |
696
|
|
|
SET product_id = '" . (int)$product_id . "', |
697
|
|
|
related_id = '" . (int)$related_id . "' |
698
|
|
|
"); |
699
|
|
|
$this->db->query(" |
700
|
|
|
DELETE |
701
|
|
|
FROM product_related |
702
|
|
|
WHERE product_id = '" . (int)$related_id . "' |
703
|
|
|
AND related_id = '" . (int)$product_id . "' |
704
|
|
|
"); |
705
|
|
|
$this->db->query(" |
706
|
|
|
INSERT INTO product_related |
707
|
|
|
SET product_id = '" . (int)$related_id . "', |
708
|
|
|
related_id = '" . (int)$product_id . "' |
709
|
|
|
"); |
710
|
|
|
} |
711
|
|
|
} |
712
|
|
|
|
713
|
|
|
$this->db->query(" |
714
|
|
|
DELETE |
715
|
|
|
FROM product_related_article |
716
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
717
|
|
|
"); |
718
|
|
|
|
719
|
|
|
if (isset($data['product_related_article'])) { |
720
|
|
|
foreach ($data['product_related_article'] as $article_id) { |
721
|
|
|
$this->db->query(" |
722
|
|
|
DELETE |
723
|
|
|
FROM product_related_article |
724
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
725
|
|
|
AND article_id = '" . (int)$article_id . "' |
726
|
|
|
"); |
727
|
|
|
$this->db->query(" |
728
|
|
|
INSERT INTO product_related_article |
729
|
|
|
SET product_id = '" . (int)$product_id . "', |
730
|
|
|
article_id = '" . (int)$article_id . "' |
731
|
|
|
"); |
732
|
|
|
} |
733
|
|
|
} |
734
|
|
|
|
735
|
|
|
$this->db->query(" |
736
|
|
|
DELETE |
737
|
|
|
FROM product_reward |
738
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
739
|
|
|
"); |
740
|
|
|
|
741
|
|
|
if (isset($data['product_reward'])) { |
742
|
|
|
foreach ($data['product_reward'] as $customer_group_id => $value) { |
743
|
|
|
if ((int)$value['points'] > 0) { |
744
|
|
|
$this->db->query(" |
745
|
|
|
INSERT INTO product_reward |
746
|
|
|
SET product_id = '" . (int)$product_id . "', |
747
|
|
|
customer_group_id = '" . (int)$customer_group_id . "', |
748
|
|
|
points = '" . (int)$value['points'] . "' |
749
|
|
|
"); |
750
|
|
|
} |
751
|
|
|
} |
752
|
|
|
} |
753
|
|
|
|
754
|
|
|
$this->db->query(" |
755
|
|
|
DELETE |
756
|
|
|
FROM product_to_layout |
757
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
758
|
|
|
"); |
759
|
|
|
|
760
|
|
|
if (isset($data['product_layout'])) { |
761
|
|
|
foreach ($data['product_layout'] as $store_id => $layout_id) { |
762
|
|
|
$this->db->query(" |
763
|
|
|
INSERT INTO product_to_layout |
764
|
|
|
SET product_id = '" . (int)$product_id . "', |
765
|
|
|
layout_id = '" . (int)$layout_id . "' |
766
|
|
|
"); |
767
|
|
|
} |
768
|
|
|
} |
769
|
|
|
|
770
|
|
|
$this->db->query(" |
771
|
|
|
DELETE |
772
|
|
|
FROM product_to_benefit |
773
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
774
|
|
|
"); |
775
|
|
|
if (isset($data['product_benefits'])) { |
776
|
|
|
foreach ($data['product_benefits'] as $benefit_id) { |
777
|
|
|
$this->db->query(" |
778
|
|
|
INSERT INTO product_to_benefit |
779
|
|
|
SET product_id = '" . (int)$product_id . "', |
780
|
|
|
benefit_id = '" . (int)$benefit_id . "' |
781
|
|
|
"); |
782
|
|
|
} |
783
|
|
|
} |
784
|
|
|
|
785
|
|
|
$this->db->query(" |
786
|
|
|
DELETE |
787
|
|
|
FROM product_to_sticker |
788
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
789
|
|
|
"); |
790
|
|
|
|
791
|
|
|
if (isset($data['product_stickers'])) { |
792
|
|
|
foreach ($data['product_stickers'] as $key => $sticker_id) { |
793
|
|
|
if ($sticker_id) { |
794
|
|
|
$this->db->query(" |
795
|
|
|
INSERT INTO product_to_sticker |
796
|
|
|
SET product_id = '" . (int)$product_id . "', |
797
|
|
|
position = '" . (int)$key . "', |
798
|
|
|
sticker_id = '" . (int)$sticker_id . "' |
799
|
|
|
"); |
800
|
|
|
} |
801
|
|
|
} |
802
|
|
|
} |
803
|
|
|
|
804
|
|
|
$this->db->query(" |
805
|
|
|
DELETE |
806
|
|
|
FROM url_alias |
807
|
|
|
WHERE query = 'product_id=" . (int)$product_id . "' |
808
|
|
|
"); |
809
|
|
|
|
810
|
|
|
$this->cache->delete('url_formatter'); |
811
|
|
|
|
812
|
|
|
|
813
|
|
|
if ($data['keyword']) { |
814
|
|
|
$this->db->query(" |
815
|
|
|
INSERT INTO url_alias |
816
|
|
|
SET query = 'product_id=" . (int)$product_id . "', |
817
|
|
|
keyword = '" . $this->db->escape($data['keyword']) . "' |
818
|
|
|
"); |
819
|
|
|
} |
820
|
|
|
|
821
|
|
|
$this->cache->delete('product'); |
822
|
|
|
} |
823
|
|
|
|
824
|
|
|
public function editProductStatus($product_id, $status) |
825
|
|
|
{ |
826
|
|
|
$this->db->query(" |
827
|
|
|
UPDATE product |
828
|
|
|
SET status = '" . (int)$status . "', |
829
|
|
|
date_modified = NOW() |
830
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
831
|
|
|
"); |
832
|
|
|
|
833
|
|
|
$this->cache->delete('product'); |
834
|
|
|
|
835
|
|
|
return $product_id; |
836
|
|
|
} |
837
|
|
|
|
838
|
|
|
public function copyProduct($product_id) |
839
|
|
|
{ |
840
|
|
|
$query = $this->db->query(" |
841
|
|
|
SELECT DISTINCT * |
842
|
|
|
FROM product p |
843
|
|
|
WHERE p.product_id = '" . (int)$product_id . "' |
844
|
|
|
"); |
845
|
|
|
|
846
|
|
|
if ($query->num_rows) { |
847
|
|
|
$data = $query->row; |
848
|
|
|
|
849
|
|
|
$data['sku'] = ''; |
850
|
|
|
$data['upc'] = ''; |
851
|
|
|
$data['viewed'] = '0'; |
852
|
|
|
$data['keyword'] = ''; |
853
|
|
|
$data['status'] = '0'; |
854
|
|
|
$data['noindex'] = '0'; |
855
|
|
|
|
856
|
|
|
$data['product_attribute'] = $this->getProductAttributes($product_id); |
857
|
|
|
$data['product_description'] = $this->getProductDescriptions($product_id); |
|
|
|
|
858
|
|
|
$data['product_discount'] = $this->getProductDiscounts($product_id); |
859
|
|
|
$data['product_filter'] = $this->getProductFilters($product_id); |
|
|
|
|
860
|
|
|
$data['product_image'] = $this->getProductImages($product_id); |
861
|
|
|
$data['product_option'] = $this->getProductOptions($product_id); |
862
|
|
|
$data['product_related'] = $this->getProductRelated($product_id); |
863
|
|
|
$data['product_related_article'] = $this->getArticleRelated($product_id); |
|
|
|
|
864
|
|
|
$data['product_reward'] = $this->getProductRewards($product_id); |
|
|
|
|
865
|
|
|
$data['product_special'] = $this->getProductSpecials($product_id); |
866
|
|
|
$data['product_category'] = $this->getProductCategories($product_id); |
|
|
|
|
867
|
|
|
$data['product_download'] = $this->getProductDownloads($product_id); |
|
|
|
|
868
|
|
|
$data['product_layout'] = $this->getProductLayouts($product_id); |
|
|
|
|
869
|
|
|
$data['product_benefits'] = $this->getBenefits($product_id); |
|
|
|
|
870
|
|
|
|
871
|
|
|
$this->addProduct($data); |
|
|
|
|
872
|
|
|
} |
873
|
|
|
} |
874
|
|
|
|
875
|
|
|
public function deleteProduct($product_id) |
876
|
|
|
{ |
877
|
|
|
$this->db->query(" |
878
|
|
|
DELETE |
879
|
|
|
FROM product |
880
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
881
|
|
|
"); |
882
|
|
|
$this->db->query(" |
883
|
|
|
DELETE |
884
|
|
|
FROM product_attribute |
885
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
886
|
|
|
"); |
887
|
|
|
$this->db->query(" |
888
|
|
|
DELETE |
889
|
|
|
FROM product_description |
890
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
891
|
|
|
"); |
892
|
|
|
$this->db->query(" |
893
|
|
|
DELETE |
894
|
|
|
FROM product_discount |
895
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
896
|
|
|
"); |
897
|
|
|
$this->db->query(" |
898
|
|
|
DELETE |
899
|
|
|
FROM product_filter |
900
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
901
|
|
|
"); |
902
|
|
|
$this->db->query(" |
903
|
|
|
DELETE |
904
|
|
|
FROM product_image |
905
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
906
|
|
|
"); |
907
|
|
|
$this->db->query(" |
908
|
|
|
DELETE |
909
|
|
|
FROM product_option |
910
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
911
|
|
|
"); |
912
|
|
|
$this->db->query(" |
913
|
|
|
DELETE |
914
|
|
|
FROM product_option_value |
915
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
916
|
|
|
"); |
917
|
|
|
$this->db->query(" |
918
|
|
|
DELETE |
919
|
|
|
FROM product_related |
920
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
921
|
|
|
"); |
922
|
|
|
$this->db->query(" |
923
|
|
|
DELETE |
924
|
|
|
FROM product_related |
925
|
|
|
WHERE related_id = '" . (int)$product_id . "' |
926
|
|
|
"); |
927
|
|
|
$this->db->query(" |
928
|
|
|
DELETE |
929
|
|
|
FROM product_related_article |
930
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
931
|
|
|
"); |
932
|
|
|
$this->db->query(" |
933
|
|
|
DELETE |
934
|
|
|
FROM product_reward |
935
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
936
|
|
|
"); |
937
|
|
|
$this->db->query(" |
938
|
|
|
DELETE |
939
|
|
|
FROM product_special |
940
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
941
|
|
|
"); |
942
|
|
|
$this->db->query(" |
943
|
|
|
DELETE |
944
|
|
|
FROM product_to_category |
945
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
946
|
|
|
"); |
947
|
|
|
$this->db->query(" |
948
|
|
|
DELETE |
949
|
|
|
FROM product_to_download |
950
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
951
|
|
|
"); |
952
|
|
|
$this->db->query(" |
953
|
|
|
DELETE |
954
|
|
|
FROM product_to_layout |
955
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
956
|
|
|
"); |
957
|
|
|
$this->db->query(" |
958
|
|
|
DELETE |
959
|
|
|
FROM review |
960
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
961
|
|
|
"); |
962
|
|
|
$this->db->query(" |
963
|
|
|
DELETE |
964
|
|
|
FROM url_alias |
965
|
|
|
WHERE query = 'product_id=" . (int)$product_id . "' |
966
|
|
|
"); |
967
|
|
|
$this->db->query(" |
968
|
|
|
DELETE |
969
|
|
|
FROM product_tab |
970
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
971
|
|
|
"); |
972
|
|
|
$this->db->query(" |
973
|
|
|
DELETE |
974
|
|
|
FROM product_tab_desc |
975
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
976
|
|
|
"); |
977
|
|
|
$this->db->query(" |
978
|
|
|
DELETE |
979
|
|
|
FROM product_to_benefit |
980
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
981
|
|
|
"); |
982
|
|
|
$this->db->query(" |
983
|
|
|
DELETE |
984
|
|
|
FROM product_to_sticker |
985
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
986
|
|
|
"); |
987
|
|
|
|
988
|
|
|
$this->cache->delete('product'); |
989
|
|
|
} |
990
|
|
|
|
991
|
|
|
public function getProductTabbyProductID($product_id) |
992
|
|
|
{ |
993
|
|
|
$product_tab_data = array(); |
994
|
|
|
$description = array(); |
995
|
|
|
$query = $this->db->query(" |
996
|
|
|
SELECT * |
997
|
|
|
FROM product_tab |
998
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
999
|
|
|
"); |
1000
|
|
|
|
1001
|
|
|
foreach ($query->rows as $result) { |
1002
|
|
|
$querys = $this->db->query(" |
1003
|
|
|
SELECT * |
1004
|
|
|
FROM product_tab_desc |
1005
|
|
|
WHERE product_tab_id = '" . (int)$result['product_tab_id']. "' |
1006
|
|
|
"); |
1007
|
|
|
foreach ($querys->rows as $row) { |
1008
|
|
|
$description[$row['language_id']]=array( |
1009
|
|
|
'heading' => $row['heading'], |
1010
|
|
|
'description' => $row['description'], |
1011
|
|
|
); |
1012
|
|
|
} |
1013
|
|
|
$product_tab_data[]=array( |
1014
|
|
|
'status' => $result['status'], |
1015
|
|
|
'sort_order' => $result['sort_order'], |
1016
|
|
|
'description' => $description, |
1017
|
|
|
); |
1018
|
|
|
} |
1019
|
|
|
return $product_tab_data; |
1020
|
|
|
} |
1021
|
|
|
|
1022
|
|
|
public function getProduct($product_id) |
1023
|
|
|
{ |
1024
|
|
|
$query = $this->db->query(" |
1025
|
|
|
SELECT DISTINCT *, |
1026
|
|
|
( |
1027
|
|
|
SELECT keyword |
1028
|
|
|
FROM url_alias |
1029
|
|
|
WHERE query = 'product_id=" . (int)$product_id . "') AS keyword |
1030
|
|
|
FROM product p |
1031
|
|
|
LEFT JOIN product_description pd ON (p.product_id = pd.product_id) |
1032
|
|
|
WHERE p.product_id = '" . (int)$product_id . "' |
1033
|
|
|
AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' |
1034
|
|
|
"); |
1035
|
|
|
|
1036
|
|
|
return $query->row; |
1037
|
|
|
} |
1038
|
|
|
|
1039
|
|
|
public function getProducts($data = array()) |
1040
|
|
|
{ |
1041
|
|
|
$sql = " |
1042
|
|
|
SELECT * |
1043
|
|
|
FROM product p |
1044
|
|
|
LEFT JOIN product_description pd ON (p.product_id = pd.product_id) |
1045
|
|
|
WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' |
1046
|
|
|
"; |
1047
|
|
|
|
1048
|
|
|
if (isset($data['filter_category']) && !is_null($data['filter_category'])) { |
1049
|
|
|
preg_match('/(.*)(WHERE pd\.language_id.*)/', $sql, $sql_crutch_matches); |
1050
|
|
|
if (isset($sql_crutch_matches[2])) { |
1051
|
|
|
$sql = $sql_crutch_matches[1] . " LEFT JOIN product_to_category p2c ON (p.product_id = p2c.product_id)" . $sql_crutch_matches[2]; |
|
|
|
|
1052
|
|
|
} else { |
1053
|
|
|
$data['filter_category'] = null; |
1054
|
|
|
} |
1055
|
|
|
} |
1056
|
|
|
|
1057
|
|
|
if (!empty($data['filter_name'])) { |
1058
|
|
|
$sql .= " AND pd.name LIKE '%" . $this->db->escape($data['filter_name']) . "%'"; |
1059
|
|
|
} |
1060
|
|
|
|
1061
|
|
|
if (!empty($data['filter_model'])) { |
1062
|
|
|
$sql .= " AND p.model LIKE '%" . $this->db->escape($data['filter_model']) . "%'"; |
1063
|
|
|
} |
1064
|
|
|
|
1065
|
|
|
if (isset($data['filter_category']) && !is_null($data['filter_category'])) { |
1066
|
|
|
if (!empty($data['filter_category']) && !empty($data['filter_sub_category'])) { |
1067
|
|
|
$implode_data = array(); |
1068
|
|
|
|
1069
|
|
|
$this->load->model('catalog/category'); |
1070
|
|
|
|
1071
|
|
|
$categories = $this->model_catalog_category->getCategoriesChildren($data['filter_category']); |
1072
|
|
|
|
1073
|
|
|
foreach ($categories as $category) { |
1074
|
|
|
$implode_data[] = "p2c.category_id = '" . (int)$category['category_id'] . "'"; |
1075
|
|
|
} |
1076
|
|
|
|
1077
|
|
|
$sql .= " AND (" . implode(' OR ', $implode_data) . ")"; |
|
|
|
|
1078
|
|
|
} else { |
1079
|
|
|
if ((int)$data['filter_category'] > 0) { |
1080
|
|
|
$sql .= " AND p2c.category_id = '" . (int)$data['filter_category'] . "'"; |
1081
|
|
|
} else { |
1082
|
|
|
$sql .= " AND p2c.category_id IS NULL"; |
|
|
|
|
1083
|
|
|
} |
1084
|
|
|
} |
1085
|
|
|
} |
1086
|
|
|
|
1087
|
|
|
if (isset($data['filter_manufacturer']) && !is_null($data['filter_manufacturer'])) { |
1088
|
|
|
$sql .= " AND p.manufacturer_id = '" . (int)$data['filter_manufacturer'] . "'"; |
1089
|
|
|
} |
1090
|
|
|
|
1091
|
|
|
if (isset($data['filter_price']) && !is_null($data['filter_price'])) { |
1092
|
|
|
$sql .= " AND p.price LIKE '" . $this->db->escape($data['filter_price']) . "%'"; |
1093
|
|
|
} |
1094
|
|
|
|
1095
|
|
|
if (isset($data['filter_price_min']) && !is_null($data['filter_price_min'])) { |
1096
|
|
|
$sql .= " AND p.price >= '" . (float)$data['filter_price_min'] . "'"; |
1097
|
|
|
} |
1098
|
|
|
|
1099
|
|
|
if (isset($data['filter_price_max']) && !is_null($data['filter_price_max'])) { |
1100
|
|
|
$sql .= " AND p.price <= '" . (float)$data['filter_price_max'] . "'"; |
1101
|
|
|
} |
1102
|
|
|
|
1103
|
|
|
if (isset($data['filter_quantity']) && !is_null($data['filter_quantity'])) { |
1104
|
|
|
$sql .= " AND p.quantity = '" . (int)$data['filter_quantity'] . "'"; |
1105
|
|
|
} |
1106
|
|
|
|
1107
|
|
|
if (isset($data['filter_quantity_min']) && !is_null($data['filter_quantity_min'])) { |
1108
|
|
|
$sql .= " AND p.quantity >= '" . (int)$data['filter_quantity_min'] . "'"; |
1109
|
|
|
} |
1110
|
|
|
|
1111
|
|
|
if (isset($data['filter_quantity_max']) && !is_null($data['filter_quantity_max'])) { |
1112
|
|
|
$sql .= " AND p.quantity <= '" . (int)$data['filter_quantity_max'] . "'"; |
1113
|
|
|
} |
1114
|
|
|
|
1115
|
|
|
if (isset($data['filter_status']) && !is_null($data['filter_status'])) { |
1116
|
|
|
$sql .= " AND p.status = '" . (int)$data['filter_status'] . "'"; |
1117
|
|
|
} |
1118
|
|
|
|
1119
|
|
|
if (isset($data['filter_noindex']) && !is_null($data['filter_noindex'])) { |
1120
|
|
|
$sql .= " AND p.noindex = '" . (int)$data['filter_noindex'] . "'"; |
1121
|
|
|
} |
1122
|
|
|
|
1123
|
|
|
if (isset($data['filter_image']) && !is_null($data['filter_image'])) { |
1124
|
|
|
if ($data['filter_image'] == 1) { |
1125
|
|
|
$sql .= " AND (p.image IS NOT NULL AND p.image <> '' AND p.image <> 'no_image.png')"; |
1126
|
|
|
} else { |
1127
|
|
|
$sql .= " AND (p.image IS NULL OR p.image = '' OR p.image = 'no_image.png')"; |
1128
|
|
|
} |
1129
|
|
|
} |
1130
|
|
|
|
1131
|
|
|
$sql .= " GROUP BY p.product_id"; |
|
|
|
|
1132
|
|
|
|
1133
|
|
|
$sort_data = array( |
1134
|
|
|
'pd.name', |
1135
|
|
|
'p.model', |
1136
|
|
|
'p.price', |
1137
|
|
|
'p.quantity', |
1138
|
|
|
'p.status', |
1139
|
|
|
'p.noindex', |
1140
|
|
|
'p.sort_order' |
1141
|
|
|
); |
1142
|
|
|
|
1143
|
|
|
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { |
1144
|
|
|
$sql .= " ORDER BY " . $data['sort']; |
|
|
|
|
1145
|
|
|
} else { |
1146
|
|
|
$sql .= " ORDER BY pd.name"; |
|
|
|
|
1147
|
|
|
} |
1148
|
|
|
|
1149
|
|
|
if (isset($data['order']) && ($data['order'] == 'DESC')) { |
1150
|
|
|
$sql .= " DESC"; |
|
|
|
|
1151
|
|
|
} else { |
1152
|
|
|
$sql .= " ASC"; |
|
|
|
|
1153
|
|
|
} |
1154
|
|
|
|
1155
|
|
|
if (isset($data['start']) || isset($data['limit'])) { |
1156
|
|
|
if ($data['start'] < 0) { |
1157
|
|
|
$data['start'] = 0; |
1158
|
|
|
} |
1159
|
|
|
|
1160
|
|
|
if ($data['limit'] < 1) { |
1161
|
|
|
$data['limit'] = 20; |
1162
|
|
|
} |
1163
|
|
|
|
1164
|
|
|
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; |
|
|
|
|
1165
|
|
|
} |
1166
|
|
|
|
1167
|
|
|
$query = $this->db->query($sql); |
1168
|
|
|
|
1169
|
|
|
return $query->rows; |
1170
|
|
|
} |
1171
|
|
|
|
1172
|
|
|
public function getProductsByCategoryId($category_id) |
1173
|
|
|
{ |
1174
|
|
|
$query = $this->db->query(" |
1175
|
|
|
SELECT * |
1176
|
|
|
FROM product p |
1177
|
|
|
LEFT JOIN product_description pd ON (p.product_id = pd.product_id) |
1178
|
|
|
LEFT JOIN product_to_category p2c ON (p.product_id = p2c.product_id) |
1179
|
|
|
WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' |
1180
|
|
|
AND p2c.category_id = '" . (int)$category_id . "' |
1181
|
|
|
ORDER BY pd.name ASC |
1182
|
|
|
"); |
1183
|
|
|
|
1184
|
|
|
return $query->rows; |
1185
|
|
|
} |
1186
|
|
|
|
1187
|
|
|
public function getProductDescriptions($product_id) |
1188
|
|
|
{ |
1189
|
|
|
$product_description_data = array(); |
1190
|
|
|
|
1191
|
|
|
$query = $this->db->query(" |
1192
|
|
|
SELECT * |
1193
|
|
|
FROM product_description |
1194
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
1195
|
|
|
"); |
1196
|
|
|
|
1197
|
|
|
foreach ($query->rows as $result) { |
1198
|
|
|
$product_description_data[$result['language_id']] = array( |
1199
|
|
|
'name' => $result['name'], |
1200
|
|
|
'description' => $result['description'], |
1201
|
|
|
'description_mini' => $result['description_mini'], |
1202
|
|
|
'meta_title' => $result['meta_title'], |
1203
|
|
|
'meta_h1' => $result['meta_h1'], |
1204
|
|
|
'meta_description' => $result['meta_description'], |
1205
|
|
|
'tag' => $result['tag'] |
1206
|
|
|
); |
1207
|
|
|
} |
1208
|
|
|
|
1209
|
|
|
return $product_description_data; |
1210
|
|
|
} |
1211
|
|
|
|
1212
|
|
|
public function getProductCategories($product_id) |
1213
|
|
|
{ |
1214
|
|
|
$product_category_data = array(); |
1215
|
|
|
|
1216
|
|
|
$query = $this->db->query(" |
1217
|
|
|
SELECT * |
1218
|
|
|
FROM product_to_category |
1219
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
1220
|
|
|
"); |
1221
|
|
|
|
1222
|
|
|
foreach ($query->rows as $result) { |
1223
|
|
|
$product_category_data[] = $result['category_id']; |
1224
|
|
|
} |
1225
|
|
|
|
1226
|
|
|
return $product_category_data; |
1227
|
|
|
} |
1228
|
|
|
|
1229
|
|
|
public function getProductMainCategoryId($product_id) |
1230
|
|
|
{ |
1231
|
|
|
$query = $this->db->query(" |
1232
|
|
|
SELECT category_id |
1233
|
|
|
FROM product_to_category |
1234
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
1235
|
|
|
AND main_category = '1' |
1236
|
|
|
LIMIT 1 |
1237
|
|
|
"); |
1238
|
|
|
|
1239
|
|
|
return ($query->num_rows ? (int)$query->row['category_id'] : 0); |
1240
|
|
|
} |
1241
|
|
|
|
1242
|
|
|
public function getProductFilters($product_id) |
1243
|
|
|
{ |
1244
|
|
|
$product_filter_data = array(); |
1245
|
|
|
|
1246
|
|
|
$query = $this->db->query(" |
1247
|
|
|
SELECT * |
1248
|
|
|
FROM product_filter |
1249
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
1250
|
|
|
"); |
1251
|
|
|
|
1252
|
|
|
foreach ($query->rows as $result) { |
1253
|
|
|
$product_filter_data[] = $result['filter_id']; |
1254
|
|
|
} |
1255
|
|
|
|
1256
|
|
|
return $product_filter_data; |
1257
|
|
|
} |
1258
|
|
|
|
1259
|
|
|
public function getProductAttributes($product_id) |
1260
|
|
|
{ |
1261
|
|
|
$product_attribute_data = array(); |
1262
|
|
|
|
1263
|
|
|
$product_attribute_query = $this->db->query(" |
1264
|
|
|
SELECT attribute_id |
1265
|
|
|
FROM product_attribute |
1266
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
1267
|
|
|
GROUP BY attribute_id |
1268
|
|
|
"); |
1269
|
|
|
|
1270
|
|
|
foreach ($product_attribute_query->rows as $product_attribute) { |
1271
|
|
|
$product_attribute_description_data = array(); |
1272
|
|
|
|
1273
|
|
|
$product_attribute_description_query = $this->db->query(" |
1274
|
|
|
SELECT * |
1275
|
|
|
FROM product_attribute |
1276
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
1277
|
|
|
AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "' |
1278
|
|
|
"); |
1279
|
|
|
|
1280
|
|
|
foreach ($product_attribute_description_query->rows as $product_attribute_description) { |
1281
|
|
|
$product_attribute_description_data[$product_attribute_description['language_id']] = array('text' => $product_attribute_description['text']); |
1282
|
|
|
} |
1283
|
|
|
|
1284
|
|
|
$product_attribute_data[] = array( |
1285
|
|
|
'attribute_id' => $product_attribute['attribute_id'], |
1286
|
|
|
'product_attribute_description' => $product_attribute_description_data |
1287
|
|
|
); |
1288
|
|
|
} |
1289
|
|
|
|
1290
|
|
|
return $product_attribute_data; |
1291
|
|
|
} |
1292
|
|
|
|
1293
|
|
|
public function getProductOptions($product_id) |
1294
|
|
|
{ |
1295
|
|
|
$product_option_data = array(); |
1296
|
|
|
|
1297
|
|
|
$product_option_query = $this->db->query(" |
1298
|
|
|
SELECT * |
1299
|
|
|
FROM `product_option` po |
1300
|
|
|
LEFT JOIN `option` o ON (po.option_id = o.option_id) |
1301
|
|
|
LEFT JOIN `option_description` od ON (o.option_id = od.option_id) |
1302
|
|
|
WHERE po.product_id = '" . (int)$product_id . "' |
1303
|
|
|
AND od.language_id = '" . (int)$this->config->get('config_language_id') . "' |
1304
|
|
|
"); |
1305
|
|
|
|
1306
|
|
|
foreach ($product_option_query->rows as $product_option) { |
1307
|
|
|
$product_option_value_data = array(); |
1308
|
|
|
|
1309
|
|
|
$product_option_value_query = $this->db->query(" |
1310
|
|
|
SELECT * |
1311
|
|
|
FROM product_option_value pov |
1312
|
|
|
LEFT JOIN option_value ov ON(pov.option_value_id = ov.option_value_id) |
1313
|
|
|
WHERE pov.product_option_id = '" . (int)$product_option['product_option_id'] . "' |
1314
|
|
|
ORDER BY ov.sort_order ASC |
1315
|
|
|
"); |
1316
|
|
|
|
1317
|
|
|
foreach ($product_option_value_query->rows as $product_option_value) { |
1318
|
|
|
$product_option_value_data[] = array( |
1319
|
|
|
'product_option_value_id' => $product_option_value['product_option_value_id'], |
1320
|
|
|
'option_value_id' => $product_option_value['option_value_id'], |
1321
|
|
|
'quantity' => $product_option_value['quantity'], |
1322
|
|
|
'subtract' => $product_option_value['subtract'], |
1323
|
|
|
'price' => $product_option_value['price'], |
1324
|
|
|
'price_prefix' => $product_option_value['price_prefix'], |
1325
|
|
|
'points' => $product_option_value['points'], |
1326
|
|
|
'points_prefix' => $product_option_value['points_prefix'] |
1327
|
|
|
); |
1328
|
|
|
} |
1329
|
|
|
|
1330
|
|
|
$product_option_data[] = array( |
1331
|
|
|
'product_option_id' => $product_option['product_option_id'], |
1332
|
|
|
'product_option_value' => $product_option_value_data, |
1333
|
|
|
'option_id' => $product_option['option_id'], |
1334
|
|
|
'name' => $product_option['name'], |
1335
|
|
|
'type' => $product_option['type'], |
1336
|
|
|
'value' => $product_option['value'], |
1337
|
|
|
'required' => $product_option['required'] |
1338
|
|
|
); |
1339
|
|
|
} |
1340
|
|
|
|
1341
|
|
|
return $product_option_data; |
1342
|
|
|
} |
1343
|
|
|
|
1344
|
|
|
public function getProductOptionValue($product_id, $product_option_value_id) |
1345
|
|
|
{ |
1346
|
|
|
$query = $this->db->query(" |
1347
|
|
|
SELECT pov.option_value_id, |
1348
|
|
|
ovd.name, |
1349
|
|
|
pov.quantity, |
1350
|
|
|
pov.subtract, |
1351
|
|
|
pov.price, |
1352
|
|
|
pov.price_prefix, |
1353
|
|
|
pov.points, |
1354
|
|
|
pov.points_prefix, |
1355
|
|
|
FROM product_option_value pov |
1356
|
|
|
LEFT JOIN option_value ov ON (pov.option_value_id = ov.option_value_id) |
1357
|
|
|
LEFT JOIN option_value_description ovd ON (ov.option_value_id = ovd.option_value_id) |
1358
|
|
|
WHERE pov.product_id = '" . (int)$product_id . "' |
1359
|
|
|
AND pov.product_option_value_id = '" . (int)$product_option_value_id . "' |
1360
|
|
|
AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "' |
1361
|
|
|
"); |
1362
|
|
|
|
1363
|
|
|
return $query->row; |
1364
|
|
|
} |
1365
|
|
|
|
1366
|
|
|
public function getProductImages($product_id) |
1367
|
|
|
{ |
1368
|
|
|
$query = $this->db->query(" |
1369
|
|
|
SELECT * |
1370
|
|
|
FROM product_image |
1371
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
1372
|
|
|
ORDER BY sort_order ASC |
1373
|
|
|
"); |
1374
|
|
|
|
1375
|
|
|
return $query->rows; |
1376
|
|
|
} |
1377
|
|
|
|
1378
|
|
|
public function getProductDiscounts($product_id) |
1379
|
|
|
{ |
1380
|
|
|
$query = $this->db->query(" |
1381
|
|
|
SELECT * |
1382
|
|
|
FROM product_discount |
1383
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
1384
|
|
|
ORDER BY quantity, priority, price |
1385
|
|
|
"); |
1386
|
|
|
|
1387
|
|
|
return $query->rows; |
1388
|
|
|
} |
1389
|
|
|
|
1390
|
|
|
public function getProductSpecials($product_id) |
1391
|
|
|
{ |
1392
|
|
|
$query = $this->db->query(" |
1393
|
|
|
SELECT * |
1394
|
|
|
FROM product_special |
1395
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
1396
|
|
|
ORDER BY priority, price |
1397
|
|
|
"); |
1398
|
|
|
|
1399
|
|
|
return $query->rows; |
1400
|
|
|
} |
1401
|
|
|
|
1402
|
|
|
public function getProductRewards($product_id) |
1403
|
|
|
{ |
1404
|
|
|
$product_reward_data = array(); |
1405
|
|
|
|
1406
|
|
|
$query = $this->db->query(" |
1407
|
|
|
SELECT * |
1408
|
|
|
FROM product_reward |
1409
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
1410
|
|
|
"); |
1411
|
|
|
|
1412
|
|
|
foreach ($query->rows as $result) { |
1413
|
|
|
$product_reward_data[$result['customer_group_id']] = array('points' => $result['points']); |
1414
|
|
|
} |
1415
|
|
|
|
1416
|
|
|
return $product_reward_data; |
1417
|
|
|
} |
1418
|
|
|
|
1419
|
|
|
public function getProductDownloads($product_id) |
1420
|
|
|
{ |
1421
|
|
|
$product_download_data = array(); |
1422
|
|
|
|
1423
|
|
|
$query = $this->db->query(" |
1424
|
|
|
SELECT * |
1425
|
|
|
FROM product_to_download |
1426
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
1427
|
|
|
"); |
1428
|
|
|
|
1429
|
|
|
foreach ($query->rows as $result) { |
1430
|
|
|
$product_download_data[] = $result['download_id']; |
1431
|
|
|
} |
1432
|
|
|
|
1433
|
|
|
return $product_download_data; |
1434
|
|
|
} |
1435
|
|
|
|
1436
|
|
|
public function getProductLayouts($product_id) |
1437
|
|
|
{ |
1438
|
|
|
$product_layout_data = array(); |
1439
|
|
|
|
1440
|
|
|
$query = $this->db->query(" |
1441
|
|
|
SELECT * |
1442
|
|
|
FROM product_to_layout |
1443
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
1444
|
|
|
"); |
1445
|
|
|
|
1446
|
|
|
foreach ($query->rows as $result) { |
1447
|
|
|
$product_layout_data = $result['layout_id']; |
1448
|
|
|
} |
1449
|
|
|
|
1450
|
|
|
return $product_layout_data; |
1451
|
|
|
} |
1452
|
|
|
|
1453
|
|
|
public function getProductRelated($product_id) |
1454
|
|
|
{ |
1455
|
|
|
$product_related_data = array(); |
1456
|
|
|
|
1457
|
|
|
$query = $this->db->query(" |
1458
|
|
|
SELECT * |
1459
|
|
|
FROM product_related |
1460
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
1461
|
|
|
"); |
1462
|
|
|
|
1463
|
|
|
foreach ($query->rows as $result) { |
1464
|
|
|
$product_related_data[] = $result['related_id']; |
1465
|
|
|
} |
1466
|
|
|
|
1467
|
|
|
return $product_related_data; |
1468
|
|
|
} |
1469
|
|
|
|
1470
|
|
|
public function getArticleRelated($product_id) |
1471
|
|
|
{ |
1472
|
|
|
$article_related_data = array(); |
1473
|
|
|
|
1474
|
|
|
$query = $this->db->query(" |
1475
|
|
|
SELECT * |
1476
|
|
|
FROM product_related_article |
1477
|
|
|
WHERE product_id = '" . (int)$product_id . "' |
1478
|
|
|
"); |
1479
|
|
|
|
1480
|
|
|
foreach ($query->rows as $result) { |
1481
|
|
|
$article_related_data[] = $result['article_id']; |
1482
|
|
|
} |
1483
|
|
|
|
1484
|
|
|
return $article_related_data; |
1485
|
|
|
} |
1486
|
|
|
|
1487
|
|
|
public function getBenefits($product_id) |
1488
|
|
|
{ |
1489
|
|
|
$benefits = array(); |
1490
|
|
|
|
1491
|
|
|
$query = $this->db->query(" |
|
|
|
|
1492
|
|
|
SELECT benefit_id |
1493
|
|
|
FROM `product_to_benefit` |
1494
|
|
|
WHERE product_id = |
1495
|
|
|
" . (int)$product_id); |
1496
|
|
|
|
1497
|
|
|
foreach ($query->rows as $result) { |
1498
|
|
|
$benefits[] = $result['benefit_id']; |
1499
|
|
|
} |
1500
|
|
|
|
1501
|
|
|
return $benefits; |
1502
|
|
|
} |
1503
|
|
|
|
1504
|
|
|
public function getTotalProducts($data = array()) |
1505
|
|
|
{ |
1506
|
|
|
$sql = " |
|
|
|
|
1507
|
|
|
SELECT COUNT(DISTINCT p.product_id) AS total |
1508
|
|
|
FROM product p |
1509
|
|
|
LEFT JOIN product_description pd ON (p.product_id = pd.product_id) |
1510
|
|
|
"; |
1511
|
|
|
|
1512
|
|
|
if (isset($data['filter_category']) && !is_null($data['filter_category'])) { |
1513
|
|
|
$sql .= " LEFT JOIN product_to_category p2c ON (p.product_id = p2c.product_id)"; |
|
|
|
|
1514
|
|
|
} |
1515
|
|
|
|
1516
|
|
|
$sql .= " WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "'"; |
1517
|
|
|
|
1518
|
|
|
if (!empty($data['filter_name'])) { |
1519
|
|
|
$sql .= " AND pd.name LIKE '%" . $this->db->escape($data['filter_name']) . "%'"; |
1520
|
|
|
} |
1521
|
|
|
|
1522
|
|
|
if (!empty($data['filter_model'])) { |
1523
|
|
|
$sql .= " AND p.model LIKE '%" . $this->db->escape($data['filter_model']) . "%'"; |
1524
|
|
|
} |
1525
|
|
|
|
1526
|
|
|
if (isset($data['filter_category']) && !is_null($data['filter_category'])) { |
1527
|
|
|
if (!empty($data['filter_category']) && !empty($data['filter_sub_category'])) { |
1528
|
|
|
$implode_data = array(); |
1529
|
|
|
|
1530
|
|
|
$this->load->model('catalog/category'); |
1531
|
|
|
|
1532
|
|
|
$categories = $this->model_catalog_category->getCategoriesChildren($data['filter_category']); |
1533
|
|
|
|
1534
|
|
|
foreach ($categories as $category) { |
1535
|
|
|
$implode_data[] = "p2c.category_id = '" . (int)$category['category_id'] . "'"; |
1536
|
|
|
} |
1537
|
|
|
|
1538
|
|
|
$sql .= " AND (" . implode(' OR ', $implode_data) . ")"; |
|
|
|
|
1539
|
|
|
} else { |
1540
|
|
|
if ((int)$data['filter_category'] > 0) { |
1541
|
|
|
$sql .= " AND p2c.category_id = '" . (int)$data['filter_category'] . "'"; |
1542
|
|
|
} else { |
1543
|
|
|
$sql .= " AND p2c.category_id IS NULL"; |
|
|
|
|
1544
|
|
|
} |
1545
|
|
|
} |
1546
|
|
|
} |
1547
|
|
|
|
1548
|
|
|
if (isset($data['filter_manufacturer']) && !is_null($data['filter_manufacturer'])) { |
1549
|
|
|
$sql .= " AND p.manufacturer_id = '" . (int)$data['filter_manufacturer'] . "'"; |
1550
|
|
|
} |
1551
|
|
|
|
1552
|
|
|
if (isset($data['filter_price']) && !is_null($data['filter_price'])) { |
1553
|
|
|
$sql .= " AND p.price LIKE '" . $this->db->escape($data['filter_price']) . "%'"; |
1554
|
|
|
} |
1555
|
|
|
|
1556
|
|
|
if (isset($data['filter_price_min']) && !is_null($data['filter_price_min'])) { |
1557
|
|
|
$sql .= " AND p.price >= '" . (float)$data['filter_price_min'] . "'"; |
1558
|
|
|
} |
1559
|
|
|
|
1560
|
|
|
if (isset($data['filter_price_max']) && !is_null($data['filter_price_max'])) { |
1561
|
|
|
$sql .= " AND p.price <= '" . (float)$data['filter_price_max'] . "'"; |
1562
|
|
|
} |
1563
|
|
|
|
1564
|
|
|
if (isset($data['filter_quantity']) && !is_null($data['filter_quantity'])) { |
1565
|
|
|
$sql .= " AND p.quantity = '" . (int)$data['filter_quantity'] . "'"; |
1566
|
|
|
} |
1567
|
|
|
|
1568
|
|
|
if (isset($data['filter_quantity_min']) && !is_null($data['filter_quantity_min'])) { |
1569
|
|
|
$sql .= " AND p.quantity >= '" . (int)$data['filter_quantity_min'] . "'"; |
1570
|
|
|
} |
1571
|
|
|
|
1572
|
|
|
if (isset($data['filter_quantity_max']) && !is_null($data['filter_quantity_max'])) { |
1573
|
|
|
$sql .= " AND p.quantity <= '" . (int)$data['filter_quantity_max'] . "'"; |
1574
|
|
|
} |
1575
|
|
|
|
1576
|
|
|
if (isset($data['filter_status']) && !is_null($data['filter_status'])) { |
1577
|
|
|
$sql .= " AND p.status = '" . (int)$data['filter_status'] . "'"; |
1578
|
|
|
} |
1579
|
|
|
|
1580
|
|
|
if (isset($data['filter_noindex']) && !is_null($data['filter_noindex'])) { |
1581
|
|
|
$sql .= " AND p.noindex = '" . (int)$data['filter_noindex'] . "'"; |
1582
|
|
|
} |
1583
|
|
|
|
1584
|
|
|
if (isset($data['filter_image']) && !is_null($data['filter_image'])) { |
1585
|
|
|
if ($data['filter_image'] == 1) { |
1586
|
|
|
$sql .= " AND (p.image IS NOT NULL AND p.image <> '' AND p.image <> 'no_image.png')"; |
1587
|
|
|
} else { |
1588
|
|
|
$sql .= " AND (p.image IS NULL OR p.image = '' OR p.image = 'no_image.png')"; |
1589
|
|
|
} |
1590
|
|
|
} |
1591
|
|
|
|
1592
|
|
|
$query = $this->db->query($sql); |
1593
|
|
|
|
1594
|
|
|
return $query->row['total']; |
1595
|
|
|
} |
1596
|
|
|
|
1597
|
|
|
public function getTotalProductsByStockStatusId($stock_status_id) |
1598
|
|
|
{ |
1599
|
|
|
$query = $this->db->query(" |
1600
|
|
|
SELECT COUNT(*) AS total |
1601
|
|
|
FROM product |
1602
|
|
|
WHERE stock_status_id = '" . (int)$stock_status_id . "' |
1603
|
|
|
"); |
1604
|
|
|
|
1605
|
|
|
return $query->row['total']; |
1606
|
|
|
} |
1607
|
|
|
|
1608
|
|
|
public function getTotalProductsByDownloadId($download_id) |
1609
|
|
|
{ |
1610
|
|
|
$query = $this->db->query(" |
1611
|
|
|
SELECT COUNT(*) AS total |
1612
|
|
|
FROM product_to_download |
1613
|
|
|
WHERE download_id = '" . (int)$download_id . "' |
1614
|
|
|
"); |
1615
|
|
|
|
1616
|
|
|
return $query->row['total']; |
1617
|
|
|
} |
1618
|
|
|
|
1619
|
|
|
public function getTotalProductsByManufacturerId($manufacturer_id) |
1620
|
|
|
{ |
1621
|
|
|
$query = $this->db->query(" |
1622
|
|
|
SELECT COUNT(*) AS total |
1623
|
|
|
FROM product |
1624
|
|
|
WHERE manufacturer_id = '" . (int)$manufacturer_id . "' |
1625
|
|
|
"); |
1626
|
|
|
|
1627
|
|
|
return $query->row['total']; |
1628
|
|
|
} |
1629
|
|
|
|
1630
|
|
|
public function getTotalProductsByAttributeId($attribute_id) |
1631
|
|
|
{ |
1632
|
|
|
$query = $this->db->query(" |
1633
|
|
|
SELECT COUNT(*) AS total |
1634
|
|
|
FROM product_attribute |
1635
|
|
|
WHERE attribute_id = '" . (int)$attribute_id . "' |
1636
|
|
|
"); |
1637
|
|
|
|
1638
|
|
|
return $query->row['total']; |
1639
|
|
|
} |
1640
|
|
|
|
1641
|
|
|
public function getTotalProductsByOptionId($option_id) |
1642
|
|
|
{ |
1643
|
|
|
$query = $this->db->query(" |
1644
|
|
|
SELECT COUNT(*) AS total |
1645
|
|
|
FROM product_option |
1646
|
|
|
WHERE option_id = '" . (int)$option_id . "' |
1647
|
|
|
"); |
1648
|
|
|
|
1649
|
|
|
return $query->row['total']; |
1650
|
|
|
} |
1651
|
|
|
|
1652
|
|
|
public function getTotalProductsByLayoutId($layout_id) |
1653
|
|
|
{ |
1654
|
|
|
$query = $this->db->query(" |
1655
|
|
|
SELECT COUNT(*) AS total |
1656
|
|
|
FROM product_to_layout |
1657
|
|
|
WHERE layout_id = '" . (int)$layout_id . "' |
1658
|
|
|
"); |
1659
|
|
|
|
1660
|
|
|
return $query->row['total']; |
1661
|
|
|
} |
1662
|
|
|
} |
1663
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.