-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinstall.xml
137 lines (127 loc) · 6.33 KB
/
install.xml
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
<?xml version="1.0" encoding="utf-8"?>
<modification>
<code>1</code>
<name>Opencart Easy Featured Mofification</name>
<version>0.1</version>
<author>EMRE ACAR</author>
<link>http://www.emreacar.com.tr</link>
<file path="admin/controller/catalog/product.php">
<operation>
<search><![CDATA[
$this->response->setOutput($this->load->view('catalog/product_list', $data));
]]></search>
<add position="before"><![CDATA[
$this->load->model('setting/module');
$data['featuredProducts'] = array("ids" => array(), "p2m" => array());
$data['featuredModules'] = $this->model_setting_module->getModulesByCode('featured');
foreach((array) $data['featuredModules'] as $key => $value) {
$module_id = $value['module_id'];
$module_setting = json_decode($value['setting'], TRUE);
$data['featuredProducts']['ids'] = array_merge($data['featuredProducts']['ids'],$module_setting['product']);
foreach((array) $module_setting['product'] as $p) {$data['featuredProducts']['p2m'][$p] = $module_id;}
}
]]></add>
</operation>
<operation>
<search><![CDATA[
protected function getList() {
]]></search>
<add position="before"><![CDATA[
public function removeFeatured() {
$return = array();
$data = explode('-',$this->request->get['featured_data']);
$product_id = $data[0];
$module_id = $data[1];
if($product_id > 0 && $module_id > 0) {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "module` WHERE `module_id` = '" . (int)$module_id . "'");
if ($query->row) {
$module = json_decode($query->row['setting'], true);
$remove_product = array_diff($module['product'], array($product_id));
$module['product'] = $remove_product;
$this->db->query("UPDATE `" . DB_PREFIX . "module` SET `setting` = '" . $this->db->escape(json_encode($module)) . "' WHERE `module_id` = '" . (int)$module_id . "'");
$return['status'] = 'ok';
} else {
$return['status'] = 'no'; $return['message'] = 'Database Query Failed.';
}
}else{ $return['status'] = 'no'; $return['message'] = 'Product or Module could not set. Please refresh your page and try again.'; }
echo json_encode($return, JSON_UNESCAPED_UNICODE);
}
public function setFeatured() {
$return = array();
$data = explode('-',$this->request->get['featured_data']);
$product_id = $data[0];
$module_id = $data[1];
if($product_id > 0 && $module_id > 0) {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "module` WHERE `module_id` = '" . (int)$module_id . "'");
if ($query->row) {
$module = json_decode($query->row['setting'], true);
$module['product'][] = $product_id;
$this->db->query("UPDATE `" . DB_PREFIX . "module` SET `setting` = '" . $this->db->escape(json_encode($module)) . "' WHERE `module_id` = '" . (int)$module_id . "'");
$return['status'] = 'ok';
} else {
$return['status'] = 'no'; $return['message'] = 'Database Query Failed.';
}
}else{ $return['status'] = 'no'; $return['message'] = 'Product or Module could not set. Please refresh your page and try again.'; }
echo json_encode($return, JSON_UNESCAPED_UNICODE);
}
]]></add>
</operation>
</file>
<file path="admin/view/template/catalog/product_list.twig">
<operation>
<search><![CDATA[
<td class="text-center">{{ column_image }}</td>
]]></search>
<add position="after"><![CDATA[
<td class="text-center"><i class="fa fa-star"></i></td>
]]></add>
</operation>
<operation>
<search><![CDATA[
<td class="text-left">{{ product.name }}</td>
]]></search>
<add position="before"><![CDATA[
<td class="text-center">
{% if product.product_id in featuredProducts.ids %}
<a class="btn btn-warning removeFeatured" data-id="{{product.product_id}}-{{featuredProducts.p2m[product.product_id]}}"><i class="fa fa-star"></i></a>
{% else %}
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-star"></i></button>
<ul class="dropdown-menu">
{% for fm in featuredModules %}
<li><a data-id="{{product.product_id}}-{{fm.module_id}}" class="setFeatured">{{fm.name}}</a></li>
{% endfor %}
</ul>
</div>
{% endif %}
</td>
]]></add>
</operation>
<operation>
<search><![CDATA[
$('#button-filter').on('click', function() {
]]></search>
<add position="before"><![CDATA[
$('.removeFeatured').on('click', function() {
var checkConfirm = confirm('Are you sure remove this product from featured list ?');
var data = $(this).data('id');
if(checkConfirm) {
$.ajax({
url: 'index.php?route=catalog/product/removeFeatured&user_token={{ user_token }}&featured_data=' + data,
dataType: 'json',
success: function(json) { if(json.status == 'ok') {window.location.reload();}else{alert(json.message);} }
});
}
});
$('.setFeatured').on('click', function() {
var data = $(this).data('id');
$.ajax({
url: 'index.php?route=catalog/product/setFeatured&user_token={{ user_token }}&featured_data=' + data,
dataType: 'json',
success: function(json) { if(json.status == 'ok') {window.location.reload();}else{alert(json.message);} }
});
});
]]></add>
</operation>
</file>
</modification>