oct_stickers.php
4.67 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
<?php
/**
* @copyright OCTemplates
* @support https://octemplates.net/
* @license LICENSE.txt
*/
class ModelOCTemplatesStickersOctStickers extends Model {
public function getOCTStickers($result) {
$oct_stickers_data = $oct_stikers = [];
if ($this->config->get('oct_stickers_status')) {
$oct_stickers = $this->config->get('oct_stickers_data');
if (isset($result['special']) && (float)$result['special']) {
$special = true;
} else {
$special = false;
}
$sticker_types = ['new', 'bestseller', 'popular', 'special', 'sold', 'ends'];
foreach ($sticker_types as $sticker_type) {
if ($this->isStickerAutoSet($oct_stickers, $sticker_type, $result, $special)) {
$oct_stickers_data['stickers']["stickers_{$sticker_type}"] = $this->getStickerData($oct_stickers, $sticker_type);
}
}
if (isset($result['oct_stickers']) && !empty($result['oct_stickers'])) {
$this->load->model('tool/image');
$languageId = (int)$this->config->get('config_language_id');
foreach ($result['oct_stickers'] as $oct_sticker) {
$oct_t_sticker = explode('_', $oct_sticker);
$currentSticker = $oct_stickers[$oct_t_sticker[0]][$oct_t_sticker[1]] ?? null;
if (is_null($currentSticker) || empty($currentSticker['status'])) {
continue;
}
$title = $currentSticker['title'][$languageId] ?? '';
if (empty($title)) {
continue;
}
$description = $currentSticker['description'][$languageId] ?? false;
$description = $description ? nl2br($description) : false;
$image = $currentSticker['image'] ?? false;
$sort = (int)$currentSticker['sort'];
if ($image && is_file(DIR_IMAGE . $image)) {
$image = $this->model_tool_image->resize($image, 32, 32);
}
$oct_stickers_data['stickers']['stickers_'.$oct_t_sticker[1]] = [
'title' => $title,
'description' => $description,
'image' => $image,
'sort' => $sort,
];
}
}
$i_sort_order = [];
if (isset($oct_stickers_data['stickers']) && !empty($oct_stickers_data['stickers'])) {
foreach ($oct_stickers_data['stickers'] as $key => $value) {
$i_sort_order[$key] = $value['sort'];
}
array_multisort($i_sort_order, SORT_ASC, $oct_stickers_data['stickers']);
foreach ($oct_stickers_data['stickers'] as $st => $oct_stiker) {
if (!empty($oct_stiker['image'])) {
$oct_stikers['stickers'][$st] = array(
'title' => $oct_stiker['title'],
'description' => $oct_stiker['description'],
'image' => $oct_stiker['image'],
'sort' => $oct_stiker['sort']
);
} else {
$oct_stikers['stickers'][$st] = $oct_stiker['title'];
}
}
}
}
return $oct_stikers;
}
private function isStickerAutoSet($oct_stickers, $sticker_type, $result, $special) {
if (!(isset($oct_stickers['stickers'][$sticker_type]['status']) && $oct_stickers['stickers'][$sticker_type]['status'])) {
return false;
}
if (!(isset($oct_stickers['stickers'][$sticker_type]['auto']) && $oct_stickers['stickers'][$sticker_type]['auto'] == 'on')) {
return false;
}
switch ($sticker_type) {
case 'new':
return strtotime($result['date_added']) >= strtotime("-".(int)$oct_stickers['stickers'][$sticker_type]['count']." day", time());
case 'bestseller':
return $this->model_catalog_product->getOCTBestSellerProducts($result['product_id']) >= (int)$oct_stickers['stickers'][$sticker_type]['count'];
case 'popular':
return $result['viewed'] > (int)$oct_stickers['stickers'][$sticker_type]['count'];
case 'special':
return $special;
case 'sold':
return (int)$result['quantity'] == (int)$oct_stickers['stickers'][$sticker_type]['count'];
case 'ends':
return ((int)$result['quantity'] <= (int)$oct_stickers['stickers'][$sticker_type]['count']) && ((int)$result['quantity'] > 0);
default:
return false;
}
}
private function getStickerData($oct_stickers, $sticker_type) {
return [
'title' => $this->getStickerTitle($oct_stickers, $sticker_type),
'sort' => $oct_stickers['stickers'][$sticker_type]['sort']
];
}
private function getStickerTitle($oct_stickers, $sticker_type) {
if ($sticker_type == 'special' && !isset($oct_stickers['stickers']['special']['view_title'])) {
return false;
}
if (isset($oct_stickers['stickers'][$sticker_type]['title'][(int)$this->config->get('config_language_id')]) && !empty($oct_stickers['stickers'][$sticker_type]['title'][(int)$this->config->get('config_language_id')])) {
return $oct_stickers['stickers'][$sticker_type]['title'][(int)$this->config->get('config_language_id')];
} else {
return $this->language->get("entry_sticker_{$sticker_type}");
}
}
}