Rev 20018 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?phpApp::uses('AppController', 'Controller');/*** Categories Controller** @property Category $Category* @property PaginatorComponent $Paginator*/class CategoriesController extends AppController {/*** Components** @var array*/public $components = array('Paginator');public $apihost;public $limit;public function beforeFilter() {parent::beforeFilter();$this->Auth->allow('deals');$this->apihost = Configure::read('pythonapihost');$this->limit = Configure::read('dealsperpage');$this->mobileapi = Configure::read('saholicapihost');setcookie("fresh", '1', null, '/');}/*** index method** @return void*/public function index() {// $this->Category->recursive = 0;// $this->set('categories', $this->Paginator->paginate());$userId = $this->request->query('user_id');$this->loadModel('UserCategory');$options = array('conditions' => array('user_id'=>$userId),'order'=>array('rank','asc'),'recursive'=>-1);$userCategories = $this->UserCategory->find('all',$options);$this->response->type('json');$this->layout = 'ajax';$conditions = array(array('Category.parent_id !='=>0));if(!empty($userCategories)){foreach ($userCategories as $key => $value) {$categoryIds[] = $value['UserCategory']['category_id'];}array_push($conditions,array('Category.id'=>$categoryIds));}$this->Category->recursive = -1;$categories = $this->Paginator->paginate(null,$conditions);$callback = $this->request->query('callback');$result = array('categories' => $categories);$this->set(array('result' => $result,'callback' => $callback,'_serialize' => array('result')));$this->render('/Elements/jsonp');}public function deals(){$userId = $this->request->query('user_id');$error = $this->request->query('error');if(isset($userId) && !empty($userId)){$this->loadModel('User');$dbuser = $this->User->findById($userId);$this->Auth->login($dbuser['User']);}$likedDeals = $disLikedDeals = array();// $this->loadModel('Api');// $apideals = $this->Api->getCategoryDeals($this->Auth->User('id'),1);// $categorydeals = $apideals['products'];$page = $this->request->query('page');if(!isset($page)){$page = 1;}$offset = ($page - 1) * $this->limit;$url = $this->apihost.'deals/'.$this->Auth->User('id').'?categoryId=0&limit='.$this->limit.'&offset='.$offset;//debug($url);$deals = $this->make_request($url,null);$myactions = $this->Api->getMyActions($this->Auth->User('id'));if(!empty($myactions)) {foreach ($myactions['actions'] as $key => $value) {if($value['UserAction']['action'] == 'like'){$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];}else{$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];}}}$errorstr = '';if(isset($error)){$errorstr = 'Oops!! Some Error Occured. <br> Please try after Some Time';}$rows = sizeof($categorydeals);if($rows>=1){$this->set('deals',$categorydeals);$this->set('likedDeals',$likedDeals);$this->set('disLikedDeals',$disLikedDeals);$this->set('errorstr',$errorstr);$this->render('categorydeals');}else{foreach ($categorydeals as $key => $dealarr) {foreach ($dealarr as $key => $deal) {$deals[] = $deal[0];}}$this->set(compact('deals','likedDeals','disLikedDeals','errorstr'));}}/*** view method** @throws NotFoundException* @param string $id* @return void*/public function view($id = null) {$arrSubCategory = Configure::read('arrSubCategory');$userId = $this->request->query('user_id');// $dealpin = $this->getpin();// $this->set(compact('dealpin'));if(isset($userId) && !empty($userId)) {$this->loadModel('User');$dbuser = $this->User->findById($userId);$this->Auth->login($dbuser['User']);}$version = $this->request->query('version');if(isset($version) && !isset($_COOKIE['version'])){setcookie('version', $version, time() + (86400 * 30), "/");}$color = array('0'=>'#458ccc','1'=>'#44cbbc','2'=>'#a77189', '3'=>'#f9b931' ,'4' =>'#44cbbc', '5' => '#f48f3f' , '6'=>'#a77189');//Sort - type, ordering$sort = $this->request->query('sort');$direction = $this->request->query('direction');//Filter - brand/subcategory$brands = $this->request->query('brands');$subcategories = $this->request->query('subcategories');$searchableSubCategories = array('20'=>'Screen Guard', '27'=>'Back Cover', '29'=>'Batteries', '33'=>'Flip Cover', '28'=>'Tempered Glass');$subcatlist = Configure::read('arrSubCategory');$whatfirst = $this->request->query('whatfirst');if($id == 6){if(isset($brands) && !empty($brands) && !isset($subcategories) && !isset($whatfirst)){$whatfirst = "brand";}else if(isset($subcategories) && !empty($subcategories) && !isset($brands) && !isset($whatfirst)){$whatfirst = "subCategory";}else if(isset($subcategories) && !empty($subcategories) && isset($brands) && !empty($brands) && !isset($whatfirst)){$whatfirst = "subCategory";}$cachekey = 'subcat-6';$getdet = Cache::read($cachekey,'subcatdetail');if(empty($getdet) || $getdet === false){$url = $this->apihost."getHeaderLinks/?category_id=6";$getdet = $this->make_request($url,null);Cache::write($cachekey , $getdet ,'subcatdetail');}$this->set(compact('getdet'));}$whatsecond = "";$whatsecondid = "";$whatfirstid = "";$secondloop = "";if(isset($whatfirst)){$brandprourl = "";if($whatfirst == "subCategory"){$secondloop = explode("^",$brands);$whatsecond = "brand";$whatsecondid = "brand_id";$whatfirstid = "subCategoryId";$brandprourl = $this->apihost."getBrandSubCategoryInfo/?category_id=6&type=subCategoryInfo&id_list=".$subcategories;}else if($whatfirst == "brand"){$secondloop = explode("^",$subcategories);$whatsecond = "subCategory";$whatsecondid = "subCategoryId";$whatfirstid = "brand_id";$brandprourl = $this->apihost."getBrandSubCategoryInfo/?category_id=6&type=brandInfo&id_list=".$brands;}$allbrandsubcat = $this->make_request($brandprourl, null);$this->set(compact('secondloop','whatfirstid','whatsecondid','subcatlist','whatfirst','whatsecond','allbrandsubcat'));}$page = $this->request->query('page');$searchfor = $this->request->query('searchFor');// echo "page=>",$page;$error = $this->request->query('error');if(!isset($page)){$page = 1;}//$filter = $this->request->query('filter');// $brands = $this->request->query('brands');if($id != 2) {if($id != 6){$url = $this->apihost.'deals/brands/?category_id='.$id;$brandres = $this->make_request($url,null);$brandlist = array();foreach ($brandres as $bkey => $bvalue){$brandlist[$bvalue['brand_id']] = $bvalue['brand'];}$this->set(compact('brandlist'));}//Fetch deals$likedDeals = $disLikedDeals = array();if(!empty($brands) && !empty($subcategories)){$filter = 'brand|subcategory';}else if(!empty($brands)){$filter = 'brand';}else if(!empty($subcategories)){$filter = 'subcategory';}$sortlabel = 'recommended';if ($sort=='bestSellerPoints'){$sortlabel = 'bestseller';}else if ($sort=='available_price' && $direction==-1){$sortlabel = 'pricehigh';}else if ($sort=='available_price' && $direction==1){$sortlabel = 'pricelow';}$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands,$subcategories);// $url = $url."&pin=".$dealpin;$response = $this->make_request($url,null);$deals = array();$response_count =1;if($response == ''){$response_count = 0;}// debug($response_count);if(!empty($response)){foreach ($response as $key => $value) {if(!empty($value)){$deals[] = $value;}}}#print_r($deals);$this->loadModel('Api');$myactions = $this->Api->getMyActions($this->Auth->User('id'));if(!empty($myactions)) {foreach ($myactions['actions'] as $key => $value) {if($value['UserAction']['action'] == 'like'){$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];}else{$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];}}}$this->loadModel('NotificationRule');$notification = $this->NotificationRule->getNotification($this->Auth->User('id'));$filterstr = '';if(isset($filter) && !empty($filter)){$filterstr = '&filter='.$filter.'&brands='.$brands.'&subcategories='.$subcategories;}$get_url = "'".$_SERVER['REQUEST_URI']."'";$urlArray = explode('=',$_SERVER['REQUEST_URI']);$last = $urlArray[sizeof($urlArray)-1];$errorstr = '';if(isset($error)){$errorstr = 'Oops!! Some Error Occured. <br> Please try after Some Time';}$filterstr = '&brands='.$brands.'&subcategories='.$subcategories;$nexturl = "/categories/getdeals/".$id."/?page=".($page+1)."&sort=".$sort."&direction=".$direction."".$filterstr;$offerresponse = $this->getuseroffer();$clearancesale = Configure::read('clearancesale');$this->set(compact('clearancesale','color','arrSubCategory','offerresponse','response_count','deals','id','likedDeals','disLikedDeals','page','sort','direction','notification','filter','brands','filterstr','subcategories','errorstr','nexturl','searchfor', 'searchableSubCategories', 'sortlabel'));}else{//Check for apk support of sharing$sharable = 0;if(isset($_COOKIE['shareApps']) && !empty($_COOKIE['shareApps'])) {$sharable = 1;}$url = $this->apihost."appOffers/1";$appOffers = $this->make_request($url,null);$this->set(compact('page','id','sharable','appOffers'));$this->render('viewapps');}}public function getapps($id=null){$this->layout = 'ajax';$page = $this->request->query('page');if(!isset($page)){$page = 1;}$this->loadModel('AppOffer');$this->AppOffer->recursive = -1;$options = array('conditions'=>array('offer_active'=>1,'show'=>1),'limit' => Configure::read('searchresultsperpage'),'page'=>$page);$this->Paginator->settings = $options;try{$appOffers = $this->Paginator->paginate('AppOffer');} catch (NotFoundException $e) {//get current page$page = $this->request->params['named']['page'];$appOffers = array();}debug($appOffers);if(!empty($appOffers)){$this->set(compact('page','id','appOffers'));$this->render('/Elements/appoffers');}else{$this->render('/Elements/nooffers');}}public function getdeals($id = null) {$this->log('getdeal id '.$id,'api');$likedDeals = $disLikedDeals = array();$this->layout = 'ajax';$page = $this->request->query('page');if(!isset($page)){$page = 1;}// $dealpin = $this->getpin();$sort = $this->request->query('sort');$direction = $this->request->query('direction');// $filter = $this->request->query('filter');// $brands = $this->request->query('brands');$brands = $this->request->query('brands');$subcategories = $this->request->query('subcategories');$likedDeals = $disLikedDeals = array();if(!empty($brands) && !empty($subcategories)){$filter = 'brand|subcategory';}else if(!empty($brands)){$filter = 'brand';}else if(!empty($subcategories)){$filter = 'subcategory';}$url = $this->getDealsApiUrl($page,$this->Auth->User('id'),$id,$sort,$direction,$filter,$brands,$subcategories);// $url = $url."&pin=".$dealpin;$response = $this->make_request($url,null);$deals = array();if(!empty($response)){foreach ($response as $key => $value) {if(!empty($value)){$deals[] = $value;}}}// if (!$this->Category->exists($id)) {// throw new NotFoundException(__('Invalid category'));// }$this->loadModel('Api');// $apideals = $this->Api->getDealsByCategory($this->Auth->User('id'),$id,$page);// $deals = $apideals['products'];$myactions = $this->Api->getMyActions($this->Auth->User('id'));if(!empty($myactions)) {foreach ($myactions['actions'] as $key => $value) {if($value['UserAction']['action'] == 'like'){$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];}else{$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];}}}$filterstr = '&brands='.$brands.'&subcategories='.$subcategories;$nexturl = "/categories/getdeals/".$id."/?page=".($page+1)."&sort=".$sort."&direction=".$direction."".$filterstr;$offerresponse = $this->getuseroffer();$this->set(compact('offerresponse','nexturl','deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','filterstr'));if(!empty($deals) && !empty($deals[0])){$this->render('/Elements/deals');}else{$this->render('/Elements/nodeals');}}public function linkdeal($id = null) {$filtertype = $this->request->query('filtertype');$user_id = $this->Auth->User('id');$page = $this->request->query('page');if(!isset($page)){$page = 1;}if($filtertype == 'below1000'){$url = $this->apihost."deals/".$user_id."?categoryId=".$id."&limit=20&offset=0&filterData=priceFilter:0^1000|sourceFilter:4&sort=available_price&direction=1";}elseif($filtertype == 'exclusive'){// $url = $this->apihost."getDealsByType?categoryId=".$id."&offset=0&limit=20&type=".$filtertype;$url = $this->apihost."deals/".$user_id."?categoryId=".$id."&limit=20&offset=0&filterData=sourceFilter:4";}$response = $this->make_request($url,null);$deals = array();$response_count =1;if($response == ''){$response_count = 0;}if(!empty($response)){foreach ($response as $key => $value) {// debug($value);if(!empty($value)){$deals[] = $value;}}}$this->loadModel('Api');$myactions = $this->Api->getMyActions($this->Auth->User('id'));if(!empty($myactions)) {foreach ($myactions['actions'] as $key => $value) {if($value['UserAction']['action'] == 'like'){$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];}else{$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];}}}$nexturl = "/categories/getlinkdeals/".$id."?page=".($page+1)."&filtertype=".$filtertype;$offerresponse = $this->getuseroffer();$this->set(compact('filtertype','offerresponse','response_count','deals','id','likedDeals','disLikedDeals','page','nexturl'));}public function getlinkdeals($id = null) {$likedDeals = $disLikedDeals = array();$this->layout = 'ajax';$page = $this->request->query('page');$filtertype = $this->request->query('filtertype');$user_id = $this->Auth->User('id');if(!isset($page)){$page = 1;}$limit = 20;$offset = ($page - 1)*$limit;$likedDeals = $disLikedDeals = array();if($filtertype == 'below1000'){// $url = $this->apihost."deals/".$user_id."?categoryId=".$id."&limit=".$limit."&offset=".$offset."&filterData=priceFilter:0^1000&sort=available_price&direction=1";$url = $this->apihost."deals/".$user_id."?categoryId=".$id."&limit=".$limit."&offset=".$offset."&filterData=priceFilter:0^1000|sourceFilter:4&sort=available_price&direction=1";}elseif($filtertype == 'exclusive'){// $url = $this->apihost."getDealsByType?categoryId=".$id."&type=".$filtertype."&limit=".$limit."&offset=".$offset;$url = $this->apihost."deals/".$user_id."?categoryId=".$id."&limit=".$limit."&offset=".$offset."&filterData=sourceFilter:4";}// $url = $this->apihost."getDealsByType?categoryId=".$id."&type=".$filtertype."&limit=".$limit."&offset=".$offset;$response = $this->make_request($url,null);$deals = array();if(!empty($response)){foreach ($response as $key => $value) {if(!empty($value)){$deals[] = $value;}}}$this->loadModel('Api');$myactions = $this->Api->getMyActions($this->Auth->User('id'));if(!empty($myactions)) {foreach ($myactions['actions'] as $key => $value) {if($value['UserAction']['action'] == 'like'){$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];}else{$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];}}}$nexturl = "/categories/getlinkdeals/".$id."/?page=".($page+1)."&filtertype=".$filtertype;$offerresponse = $this->getuseroffer();$this->set(compact('offerresponse','nexturl','deals','id','page','likedDeals','disLikedDeals'));if(!empty($deals) && !empty($deals[0])){$this->render('/Elements/deals');}else{$this->render('/Elements/nodeals');}}public function dealdetail($item_id = null){setcookie("fresh", '0', null, '/');$this->layout = "innerpages";$dealinfo = $deal = array();$likedDeals = $disLikedDeals = array();$url = $this->mobileapi.'entity/'.$item_id;$dealinfo = $this->make_request($url,null);$this->loadModel('Api');$myactions = $this->Api->getMyActions($this->Auth->User('id'));if(!empty($myactions)) {foreach ($myactions['actions'] as $key => $value) {if($value['UserAction']['action'] == 'like'){$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];}else{$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];}}}$this->set(compact('deal','dealinfo','likedDeals','disLikedDeals'));}public function saholicdeal($proid = null){$likedDeals = $disLikedDeals = array();$this->layout = 'ajax';$deal = array();$url = $this->apihost."getDealById/".$proid;$deal = $this->make_request($url,null);$this->loadModel('Api');$myactions = $this->Api->getMyActions($this->Auth->User('id'));if(!empty($myactions)) {foreach ($myactions['actions'] as $key => $value) {if($value['UserAction']['action'] == 'like'){$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];}else{$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];}}}$offerresponse = $this->getuseroffer();$this->set(compact('offerresponse','deal','likedDeals','disLikedDeals'));$this->render('/Elements/saholicdeal');}public function getdealsforsearchterm($searchterm,$page = null){$likedDeals = $disLikedDeals = array();$this->layout = 'ajax';$page = $this->request->query('page');$subcategories = $this->request->query('subcategories');if(!isset($page)){$page = 1;$offset = 0;$limit=10;}else{$offset = ($page*20) - 30;$limit = 20;}$sort = $this->request->query('sort');$direction = $this->request->query('direction');$url = $this->apihost."searchSubCategory/?offset=".$offset."&limit=".$limit."&searchTerm=".urlencode($searchterm)."&subCategoryId=".$subcategories;$response = $this->make_request($url,null);$deals = array();if(!empty($response)){foreach ($response as $key => $value) {if(!empty($value)){$deals[] = $value;}}}$this->loadModel('Api');$myactions = $this->Api->getMyActions($this->Auth->User('id'));if(!empty($myactions)) {foreach ($myactions['actions'] as $key => $value) {if($value['UserAction']['action'] == 'like'){$likedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];}else{$disLikedDeals[$value['UserAction']['store_product_id']] = $value['UserAction']['id'];}}}$nexturl = "/categories/getdealsforsearchterm/".urlencode($searchterm)."/?page=".($page+1).'&subcategories='.$subcategories;$offerresponse = $this->getuseroffer();$this->set(compact('offerresponse','deals','id','page','likedDeals','disLikedDeals','sort','direction','brands','filter','nexturl'));if(!empty($deals) && !empty($deals[0])){$this->render('/Elements/deals');}else{$this->render('/Elements/nodeals');}}public function target(){$this->layout = "innerpages";$user_id = $this->Auth->user('id');$cachekey = 'target-'.$user_id;$getoffer = Cache::read($cachekey,'target');$current_time = time();$response = "";if($getoffer === false){$offerurl = $this->apihost."getOfferForUser/?user_id=".$user_id;$response = $this->make_request($offerurl,null);Cache::write($cachekey , $response ,'target');if(!empty($response)){// if($response['startDate']/1000 <= $current_time && $response['endDate']/1000 >= $current_time ){// }// else{// $response = "";// }}else{$response = "";}}else{if(!empty($getoffer)){$response = $getoffer;// if($response['startDate']/1000 <= $current_time && $response['endDate']/1000 >= $current_time ){// }// else{// $response = "";// }}}$maxpercentage = 0;if(isset($response['target2_cash_back_percetage']) && !empty($response['target2_cash_back_percetage'])){$maxpercentage = $response['target2_cash_back_percetage'];}else{if(isset($response['target1_cash_back_percetage']) && !empty($response['target1_cash_back_percetage'])){$maxpercentage = $response['target1_cash_back_percetage'];}}$this->loadModel('User');$user_email = "";$user_email = $this->Auth->user('email');$this->set(compact('response','maxpercentage','user_email'));}/*** add method** @return void*/public function add() {if ($this->request->is('post')) {$this->Category->create();if ($this->Category->save($this->request->data)) {$this->Session->setFlash(__('The category has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The category could not be saved. Please, try again.'));}}}/*** edit method** @throws NotFoundException* @param string $id* @return void*/public function edit($id = null) {if (!$this->Category->exists($id)) {throw new NotFoundException(__('Invalid category'));}if ($this->request->is(array('post', 'put'))) {if ($this->Category->save($this->request->data)) {$this->Session->setFlash(__('The category has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The category could not be saved. Please, try again.'));}} else {$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));$this->request->data = $this->Category->find('first', $options);}}/*** delete method** @throws NotFoundException* @param string $id* @return void*/public function delete($id = null) {$this->Category->id = $id;if (!$this->Category->exists()) {throw new NotFoundException(__('Invalid category'));}$this->request->onlyAllow('post', 'delete');if ($this->Category->delete()) {$this->Session->setFlash(__('The category has been deleted.'));} else {$this->Session->setFlash(__('The category could not be deleted. Please, try again.'));}return $this->redirect(array('action' => 'index'));}/*** admin_index method** @return void*/public function admin_index() {$this->Category->recursive = 0;$this->set('categories', $this->Paginator->paginate());}/*** admin_view method** @throws NotFoundException* @param string $id* @return void*/public function admin_view($id = null) {if (!$this->Category->exists($id)) {throw new NotFoundException(__('Invalid category'));}$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));$this->set('category', $this->Category->find('first', $options));}/*** admin_add method** @return void*/public function admin_add() {if ($this->request->is('post')) {// print_r($this->request->data);die;$this->Category->create();if ($this->Category->save($this->request->data)) {$this->Session->setFlash(__('The category has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The category could not be saved. Please, try again.'));}}$this->set('parent_id',$this->Category->find('list'));}/*** admin_edit method** @throws NotFoundException* @param string $id* @return void*/public function admin_edit($id = null) {if (!$this->Category->exists($id)) {throw new NotFoundException(__('Invalid category'));}if ($this->request->is(array('post', 'put'))) {if ($this->Category->save($this->request->data)) {$this->Session->setFlash(__('The category has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The category could not be saved. Please, try again.'));}} else {$options = array('conditions' => array('Category.' . $this->Category->primaryKey => $id));$this->request->data = $this->Category->find('first', $options);}}/*** admin_delete method** @throws NotFoundException* @param string $id* @return void*/public function admin_delete($id = null) {$this->Category->id = $id;if (!$this->Category->exists()) {throw new NotFoundException(__('Invalid category'));}$this->request->onlyAllow('post', 'delete');if ($this->Category->delete()) {$this->Session->setFlash(__('The category has been deleted.'));} else {$this->Session->setFlash(__('The category could not be deleted. Please, try again.'));}return $this->redirect(array('action' => 'index'));}}