| 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 |
|
|
|
11 |
Class Oauth_model extends CI_Model {
|
|
|
12 |
|
|
|
13 |
var $url = '';
|
|
|
14 |
var $parser_model;
|
|
|
15 |
var $parser;
|
|
|
16 |
var $current_client;
|
|
|
17 |
|
|
|
18 |
function __construct() {
|
|
|
19 |
|
|
|
20 |
// Call the Model constructor
|
|
|
21 |
parent::__construct();
|
|
|
22 |
//load appropriate parser
|
|
|
23 |
$current_client =$this -> config -> item('current_client');
|
|
|
24 |
$model = $current_client.'_model';
|
|
|
25 |
$this->load->model($model);
|
|
|
26 |
$this->parser = $this-> $model;
|
|
|
27 |
$this->current_client=$this -> config -> item('current_client');
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
function getLogin($get=array(),$post=array(),$module=array())
|
|
|
34 |
{
|
|
|
35 |
|
|
|
36 |
$output =array();
|
|
|
37 |
if(isset($module) and !empty($module))
|
|
|
38 |
{
|
|
|
39 |
if(isset($module['header']) and !empty($module['header']))
|
|
|
40 |
{
|
|
|
41 |
foreach($module['header'] as $header)
|
|
|
42 |
{
|
|
|
43 |
|
|
|
44 |
$this->curlURL($header,'get');
|
|
|
45 |
}
|
|
|
46 |
}
|
|
|
47 |
if(isset($module['footer']) and !empty($module['footer']))
|
|
|
48 |
{
|
|
|
49 |
foreach($module['footer'] as $footer)
|
|
|
50 |
{
|
|
|
51 |
$this->curlURL($footer,'get');
|
|
|
52 |
}
|
|
|
53 |
}
|
|
|
54 |
if(isset($module['response']) and !empty($module['response']))
|
|
|
55 |
{
|
|
|
56 |
foreach($module['response'] as $response)
|
|
|
57 |
{
|
|
|
58 |
if(isset($post) and !empty($post))
|
|
|
59 |
{
|
|
|
60 |
if($this->current_client=='prestashop' || $this->current_client=='magento' )
|
|
|
61 |
$this->curlURL($response,'post',$post);
|
|
|
62 |
else
|
|
|
63 |
$this->curlURL($response,'post',$post);
|
|
|
64 |
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
//add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
|
|
|
73 |
//$this->curlURL('products','get',$get);
|
|
|
74 |
$responses = $this->mcurl->execute();
|
|
|
75 |
//die();
|
|
|
76 |
if(isset($responses) and !empty($responses))
|
|
|
77 |
$responses = $this->parser->parse_response($responses,$module);
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
return $responses;
|
|
|
81 |
}
|
|
|
82 |
function getSignup($get=array(),$post=array(),$module=array())
|
|
|
83 |
{
|
|
|
84 |
$prestaresponse ='';
|
|
|
85 |
|
|
|
86 |
$output =array();
|
|
|
87 |
if(isset($module) and !empty($module))
|
|
|
88 |
{
|
|
|
89 |
if(isset($module['header']) and !empty($module['header']))
|
|
|
90 |
{
|
|
|
91 |
foreach($module['header'] as $header)
|
|
|
92 |
{
|
|
|
93 |
|
|
|
94 |
$this->curlURL($header,'get');
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
if(isset($module['footer']) and !empty($module['footer']))
|
|
|
98 |
{
|
|
|
99 |
foreach($module['footer'] as $footer)
|
|
|
100 |
{
|
|
|
101 |
$this->curlURL($footer,'get');
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
if(isset($module['response']) and !empty($module['response']))
|
|
|
105 |
{
|
|
|
106 |
foreach($module['response'] as $response)
|
|
|
107 |
{
|
|
|
108 |
if(isset($post) and !empty($post))
|
|
|
109 |
{
|
|
|
110 |
if($this->current_client=='prestashop' || $this->current_client=='magento' )
|
|
|
111 |
$this->curlURL($response,'post',$post);
|
|
|
112 |
else
|
|
|
113 |
$this->curlURL($response,'post',$post);
|
|
|
114 |
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
//add_call( KEY, METHOD, URL, array of PARAMS, array of CURL_OPTS )
|
|
|
123 |
//$this->curlURL('products','get',$get);
|
|
|
124 |
$responses = $this->mcurl->execute();
|
|
|
125 |
if(isset($prestaresponse) and !empty($prestaresponse))
|
|
|
126 |
{$responses=array_merge($responses,$prestaresponse);}
|
|
|
127 |
if(isset($responses) and !empty($responses))
|
|
|
128 |
$responses = $this->parser->parse_response($responses,$module);
|
|
|
129 |
|
|
|
130 |
|
|
|
131 |
return $responses;
|
|
|
132 |
}
|
|
|
133 |
function curlURL($configurl=null,$methodtype='get',$parameter=array())
|
|
|
134 |
{
|
|
|
135 |
|
|
|
136 |
$params ='';
|
|
|
137 |
$display='';
|
|
|
138 |
$url = $this->config->item('curl_base_url');
|
|
|
139 |
$productsurl =$this->config->item($configurl);
|
|
|
140 |
if(isset($productsurl['url']) and !empty($productsurl['url']))
|
|
|
141 |
{
|
|
|
142 |
$url .=$productsurl['url'];
|
|
|
143 |
if($productsurl['display'])
|
|
|
144 |
{$display=$productsurl['display'];}
|
|
|
145 |
if(empty($parameter)){$parameter=$productsurl['params'];}
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
if(isset($parameter) and !empty($parameter) and $methodtype=='get')
|
|
|
149 |
{
|
|
|
150 |
$params = $this->parser->prepareParams($parameter,$display,$configurl);
|
|
|
151 |
|
|
|
152 |
}
|
|
|
153 |
if(isset($parameter) and !empty($parameter) and $methodtype=='post')
|
|
|
154 |
{
|
|
|
155 |
$params = $this->parser->prepareParams($parameter,$display,$configurl);
|
|
|
156 |
$methodtype ='post';
|
|
|
157 |
}
|
|
|
158 |
if(!isset($parameter) || empty($parameter))
|
|
|
159 |
{$params =$this->parser->prepareParams('',$display,$configurl);}
|
|
|
160 |
//$methodtype = 'post';
|
|
|
161 |
return $this->mcurl->add_call($configurl,$methodtype,$url,$params);
|
|
|
162 |
}
|
|
|
163 |
else
|
|
|
164 |
{return '';}
|
|
|
165 |
|
|
|
166 |
}
|
|
|
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 |
|
|
|
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 |
|
|
|
241 |
}
|