| 19874 |
naman |
1 |
<?php
|
|
|
2 |
App::uses('AppController', 'Controller');
|
|
|
3 |
/**
|
|
|
4 |
* Exceptionalnlcs Controller
|
|
|
5 |
*
|
|
|
6 |
* @property Exceptionalnlc $Exceptionalnlc
|
|
|
7 |
* @property PaginatorComponent $Paginator
|
|
|
8 |
*/
|
|
|
9 |
class ItemcashbacksController extends AppController {
|
|
|
10 |
|
|
|
11 |
/**
|
|
|
12 |
* Components
|
|
|
13 |
*
|
|
|
14 |
* @var array
|
|
|
15 |
*/
|
|
|
16 |
public $components = array('Paginator');
|
|
|
17 |
|
|
|
18 |
public function beforeFilter() {
|
|
|
19 |
parent::beforeFilter();
|
|
|
20 |
// Configure::load('live');
|
|
|
21 |
$this->apihost = Configure::read('pythonapihost');
|
|
|
22 |
}
|
|
|
23 |
/**
|
|
|
24 |
* admin_index method
|
|
|
25 |
*
|
|
|
26 |
* @return void
|
|
|
27 |
*/
|
|
|
28 |
public function admin_index() {
|
| 20453 |
amit.gupta |
29 |
if($this->request->method()=='POST' && $this->request->data('clear-cache')!=null){
|
| 20444 |
amit.gupta |
30 |
$clearCacheApiUrl = $this->apihost."/resetCache/?type=itemCashBack";
|
|
|
31 |
$response = $this->make_request($clearCacheApiUrl,null);
|
| 20454 |
amit.gupta |
32 |
$this->set('clear', $response["1"]=='Cache cleared.'?'Cache Cleared Successfully':'Could not clear cache');
|
| 20444 |
amit.gupta |
33 |
}
|
| 19874 |
naman |
34 |
$type = $this->request->query('type');
|
|
|
35 |
$search = $this->request->query('search');
|
|
|
36 |
$page = $this->request->query('page');
|
|
|
37 |
if(!isset($page)){
|
|
|
38 |
$page = 1;
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
$limit = Configure::read('admindashboardlimit');
|
|
|
42 |
$offset = ($page - 1)*$limit;
|
|
|
43 |
if(isset($type) && !empty($type) && isset($search) && !empty($search))
|
|
|
44 |
{
|
|
|
45 |
$url = $this->apihost."Catalog/searchProducts/?class=ItemCashBack&".$type."=".$search;
|
|
|
46 |
}
|
|
|
47 |
else
|
|
|
48 |
{
|
|
|
49 |
$url = $this->apihost."getItemCashback?offset=".$offset."&limit=".$limit;
|
|
|
50 |
}
|
| 20449 |
amit.gupta |
51 |
//echo $url;
|
| 19874 |
naman |
52 |
// $url = $this->apihost."getItemCashback/?limit=$limit&offset=$offset";
|
|
|
53 |
$response = $this->make_request($url,null);
|
|
|
54 |
$this->set('cashbacks', $response);
|
|
|
55 |
$this->set('page',$page);
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
* admin_view method
|
|
|
60 |
*
|
|
|
61 |
* @throws NotFoundException
|
|
|
62 |
* @param string $id
|
|
|
63 |
* @return void
|
|
|
64 |
*/
|
|
|
65 |
public function admin_search() {
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
/**
|
|
|
69 |
* admin_add method
|
|
|
70 |
*
|
|
|
71 |
* @return void
|
|
|
72 |
*/
|
|
|
73 |
public function admin_add() {
|
|
|
74 |
if ($this->request->is('post')) {
|
|
|
75 |
$data = $this->request->data['Itemcashbacks'];
|
|
|
76 |
$senddata = array();
|
|
|
77 |
$senddata['sku'] = $data['skuId'];
|
|
|
78 |
$senddata['cash_back'] = $data['cash_back'];
|
|
|
79 |
$senddata['cash_back_status'] = $data['cash_back_status'];
|
|
|
80 |
$senddata['cash_back_type'] = $data['cash_back_type'];
|
|
|
81 |
if($data['cash_back_type'] == 2)
|
|
|
82 |
{
|
|
|
83 |
$senddata['cash_back_description'] = "Amount";
|
|
|
84 |
}
|
|
|
85 |
else{
|
|
|
86 |
$senddata['cash_back_description'] = "Percentage";
|
|
|
87 |
}
|
|
|
88 |
// debug($senddata);
|
|
|
89 |
$url = $this->apihost."getItemCashback";
|
|
|
90 |
$response = $this->make_request($url,json_encode($senddata,JSON_NUMERIC_CHECK));
|
|
|
91 |
if ($response['result'] == "success") {
|
|
|
92 |
$this->Session->setFlash("Data has been added successfully..");
|
|
|
93 |
return $this->redirect(array('action' => 'index'));
|
|
|
94 |
} else {
|
|
|
95 |
$this->Session->setFlash("Data has not been added");
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
}
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
/**
|
|
|
102 |
* admin_edit method
|
|
|
103 |
*
|
|
|
104 |
* @throws NotFoundException
|
|
|
105 |
* @param string $id
|
|
|
106 |
* @return void
|
|
|
107 |
*/
|
|
|
108 |
public function admin_edit($id = null) {
|
|
|
109 |
|
|
|
110 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
111 |
$data = $this->request->data['Itemcashbacks'];
|
|
|
112 |
|
|
|
113 |
$data = $this->request->data['Itemcashbacks'];
|
|
|
114 |
$senddata = array();
|
|
|
115 |
$senddata['class'] = 'ItemCashBack';
|
|
|
116 |
$senddata['oid'] = $data['_id'];
|
|
|
117 |
$senddata['sku'] = $data['skuId'];
|
|
|
118 |
$senddata['cash_back'] = $data['cash_back'];
|
|
|
119 |
$senddata['cash_back_status'] = $data['cash_back_status'];
|
|
|
120 |
$senddata['cash_back_type'] = $data['cash_back_type'];
|
|
|
121 |
if($data['cash_back_type'] == 2)
|
|
|
122 |
{
|
|
|
123 |
$senddata['cash_back_description'] = "Amount";
|
|
|
124 |
}
|
|
|
125 |
else{
|
|
|
126 |
$senddata['cash_back_description'] = "Percentage";
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
// $url = "http://localhost:8057/getItemCashback?status=update";
|
|
|
130 |
$url = $this->apihost."Catalog/updateCollection";
|
|
|
131 |
$response = $this->make_request($url,json_encode($senddata,JSON_NUMERIC_CHECK));
|
|
|
132 |
|
|
|
133 |
if (key($response)) {
|
|
|
134 |
$this->Session->setFlash(current($response));
|
|
|
135 |
return $this->redirect(array('action' => 'index'));
|
|
|
136 |
} else {
|
|
|
137 |
$this->Session->setFlash(current($response));
|
|
|
138 |
}
|
|
|
139 |
}
|
|
|
140 |
else
|
|
|
141 |
{
|
|
|
142 |
$url = $this->apihost."getItemCashback?id=".$id;
|
|
|
143 |
$response = $this->make_request($url,null);
|
| 20450 |
amit.gupta |
144 |
$cashbacks = $response;
|
| 20455 |
amit.gupta |
145 |
$this->set(compact('cashbacks'));
|
| 19874 |
naman |
146 |
}
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
/**
|
|
|
150 |
* admin_delete method
|
|
|
151 |
*
|
|
|
152 |
* @throws NotFoundException
|
|
|
153 |
* @param string $id
|
|
|
154 |
* @return void
|
|
|
155 |
*/
|
|
|
156 |
|
|
|
157 |
public function admin_delete($id = null) {
|
|
|
158 |
|
|
|
159 |
// $url = $this->apihost."deleteItemCashback/".$id;
|
|
|
160 |
$senddata['class'] = "ItemCashBack";
|
|
|
161 |
$senddata['oid'] = $id;
|
|
|
162 |
$url = $this->apihost."Catalog/deleteDocument";
|
|
|
163 |
// $url = "http://localhost:8057/getItemCashback?itemid=".$id."&type=delete";
|
|
|
164 |
$response = $this->make_request($url,json_encode($senddata,JSON_NUMERIC_CHECK));
|
|
|
165 |
if (key($response)) {
|
|
|
166 |
$this->Session->setFlash(current($response));
|
|
|
167 |
return $this->redirect(array('action' => 'index'));
|
|
|
168 |
} else {
|
|
|
169 |
$this->Session->setFlash(current($response));
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
}
|