| 13637 |
anikendra |
1 |
<?php
|
|
|
2 |
App::uses('AppController', 'Controller');
|
|
|
3 |
/**
|
|
|
4 |
* Preferences Controller
|
|
|
5 |
*
|
|
|
6 |
* @property Preference $Preference
|
|
|
7 |
* @property PaginatorComponent $Paginator
|
|
|
8 |
*/
|
|
|
9 |
class CashbacksController extends AppController {
|
|
|
10 |
|
|
|
11 |
/**
|
|
|
12 |
* Components
|
|
|
13 |
*
|
|
|
14 |
* @var array
|
|
|
15 |
*/
|
|
|
16 |
public $components = array('Paginator');
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* index method
|
|
|
20 |
*
|
|
|
21 |
* @return void
|
|
|
22 |
*/
|
|
|
23 |
public function index($store_id = null,$product_code = null) {
|
|
|
24 |
$this->layout = 'ajax';
|
|
|
25 |
$this->response->type('json');
|
|
|
26 |
$this->loadModel('Api');
|
|
|
27 |
if(!$store_id || !$product_code){
|
|
|
28 |
$result = array('success'=>false,'message'=>'Either Source or Product Code is missing','cashback_type'=>'value','cashback'=>0);
|
|
|
29 |
}else{
|
|
|
30 |
//First check if sku wise cashback is configured
|
|
|
31 |
$this->loadModel('ProductCashback');
|
|
|
32 |
$options = array('conditions'=>array('product_id'=>$product_code,'store_id'=>$store_id),'recursive'=>-1);
|
|
|
33 |
$productcashback = $this->ProductCashback->find('first',$options);
|
|
|
34 |
if(!empty($productcashback)){
|
|
|
35 |
if(!empty($productcashback['ProductCashback']['cashback_percantage'])){
|
|
|
36 |
$cashback_type = 'percentage';
|
|
|
37 |
$value = $productcashback['ProductCashback']['cashback_percantage'];
|
|
|
38 |
}else{
|
|
|
39 |
$cashback_type = 'value';
|
|
|
40 |
$value = $productcashback['ProductCashback']['cashback_amount'];
|
|
|
41 |
}
|
|
|
42 |
$result = array('success'=>true,'message'=>'Sku level cashback configured','cashback_type'=>$cashback_type,'cashback'=>$value);
|
|
|
43 |
}else{
|
|
|
44 |
//Check if category wise cashback is configured
|
|
|
45 |
$this->loadModel('StoreProduct');
|
|
|
46 |
$options = array('conditions'=>array('store_id'=>$store_id,'StoreProduct.url LIKE'=>"%$product_code%"),'fields'=>array('category_id'),'recursive'=>-1);
|
|
|
47 |
$storeproduct = $this->StoreProduct->find('first',$options);
|
|
|
48 |
if(empty($storeproduct)){
|
|
|
49 |
//Category couldn't be determined, so no cashback can be offered
|
|
|
50 |
$result = array('success'=>false,'message'=>'Unable to determine category','cashback_type'=>'value','cashback'=>0);
|
|
|
51 |
}else{
|
|
|
52 |
$category_id = $storeproduct['StoreProduct']['category_id'];
|
|
|
53 |
//Fetch category discount
|
|
|
54 |
$this->loadModel('StoreCashback');
|
|
|
55 |
$options = array('conditions'=>array('store_id'=>$store_id,'category_id'=>$category_id),'recursive'=>-1);
|
|
|
56 |
$storecashback = $this->StoreCashback->find('first',$options);
|
|
|
57 |
if(!empty($storecashback)){
|
|
|
58 |
$result = array('success'=>true,'message'=>'Store level cashback configured','cashback_type'=>'percentage','cashback'=>$storecashback['StoreCashback']['cashback_percantage']);
|
|
|
59 |
}else{
|
|
|
60 |
$result = array('success'=>false,'message'=>'Cashback has not been configured for this store & category combination','cashback_type'=>'value','cashback'=>0);
|
|
|
61 |
}
|
|
|
62 |
}
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
$this->set(array(
|
|
|
66 |
'result' => $result,
|
|
|
67 |
'_serialize' => array('result')
|
|
|
68 |
));
|
|
|
69 |
$this->render('/Elements/json');
|
|
|
70 |
}
|
|
|
71 |
}
|