helper.php
5.49 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
<?php
/**
* @copyright OCTemplates
* @support https://octemplates.net/
* @license LICENSE.txt
*/
class ControllerOCTemplatesEventsHelper extends Controller {
public function compareRemove() {
if (isset($this->request->server['HTTP_X_REQUESTED_WITH']) && !empty($this->request->server['HTTP_X_REQUESTED_WITH']) && strtolower($this->request->server['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$this->load->language('octemplates/oct_deals');
$json = array();
if (!isset($this->session->data['compare']) || !isset($this->request->post['product_id'])) {
$json['error'] = $this->language->get('text_empty');
} else {
$product_id = (int)$this->request->post['product_id'];
$this->load->model('catalog/product');
$product_info = $this->model_catalog_product->getProduct($product_id);
if ($product_info) {
if (in_array($product_id, $this->session->data['compare'])) {
$key = array_search($product_id, $this->session->data['compare']);
unset($this->session->data['compare'][$key]);
$json['success'] = sprintf($this->language->get('compare_remove_success'), $this->url->link('product/product', 'product_id=' . (int)$this->request->post['product_id']), $product_info['name'], $this->url->link('product/compare'));
$json['total_compare'] = (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0);
}
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
} else {
$this->response->redirect($this->url->link('error/not_found', '', true));
}
}
public function wishlistRemove() {
if (isset($this->request->server['HTTP_X_REQUESTED_WITH']) && !empty($this->request->server['HTTP_X_REQUESTED_WITH']) && strtolower($this->request->server['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$this->load->language('octemplates/oct_deals');
$json = array();
if (isset($this->request->post['product_id'])) {
$product_id = (int)$this->request->post['product_id'];
} else {
$product_id = 0;
}
$this->load->model('catalog/product');
$product_info = $this->model_catalog_product->getProduct($product_id);
if ($product_info) {
if ($this->customer->isLogged()) {
// Edit customers wishlist
$this->load->model('account/wishlist');
$this->model_account_wishlist->deleteWishlist($this->request->post['product_id']);
$json['success'] = sprintf($this->language->get('wishlist_remove_success'), $this->url->link('product/product', 'product_id=' . (int)$this->request->post['product_id']), $product_info['name'], $this->url->link('account/wishlist'));
$json['total_wishlist'] = $this->model_account_wishlist->getTotalWishlist();
} else {
if (isset($this->session->data['wishlist']) && (($key = array_search($this->request->post['product_id'], $this->session->data['wishlist'])) !== false)) {
unset($this->session->data['wishlist'][$key]);
}
$json['success'] = sprintf($this->language->get('wishlist_remove_success'), $this->url->link('product/product', 'product_id=' . (int)$this->request->post['product_id']), $product_info['name'], $this->url->link('account/wishlist'));
$json['total_wishlist'] = (isset($this->session->data['wishlist']) ? count($this->session->data['wishlist']) : 0);
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
} else {
$this->response->redirect($this->url->link('error/not_found', '', true));
}
}
public function allCartProducts() {
$this->load->model('octemplates/helper');
$product_ids = $this->model_octemplates_helper->getOctCartProducts();
if (!empty($product_ids)) {
return implode(',', $product_ids);
}
return '';
}
public function octReviewReputation() {
$json = array();
$this->load->language('octemplates/oct_deals');
if (isset($this->request->get['review_id'])) {
$this->load->model('octemplates/helper');
$check_ip = $this->model_octemplates_helper->checkOctUserIp($this->request->server['REMOTE_ADDR'], $this->request->get['review_id']);
if ($check_ip) {
$json['error'] = $this->language->get('error_ip_exist');
}
if (!isset($json['error'])) {
$filter_data = array(
'review_id' => (int)$this->request->get['review_id'],
'ip' => $this->request->server['REMOTE_ADDR']
);
$this->model_octemplates_helper->addOctProductReputation($filter_data);
$json['success'] = $this->language->get('text_ip_vote_success');
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}