Subversion Repositories SmartDukaan

Rev

Rev 10582 | Rev 11054 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10582 lgm 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
 
11052 lgm 34
		print_r($module);
10582 lgm 35
		$output =array();
36
		if(isset($module) and !empty($module))
37
		{
38
			if(isset($module['header']) and !empty($module['header']))
39
			{
40
				foreach($module['header'] as $header)
41
				{
42
 
11052 lgm 43
					$cache = getFileCache($header);
44
					if(isset($cache) && !empty($cache)){
45
						$head['header'][$header] = $cache;
46
					}else{
47
						$this->curlURL($header,'get');	
48
					}
10582 lgm 49
				}
50
			}
51
			if(isset($module['footer']) and !empty($module['footer']))
52
			{
53
				foreach($module['footer'] as $footer)
54
				{
11052 lgm 55
					$cache = getFileCache($footer);
56
					if(isset($cache) && !empty($cache)){
57
						$foot['footer'][$footer] = $cache;
58
					}else{
59
						$this->curlURL($footer,'get');	
60
					}
10582 lgm 61
				}
62
			}
63
			if(isset($module['response']) and !empty($module['response']))
64
			{
65
				foreach($module['response'] as $response)
66
				{
67
 
68
					if(isset($post) and !empty($post))
69
					{
70
						if($this->current_client=='magento' )
71
						$this->curlURL($response,'post',$post,$cartId);
72
					else
73
						$this->curlURL($response,'post',$post,$cartId);
74
 
75
					}
76
					else
77
					{
78
 
79
						$this->curlURL($response,'get',$get,$cartId);
80
					}
81
				}
82
			}
83
 
84
 
85
		}
86
 
87
		//add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
88
		//$this->curlURL('products','get',$get);
89
		$responses = $this->mcurl->execute();
90
		if(isset($responses) and !empty($responses))
91
		$responses = $this->parser->parse_response($responses,$module);
11052 lgm 92
		if(isset($head) && !empty($head)){
93
			foreach($head['header'] as $key=>$value){
94
				$responses['header'][$key] = $value;
95
			}
96
		}
97
		if(isset($foot) && !empty($foot)){
98
			foreach($foot['footer'] as $key=>$value){
99
				$responses['footer'][$key] = $value;
100
			}
101
		}
10582 lgm 102
		return $responses;
103
	}
104
function curlURL($configurl=null,$methodtype='get',$parameter=array(), $cartId=null)
105
{
106
		$params ='';
107
		$display='';
108
		$url = $this->config->item('curl_base_url');
109
		$productsurl =$this->config->item($configurl);
110
		if(isset($productsurl['url']) and !empty($productsurl['url']))
111
			{
112
				if($configurl == 'cartcoupon' || $configurl == 'cartcouponclear'){
113
					$url .= 'cart/'.$cartId.'/'.$productsurl['url'];
114
				}else{
115
					$url .=$productsurl['url'];
116
				}
117
				if($productsurl['display'])
118
				{$display=$productsurl['display'];}
119
			if(empty($parameter)){$parameter=$productsurl['params'];}
120
 
121
 
122
		if(isset($parameter) and !empty($parameter) and $methodtype=='get')
123
		{
124
			$params = $this->parser->prepareParams($parameter,$display,$configurl);
125
 
126
		}
127
		if(isset($parameter) and !empty($parameter) and $methodtype=='post')
128
		{
129
			$params = $this->parser->prepareParams($parameter,$display,$configurl);
130
			$methodtype ='post';
131
		}
132
		if(!isset($parameter) || empty($parameter))
133
			{$params =$this->parser->prepareParams('',$display,$configurl);}
134
		if($configurl == 'carts'){
135
		 	$methodtype = 'get';
136
		 	$productsparams =$this->config->item($configurl);
137
		 	$productsparams = $productsparams['params'];
138
		 	$i = 0;
139
		 	$newparams = array();
140
		 	foreach($productsparams as $key => $value){
141
		 		if (array_key_exists($value,$params)){
142
    				$newparams[$value] = $params[$value];
143
    				$i++;
144
				}
145
		 	}
146
		 	$params = $newparams;
147
		 }
148
 
149
		if(isset($cartId) && $cartId != null && $configurl != 'cartcoupon' && $configurl != 'cartcouponclear'){
150
			$url .= '/'.$cartId;
151
		}
152
		return $this->mcurl->add_call($configurl,$methodtype,$url,$params);
153
	}
154
	else
155
		{return '';}
156
 
157
}
158
 
159
}