Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12694 anikendra 1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
 
3
class Privatedeals extends MY_Controller {
4
 
5
public $layoutName ='';
6
	function __construct() {
7
		// Call the CI_controller constructor
8
		parent::__construct();		
9
		$authorized = $this->session->userdata('authorized');
10
		if(!isset($authorized) || empty($authorized)){
11
			redirect(base_url().'auth/login');
12
		}
13
		$this->layout->setlayout('layout/layout_main');
14
		$this->load->model('privatedeal_model');
15
		$this->load->model('magento_model');
16
		$this->layoutName= $this->layout->getLayout();
17
		$this->layoutName =substr($this->layoutName , 0, strrpos($this->layoutName , "/")).'/';
18
	}
19
 
20
	public function index()
21
	{
22
		$userId = $this->session->userdata['authorized']['Id'];
23
		$data = array();
24
		//get cache 
25
		$configdata =array();
26
		$configdata = $this->config->item('privatedeals');
27
		$name = $configdata['response'];
28
 
29
		foreach ($name as $key => $value) {
30
			$name = $value;
31
		}
32
		$cachemodule = array('header','footer');
33
		$configdata = getCache($configdata,$cachemodule);
34
 
35
		$data['response']=$this->privatedeal_model->getProducts('',$this->input->post(),$configdata['module'], $userId);
36
		if(isset($data['response']['response']['private_deals'][0]->response->redirectUrl)) {
37
	        redirect($data['response']['response']['private_deals'][0]->response->redirectUrl);
38
	        exit();
39
        }
40
		//set cache to output or renew cache
41
		if(isset($cachemodule) and !empty($cachemodule))
42
		{
43
			foreach($cachemodule as $cm)
44
			{
45
				if(isset($configdata[$cm]) and !empty($configdata[$cm]))
46
				{
47
					$data['response'][$cm]=$configdata[$cm];
48
				}
49
			}
50
		}
51
		setCache($configdata['module'],$cachemodule,$data['response']);
52
		$this->lessphp->object()->ccompile('assets/css/pd-list.less','assets/css/pd-list.css');
53
		$data['stylesheet'] = 'pd-list.css';
54
		//TODO: Get coupon code from api
55
		$data['response']['couponcode'] = "saholicdeal";
56
		$this->layout->view('privatedeals/products_view',$data);
57
	}
58
 
59
	public function getProductList($page=null)
60
	{
61
		$userId = $this->session->userdata['authorized']['Id'];
62
	 	$value = intval($category);
63
		$url = $this->config->item('private_deals');
64
	  	$url = $url['url'];
65
		$url = $this->config->item('curl_base_url').$url.'/'.$page;	         	
66
		$configdata =array();
67
		$configdata = $this->config->item('privatedeals');
68
		$response = $this->privatedeal_model->getProducts('',$this->input->post(),$configdata, $userId,$page);
69
		$response = $response['response']['private_deals'];	
70
		$count = $response[0]->response->count;
71
		$productListResponse ='';
72
		$TotalPage = ceil($count/10);
73
		if($TotalPage < $page) {$product_list='';}
74
		else{$product_list = $response;}
75
 
76
		if(isset($product_list) and !empty($product_list))
77
		{
78
			foreach($product_list[0]->response->items as $pl)
79
			{
80
				if(isset($pl->image_url) and !empty($pl->image_url))
81
				{
82
						$productListResponse .= '<a class="pd-list" href="'. base_url().$pl->url.'">
83
          				<div class="pd-image" style="background:url(\''.$pl->image_url.'\')no-repeat center center;background-size:contain;"></div>
84
          					<div class="pd-info">
85
            				<div class="pdt-name">'.$pl->title.'</div>
86
           			 		<div class="pdt-price"><span class="pricetype">Site Price</span>';
87
           			 		if(isset($pl->price) || isset($pl->mrp)){
88
           			 			$productListResponse .='<span class="pr">Rs</span>';
89
           			 			if(isset($pl->mrp) && $pl->mrp != 0){
90
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
91
           			 			}
92
           			 			if(isset($pl->price) && $pl->price != 0){
93
           			 				$productListResponse .='<span class="pr-linethrough">'.$pl->price.'</span>';
94
           			 			}	
95
           			 		}
96
						if(isset($pl->dealprice) && $pl->dealprice != 0){
97
							$productListResponse .='</div><div class="pdt-price pdeal-price"><span class="pricetype">Your Price</span><span class="pr">Rs</span> <span class="pr-original">'.$pl->dealprice.'</span></div>';
98
						}			
99
           			 		if(isset($pl->offer_text) && !empty($pl->offer_text)) {
100
	           			 		$productListResponse .= '<div class="pdt-offertext">'.$pl->offer_text.'</div>';	
101
	           			 	}
102
					$productListResponse .='<div class="pdt-spec">'. $pl->description.' </div>';
103
 
104
						if(isset($pl->dealcolors) && !empty($pl->dealcolors) && trim($pl->dealcolors[0])!='') {
105
							$productListResponse .= '<div class="pdt-offercolors">Offer available for : '.implode(',',$pl->dealcolors).'</div>';
106
						}
107
 
108
           			 		$productListResponse .= '</div></a>';
109
 
110
				}		
111
 
112
			}
113
		}
114
		echo $productListResponse;
115
 
116
	}
117
}