Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12694 anikendra 1
<?php
2
if (!defined('BASEPATH'))
3
	exit('No direct script access allowed');
4
 
5
 
6
/*
7
 * Model for home
8
 */ 
9
 
10
Class Cart_model extends CI_Model {
11
 
12
	var $url = '';
13
	var $parser_model;
14
	var $parser;
15
 
16
	function __construct() {
17
 
18
		// Call the Model constructor
19
		parent::__construct();
20
		//load appropriate parser
21
		$this->current_client =$this -> config -> item('current_client');
22
		$model = $this->current_client.'_model';
23
		$this->load->model($model);
24
		$this->parser = $this-> $model;
25
 
26
 
27
	}
28
 
29
 
30
 
31
	function getCart($get=array(),$post=array(),$module=array(), $cartId=null)
32
	{
33
		$output =array();
34
		if(isset($module) and !empty($module))
35
		{
36
			if(isset($module['header']) and !empty($module['header']))
37
			{
38
				foreach($module['header'] as $header)
39
				{
40
 
41
					$cache = getFileCache($header);
42
					if(isset($cache) && !empty($cache)){
43
						$head['header'][$header] = $cache;
44
					}else{
45
						$this->curlURL($header,'get');	
46
					}
47
				}
48
			}
49
			if(isset($module['footer']) and !empty($module['footer']))
50
			{
51
				foreach($module['footer'] as $footer)
52
				{
53
					$cache = getFileCache($footer);
54
					if(isset($cache) && !empty($cache)){
55
						$foot['footer'][$footer] = $cache;
56
					}else{
57
						$this->curlURL($footer,'get');	
58
					}
59
				}
60
			}
61
			if(isset($module['response']) and !empty($module['response']))
62
			{
63
				foreach($module['response'] as $response)
64
				{
65
 
66
					if(isset($post) and !empty($post))
67
					{
68
						if($this->current_client=='magento' )
69
						$this->curlURL($response,'post',$post,$cartId);
70
					else
71
						$this->curlURL($response,'post',$post,$cartId);
72
 
73
					}
74
					else
75
					{
76
						$this->curlURL($response,'get',$get,$cartId);
77
					}
78
				}
79
			}
80
 
81
 
82
		}
83
 
84
		//add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
85
		//$this->curlURL('products','get',$get);
86
		$responses = $this->mcurl->execute();
87
		if(isset($responses) and !empty($responses))
88
		$responses = $this->parser->parse_response($responses,$module);
89
		if(isset($head) && !empty($head)){
90
			foreach($head['header'] as $key=>$value){
91
				$responses['header'][$key] = $value;
92
			}
93
		}
94
		if(isset($foot) && !empty($foot)){
95
			foreach($foot['footer'] as $key=>$value){
96
				$responses['footer'][$key] = $value;
97
			}
98
		}
99
		return $responses;
100
	}
101
function curlURL($configurl=null,$methodtype='get',$parameter=array(), $cartId=null)
102
{
103
		$params ='';
104
		$display='';
105
		$url = $this->config->item('curl_base_url');
106
		$productsurl =$this->config->item($configurl);
107
		if(isset($productsurl['url']) and !empty($productsurl['url']))
108
			{
109
				if($configurl == 'cartcoupon' || $configurl == 'cartcouponclear'){
110
					$url .= 'cart/'.$cartId.'/'.$productsurl['url'];
111
				}else{
112
					$url .=$productsurl['url'];
113
				}
114
				if($productsurl['display'])
115
				{$display=$productsurl['display'];}
116
			if(empty($parameter)){$parameter=$productsurl['params'];}
117
 
118
 
119
		if(isset($parameter) and !empty($parameter) and $methodtype=='get')
120
		{
121
			$params = $this->parser->prepareParams($parameter,$display,$configurl);
122
 
123
		}
124
		if(isset($parameter) and !empty($parameter) and $methodtype=='post')
125
		{
126
			$params = $this->parser->prepareParams($parameter,$display,$configurl);
127
			$methodtype ='post';
128
		}
129
		if(!isset($parameter) || empty($parameter))
130
			{$params =$this->parser->prepareParams('',$display,$configurl);}
131
		if($configurl == 'carts'){
132
		 	$methodtype = 'get';
133
		 	$productsparams =$this->config->item($configurl);
134
		 	$productsparams = $productsparams['params'];
135
		 	$i = 0;
136
		 	$newparams = array();
137
		 	foreach($productsparams as $key => $value){
138
		 		if (array_key_exists($value,$params)){
139
    				$newparams[$value] = $params[$value];
140
    				$i++;
141
				}
142
		 	}
143
		 	$params = $newparams;		 	 
144
		 }
145
 
146
		if(isset($cartId) && $cartId != null && $configurl != 'cartcoupon' && $configurl != 'cartcouponclear'){
147
			$url .= '/'.$cartId;
148
		}
149
		return $this->mcurl->add_call($configurl,$methodtype,$url,$params);
150
	}
151
	else
152
		{return '';}
153
 
154
}
155
 
156
}