| Line 125... |
Line 125... |
| 125 |
* @return void
|
125 |
* @return void
|
| 126 |
*/
|
126 |
*/
|
| 127 |
public function add() {
|
127 |
public function add() {
|
| 128 |
$priceSaved = $brandSaved = false;
|
128 |
$priceSaved = $brandSaved = false;
|
| 129 |
$errors = array();
|
129 |
$errors = array();
|
| - |
|
130 |
$this->log('request '.print_r($this->request->data,1),'preferences');
|
| 130 |
if ($this->request->is('post')) {
|
131 |
if ($this->request->is('post')) {
|
| 131 |
// print_r($this->request->data);die;
|
132 |
// print_r($this->request->data);die;
|
| 132 |
if(!empty($this->request->data['pricerange'])){
|
133 |
if(!empty($this->request->data['pricerange'])){
|
| 133 |
//First delete exisitng price preferences
|
134 |
//First delete exisitng price preferences
|
| 134 |
$this->loadModel('PricePreference');
|
135 |
$this->loadModel('PricePreference');
|
| Line 153... |
Line 154... |
| 153 |
// $conditions = array('user_id'=>$this->request->data['user_id'],'category_id'=>$this->request->data['category_id'],'Brand.status'=>'show');
|
154 |
// $conditions = array('user_id'=>$this->request->data['user_id'],'category_id'=>$this->request->data['category_id'],'Brand.status'=>'show');
|
| 154 |
// $this->BrandPreference->deleteAll($conditions,false);
|
155 |
// $this->BrandPreference->deleteAll($conditions,false);
|
| 155 |
$sql = "DELETE FROM brand_preferences WHERE user_id = ".$this->request->data['user_id']." AND category_id = ".$this->request->data['category_id']." AND status = 'show'";
|
156 |
$sql = "DELETE FROM brand_preferences WHERE user_id = ".$this->request->data['user_id']." AND category_id = ".$this->request->data['category_id']." AND status = 'show'";
|
| 156 |
$this->BrandPreference->query($sql);
|
157 |
$this->BrandPreference->query($sql);
|
| 157 |
$data = array();
|
158 |
$data = array();
|
| - |
|
159 |
if(!empty($this->request->data['brand'])){
|
| 158 |
foreach ($this->request->data['brand'] as $key => $brand) {
|
160 |
foreach ($this->request->data['brand'] as $key => $brand) {
|
| 159 |
$temp = array('user_id' => $this->request->data['user_id'], 'category_id' => $this->request->data['category_id'], 'brand' => $brand, 'status' => 'show');
|
161 |
$temp = array('user_id' => $this->request->data['user_id'], 'category_id' => $this->request->data['category_id'], 'brand' => $brand, 'status' => 'show');
|
| 160 |
$data[] = $temp;
|
162 |
$data[] = $temp;
|
| - |
|
163 |
}
|
| - |
|
164 |
$this->BrandPreference->create();
|
| - |
|
165 |
if($this->BrandPreference->saveAll($data)){
|
| - |
|
166 |
$brandSaved = true;
|
| - |
|
167 |
}else{
|
| - |
|
168 |
$errors[] = $this->BrandPreference->validationErrors;
|
| - |
|
169 |
}
|
| 161 |
}
|
170 |
}
|
| 162 |
$this->BrandPreference->create();
|
- |
|
| 163 |
if($this->BrandPreference->saveAll($data)){
|
- |
|
| 164 |
$brandSaved = true;
|
- |
|
| 165 |
}else{
|
- |
|
| 166 |
$errors[] = $this->BrandPreference->validationErrors;
|
- |
|
| 167 |
}
|
- |
|
| 168 |
// }
|
171 |
// }
|
| 169 |
$this->response->type('json');
|
172 |
$this->response->type('json');
|
| 170 |
$this->layout = 'ajax';
|
173 |
$this->layout = 'ajax';
|
| 171 |
if($brandSaved || $priceSaved) {
|
174 |
if($brandSaved || $priceSaved) {
|
| 172 |
$result = array('success'=>true,'message'=>'Preferences Saved');
|
175 |
$result = array('success'=>true,'message'=>'Preferences Saved');
|
| 173 |
}else{
|
176 |
}else{
|
| 174 |
$result = array('success'=>false,'message'=>$errors);
|
177 |
$result = array('success'=>false,'message'=>$errors);
|
| 175 |
}
|
178 |
}
|
| 176 |
$url = $this->apihost.'resetCache/'.$this->request->data['user_id'];
|
179 |
$url = $this->apihost.'resetCache/'.$this->request->data['user_id'];
|
| 177 |
$this->make_request($url,null);
|
180 |
$response = $this->make_request($url,null);
|
| - |
|
181 |
$this->log('response '.print_r($response,1),'preferences');
|
| 178 |
$this->set(array(
|
182 |
$this->set(array(
|
| 179 |
'result' => $result,
|
183 |
'result' => $result,
|
| 180 |
'callback' => $callback,
|
184 |
'callback' => $callback,
|
| 181 |
'_serialize' => array('result')
|
185 |
'_serialize' => array('result')
|
| 182 |
));
|
186 |
));
|