Subversion Repositories SmartDukaan

Rev

Rev 20452 | Rev 20454 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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