Subversion Repositories SmartDukaan

Rev

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