forked from iSenseLabs/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenable-disable-products-oc302
185 lines (135 loc) · 6.33 KB
/
enable-disable-products-oc302
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
<modification>
<name>Enable/Disable Bundle of Products in OpenCart</name>
<version>1.0</version>
<link>http://isenselabs.com</link>
<author>iSenseLabs</author>
<code>isenselabs_enable_disable_bundle_products</code>
<file path="admin/controller/catalog/product.php">
<operation error="skip">
<search><![CDATA[$data['delete'] = $this->url->link('catalog/product/delete', 'user_token=' . $this->session->data['user_token'] . $url, true);]]></search>
<add position="after"><![CDATA[
$data['enable'] = $this->url->link('catalog/product/enable', 'user_token=' . $this->session->data['user_token'] . $url, true);
$data['disable'] = $this->url->link('catalog/product/disable', 'user_token=' . $this->session->data['user_token'] . $url, true);
]]></add>
</operation>
<operation>
<search><![CDATA[protected function getList() {]]></search>
<add position="before"><![CDATA[
public function enable() {
$this->load->language('catalog/product');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('catalog/product');
if (isset($this->request->post['selected']) && $this->validateDelete()) {
foreach ($this->request->post['selected'] as $product_id) {
$product_info = $this->model_catalog_product->getProduct($product_id);
if ($product_info && !$product_info['status']) {
$this->model_catalog_product->enableProduct($product_id);
}
}
$this->session->data['success'] = $this->language->get('text_success');
$url = '';
if (isset($this->request->get['filter_name'])) {
$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_model'])) {
$url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_price'])) {
$url .= '&filter_price=' . $this->request->get['filter_price'];
}
if (isset($this->request->get['filter_quantity'])) {
$url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
}
if (isset($this->request->get['filter_status'])) {
$url .= '&filter_status=' . $this->request->get['filter_status'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->response->redirect($this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . $url, true));
}
$this->getForm();
}
public function disable() {
$this->load->language('catalog/product');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('catalog/product');
if (isset($this->request->post['selected']) && $this->validateDelete()) {
foreach ($this->request->post['selected'] as $product_id) {
$product_info = $this->model_catalog_product->getProduct($product_id);
if ($product_info && $product_info['status']) {
$this->model_catalog_product->disableProduct($product_id);
}
}
$this->session->data['success'] = $this->language->get('text_success');
$url = '';
if (isset($this->request->get['filter_name'])) {
$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_model'])) {
$url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_price'])) {
$url .= '&filter_price=' . $this->request->get['filter_price'];
}
if (isset($this->request->get['filter_quantity'])) {
$url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
}
if (isset($this->request->get['filter_status'])) {
$url .= '&filter_status=' . $this->request->get['filter_status'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->response->redirect($this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token'] . $url, true));
}
$this->getForm();
}
]]></add>
</operation>
</file>
<file path="admin/model/catalog/product.php">
<operation>
<search><![CDATA[public function addProduct($data) {]]></search>
<add position="before"><![CDATA[
public function enableProduct($product_id) {
$product_info = $this->getProduct($product_id);
if ($product_id) {
$this->db->query("UPDATE " . DB_PREFIX . "product SET status = '1' WHERE product_id = '" . (int)$product_id . "'");
}
$this->cache->delete('product');
}
public function disableProduct($product_id) {
$product_info = $this->getProduct($product_id);
if ($product_id) {
$this->db->query("UPDATE " . DB_PREFIX . "product SET status = '0' WHERE product_id = '" . (int)$product_id . "'");
}
$this->cache->delete('product');
}
]]></add>
</operation>
</file>
<file path="admin/view/template/catalog/product_list.twig">
<operation>
<search><![CDATA[<h1>{{ heading_title }}</h1>]]></search>
<add position="before"><![CDATA[
<div class="pull-right" style="margin-right:15px;">
<a onclick="$('form').attr('action', '{{ enable }}'); $('form').submit();" class="btn btn-success">{{ button_enable }}</a>
<a onclick="$('form').attr('action', '{{ disable }}'); $('form').submit();" class="btn btn-warning">{{ button_disable }}</a>
</div>
]]></add>
</operation>
</file>
</modification>