Subversion Repositories SmartDukaan

Rev

Rev 10582 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 10582 Rev 11049
Line 29... Line 29...
29
		
29
		
30
	}
30
	}
31
 
31
 
32
	
32
	
33
	function getLogin($get=array(),$post=array(),$module=array())
33
	function getLogin($get=array(),$post=array(),$module=array())
34
	{
34
	{	
35
	
-
 
36
		$output =array();
35
		$output =array();
37
		if(isset($module) and !empty($module))
36
		if(isset($module) and !empty($module))
38
		{
37
		{
39
			if(isset($module['header']) and !empty($module['header']))
38
			if(isset($module['header']) and !empty($module['header']))
40
			{
39
			{
41
				foreach($module['header'] as $header)
40
				foreach($module['header'] as $header)
42
				{
41
				{
-
 
42
					$cache = getFileCache($header);
-
 
43
					if(isset($cache) && !empty($cache)){
-
 
44
						$head['header'][$header] = $cache;
43
 
45
					}else{
44
					$this->curlURL($header,'get');
46
						$this->curlURL($header,'get');	
-
 
47
					}
45
				}
48
				}
46
			}
49
			}
47
			if(isset($module['footer']) and !empty($module['footer']))
50
			if(isset($module['footer']) and !empty($module['footer']))
48
			{
51
			{
49
				foreach($module['footer'] as $footer)
52
				foreach($module['footer'] as $footer)
50
				{
53
				{
-
 
54
					$cache = getFileCache($header);
-
 
55
					if(isset($cache) && !empty($cache)){
-
 
56
						$foot['footer'][$footer] = $cache;
-
 
57
						//echo '<br/>';
-
 
58
					}else{
51
					$this->curlURL($footer,'get');
59
						$this->curlURL($footer,'get');	
-
 
60
					}
52
				}
61
				}
53
			}
62
			}
54
			if(isset($module['response']) and !empty($module['response']))
63
			if(isset($module['response']) and !empty($module['response']))
55
			{
64
			{
56
				foreach($module['response'] as $response)
65
				foreach($module['response'] as $response)
Line 70... Line 79...
70
		}
79
		}
71
		
80
		
72
		//add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
81
		//add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
73
		//$this->curlURL('products','get',$get);
82
		//$this->curlURL('products','get',$get);
74
		$responses = $this->mcurl->execute();
83
		$responses = $this->mcurl->execute();
75
		 //die();
-
 
76
		if(isset($responses) and !empty($responses))
84
		if(isset($responses) and !empty($responses))
77
		$responses = $this->parser->parse_response($responses,$module);
85
		$responses = $this->parser->parse_response($responses,$module);
-
 
86
		if(isset($head) && !empty($head)){
-
 
87
			foreach($head['header'] as $key=>$value){
-
 
88
				$responses['header'][$key] = $value;
-
 
89
			}
78
	
90
		}
-
 
91
		if(isset($foot) && !empty($foot)){
-
 
92
			foreach($foot['footer'] as $key=>$value){
-
 
93
				$responses['footer'][$key] = $value;
-
 
94
			}
79
		
95
		}
80
		return $responses;
96
		return $responses;
81
	}
97
	}
82
	function getSignup($get=array(),$post=array(),$module=array())
98
	function getSignup($get=array(),$post=array(),$module=array())
83
	{
99
	{
84
		$prestaresponse ='';
-
 
85
		
-
 
86
		$output =array();
100
		$output =array();
87
		if(isset($module) and !empty($module))
101
		if(isset($module) and !empty($module))
88
		{
102
		{
89
			if(isset($module['header']) and !empty($module['header']))
103
			if(isset($module['header']) and !empty($module['header']))
90
			{
104
			{
91
				foreach($module['header'] as $header)
105
				foreach($module['header'] as $header)
92
				{
106
				{
-
 
107
					$cache = getFileCache($header);
-
 
108
					if(isset($cache) && !empty($cache)){
-
 
109
						$head['header'][$header] = $cache;
93
 
110
					}else{
94
					$this->curlURL($header,'get');
111
						$this->curlURL($header,'get');	
-
 
112
					}
95
				}
113
				}
96
			}
114
			}
97
			if(isset($module['footer']) and !empty($module['footer']))
115
			if(isset($module['footer']) and !empty($module['footer']))
98
			{
116
			{
99
				foreach($module['footer'] as $footer)
117
				foreach($module['footer'] as $footer)
100
				{
118
				{
-
 
119
					$cache = getFileCache($header);
-
 
120
					if(isset($cache) && !empty($cache)){
-
 
121
						$foot['footer'][$footer] = $cache;
-
 
122
						//echo '<br/>';
-
 
123
					}else{
101
					$this->curlURL($footer,'get');
124
						$this->curlURL($footer,'get');	
-
 
125
					}
102
				}
126
				}
103
			}
127
			}
104
			if(isset($module['response']) and !empty($module['response']))
128
			if(isset($module['response']) and !empty($module['response']))
105
			{
129
			{
106
				foreach($module['response'] as $response)
130
				foreach($module['response'] as $response)
Line 120... Line 144...
120
		}
144
		}
121
		
145
		
122
		//add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
146
		//add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
123
		//$this->curlURL('products','get',$get);
147
		//$this->curlURL('products','get',$get);
124
		$responses = $this->mcurl->execute();
148
		$responses = $this->mcurl->execute();
125
		if(isset($prestaresponse) and !empty($prestaresponse))
-
 
126
			{$responses=array_merge($responses,$prestaresponse);}
-
 
127
		if(isset($responses) and !empty($responses))
149
		if(isset($responses) and !empty($responses))
128
		$responses = $this->parser->parse_response($responses,$module);
150
		$responses = $this->parser->parse_response($responses,$module);
-
 
151
		if(isset($head) && !empty($head)){
-
 
152
			foreach($head['header'] as $key=>$value){
-
 
153
				$responses['header'][$key] = $value;
-
 
154
			}
129
	
155
		}
-
 
156
		if(isset($foot) && !empty($foot)){
-
 
157
			foreach($foot['footer'] as $key=>$value){
-
 
158
				$responses['footer'][$key] = $value;
-
 
159
			}
130
		
160
		}
131
		return $responses;
161
		return $responses;
132
	}
162
	}
133
function curlURL($configurl=null,$methodtype='get',$parameter=array())
163
function curlURL($configurl=null,$methodtype='get',$parameter=array())
134
{
164
{
135
 
165
		
136
		$params ='';
166
		$params ='';
137
		$display='';
167
		$display='';
138
		$url = $this->config->item('curl_base_url');
168
		$url = $this->config->item('curl_base_url');
139
		$productsurl =$this->config->item($configurl);
169
		$productsurl =$this->config->item($configurl);
140
		if(isset($productsurl['url']) and !empty($productsurl['url']))
170
		if(isset($productsurl['url']) and !empty($productsurl['url']))
Line 162... Line 192...
162
	}
192
	}
163
	else
193
	else
164
		{return '';}
194
		{return '';}
165
 
195
 
166
}
196
}
167
function __addPrestaCurl($response,$post,$resource)
-
 
168
{
-
 
169
	$outputresponse =array();
-
 
170
	$outputresponse['method']='post';
-
 
171
	$errors=array();
-
 
172
 
-
 
173
	if(isset($post) and !empty($post))
-
 
174
	{
-
 
175
		$data =$post;
-
 
176
	}
-
 
177
	
-
 
178
 
-
 
179
//error_reporting(E_ALL);
-
 
180
//ini_set('display_errors', '1');
-
 
181
 
-
 
182
// Here we use the WebService to get the schema of "customers" resource
-
 
183
try
-
 
184
{
-
 
185
   
-
 
186
    $opt = array('resource' => $resource);
-
 
187
    $url =$this->config->item('curl_base_url').$resource;
-
 
188
   $xml = $this->prestashopwebservice->get(array('url' => $url.'?schema=blank'));
-
 
189
   $resources = $xml->children()->children();
-
 
190
    //print_r($resources);
-
 
191
   $outputresponse['url']=$url;
-
 
192
   $outputresponse['params']='';
-
 
193
 
-
 
194
 
-
 
195
 
-
 
196
}
-
 
197
catch (PrestaShopWebserviceException $e)
-
 
198
{
-
 
199
    // Here we are dealing with errors
-
 
200
    $trace = $e->getTrace();
-
 
201
    if ($trace[0]['args'][0] == 404) $errors[]= 'Bad ID';
-
 
202
    else if ($trace[0]['args'][0] == 401) $errors[]= 'Bad auth key';
-
 
203
    else $errors[]= 'Other error';
-
 
204
}
-
 
205
 
197
 
206
if (count($data) > 0)
-
 
207
{
-
 
208
	//print_r($data);
-
 
209
// Here we have XML before update, lets update XML
-
 
210
    foreach ($resources as $nodeKey => $node)
-
 
211
    {
-
 
212
    	
-
 
213
        $resources->$nodeKey = @$data[$nodeKey];
-
 
214
 
-
 
215
    }
-
 
216
    try
-
 
217
    {
-
 
218
        $opt = array('resource' => 'customers');
-
 
219
       
-
 
220
            $opt['postXml'] = $xml->asXML();
-
 
221
           
-
 
222
            $xml = $this->prestashopwebservice->add($opt);
-
 
223
 
-
 
224
             $outputresponse['response']=$xml;
-
 
225
            
-
 
226
       
-
 
227
    }
-
 
228
    catch (PrestaShopWebserviceException $ex)
-
 
229
    {
-
 
230
        // Here we are dealing with errors
-
 
231
        $trace = $ex->getTrace();
-
 
232
        if ($trace[0]['args'][0] == 404) $errors[]= 'Bad ID';
-
 
233
        else if ($trace[0]['args'][0] == 401) $errors[]= 'Bad auth key';
-
 
234
        else $errors[]= 'Other error<br />'.$ex->getMessage();
-
 
235
    }
-
 
236
}
-
 
237
 
-
 
238
return array($response=>$outputresponse,'errors'=>$errors);
-
 
239
}
-
 
240
 
198
 
241
}
199
}