Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Privatedeals extends MY_Controller {

public $layoutName ='';
        function __construct() {
                // Call the CI_controller constructor
                parent::__construct();          
                $authorized = $this->session->userdata('authorized');
                if(!isset($authorized) || empty($authorized)){
                        redirect(base_url().'auth/login');
                }
                $this->layout->setlayout('layout/layout_main');
                $this->load->model('privatedeal_model');
                $this->load->model('magento_model');
                $this->layoutName= $this->layout->getLayout();
                $this->layoutName =substr($this->layoutName , 0, strrpos($this->layoutName , "/")).'/';
        }

        public function index()
        {
                $userId = $this->session->userdata['authorized']['Id'];
                $data = array();
                //get cache 
                $configdata =array();
                $configdata = $this->config->item('privatedeals');
                $name = $configdata['response'];

                foreach ($name as $key => $value) {
                        $name = $value;
                }
                $cachemodule = array('header','footer');
                $configdata = getCache($configdata,$cachemodule);
                
                $data['response']=$this->privatedeal_model->getProducts('',$this->input->post(),$configdata['module'], $userId);
                if(isset($data['response']['response']['private_deals'][0]->response->redirectUrl)) {
                redirect($data['response']['response']['private_deals'][0]->response->redirectUrl);
                exit();
        }
                //set cache to output or renew cache
                if(isset($cachemodule) and !empty($cachemodule))
                {
                        foreach($cachemodule as $cm)
                        {
                                if(isset($configdata[$cm]) and !empty($configdata[$cm]))
                                {
                                        $data['response'][$cm]=$configdata[$cm];
                                }
                        }
                }
                setCache($configdata['module'],$cachemodule,$data['response']);
                $this->lessphp->object()->ccompile('assets/css/pd-list.less','assets/css/pd-list.css');
                $data['stylesheet'] = 'pd-list.css';
                //TODO: Get coupon code from api
                $data['response']['couponcode'] = "saholicdeal";
                $this->layout->view('privatedeals/products_view',$data);
        }

        public function getProductList($page=null)
        {
                $userId = $this->session->userdata['authorized']['Id'];
                $value = intval($category);
                $url = $this->config->item('private_deals');
                $url = $url['url'];
                $url = $this->config->item('curl_base_url').$url.'/'.$page;                     
                $configdata =array();
                $configdata = $this->config->item('privatedeals');
                $response = $this->privatedeal_model->getProducts('',$this->input->post(),$configdata, $userId,$page);
                $response = $response['response']['private_deals'];     
                $count = $response[0]->response->count;
                $productListResponse ='';
                $TotalPage = ceil($count/10);
                if($TotalPage < $page) {$product_list='';}
                else{$product_list = $response;}
                 
                if(isset($product_list) and !empty($product_list))
                {
                        foreach($product_list[0]->response->items as $pl)
                        {
                                if(isset($pl->image_url) and !empty($pl->image_url))
                                {
                                                $productListResponse .= '<a class="pd-list" href="'. base_url().$pl->url.'">
                                        <div class="pd-image" style="background:url(\''.$pl->image_url.'\')no-repeat center center;background-size:contain;"></div>
                                                <div class="pd-info">
                                        <div class="pdt-name">'.$pl->title.'</div>
                                                <div class="pdt-price"><span class="pricetype">Site Price</span>';
                                                if(isset($pl->price) || isset($pl->mrp)){
                                                        $productListResponse .='<span class="pr">Rs</span>';
                                                        if(isset($pl->mrp) && $pl->mrp != 0){
                                                                $productListResponse .='<span class="pr-linethrough">'.$pl->mrp.'</span>';
                                                        }
                                                        if(isset($pl->price) && $pl->price != 0){
                                                                $productListResponse .='<span class="pr-linethrough">'.$pl->price.'</span>';
                                                        }       
                                                }
                                                if(isset($pl->dealprice) && $pl->dealprice != 0){
                                                        $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>';
                                                }                       
                                                if(isset($pl->offer_text) && !empty($pl->offer_text)) {
                                                        $productListResponse .= '<div class="pdt-offertext">'.$pl->offer_text.'</div>'; 
                                                }
                                        $productListResponse .='<div class="pdt-spec">'. $pl->description.' </div>';
                        
                                                if(isset($pl->dealcolors) && !empty($pl->dealcolors) && trim($pl->dealcolors[0])!='') {
                                                        $productListResponse .= '<div class="pdt-offercolors">Offer available for : '.implode(',',$pl->dealcolors).'</div>';
                                                }

                                                $productListResponse .= '</div></a>';
                                        
                                }               

                        }
                }
                echo $productListResponse;

        }
}