1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* WebshopServer |
4
|
|
|
* |
5
|
|
|
* @category XMLRPC_Server |
6
|
|
|
* @package Intraface_XMLRPC_Shop |
7
|
|
|
* @author Lars Olesen <[email protected]> |
8
|
|
|
* @version @package-version@ |
9
|
|
|
*/ |
10
|
|
|
require_once 'Intraface/modules/webshop/Webshop.php'; |
11
|
|
|
require_once 'Intraface/modules/webshop/FeaturedProducts.php'; |
12
|
|
|
|
13
|
|
|
class Intraface_XMLRPC_Shop_Server |
14
|
|
|
{ |
15
|
|
|
private $kernel; |
16
|
|
|
private $webshop; |
17
|
|
|
private $basket; |
18
|
|
|
private $product; |
|
|
|
|
19
|
|
|
private $credentials; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Gets a list with products |
23
|
|
|
* |
24
|
|
|
* @param struct $credentials Credentials to use the server |
25
|
|
|
* @param array $search Optional search array |
26
|
|
|
* |
27
|
|
|
* @return array |
28
|
|
|
*/ |
29
|
|
|
public function getProducts($credentials, $search = array()) |
30
|
|
|
{ |
31
|
|
|
$this->checkCredentials($credentials); |
32
|
|
|
|
33
|
|
|
$offset = 0; |
|
|
|
|
34
|
|
|
|
35
|
|
|
$mixed = array(); |
36
|
|
|
if (!empty($search)) { |
37
|
|
|
$mixed = $search; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$search = ''; |
|
|
|
|
41
|
|
|
|
42
|
|
|
$this->_factoryWebshop(); |
43
|
|
|
|
44
|
|
|
$products = array(); |
|
|
|
|
45
|
|
|
|
46
|
|
|
$area = ''; |
47
|
|
|
|
48
|
|
|
if (!empty($mixed['area'])) { |
49
|
|
|
$area = $mixed['area']; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$product = new Product($this->webshop->kernel); |
53
|
|
|
|
54
|
|
|
if (!isset($mixed['use_paging']) || $mixed['use_paging'] == 'true') { |
55
|
|
|
$product->getDBQuery()->usePaging('paging'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
// sublevel has to be used so other searches are not overwritten |
60
|
|
|
$product->getDBQuery()->storeResult('use_stored', 'webshop_' . $area . '_' . md5($this->credentials['session_id']), 'sublevel'); |
61
|
|
|
$debug2 = serialize($mixed); |
62
|
|
|
if (isset($mixed['offset']) and array_key_exists('offset', $mixed) and is_numeric($mixed['offset'])) { |
|
|
|
|
63
|
|
|
$product->getDBQuery()->useStored(true); |
64
|
|
|
$product->getDBQuery()->setPagingOffset((int)$mixed['offset']); |
65
|
|
|
$debug2 .= 'offset ' . $mixed['offset']; |
66
|
|
|
} elseif (isset($mixed['use_stored']) and array_key_exists('use_stored', $mixed) and $mixed['use_stored'] == 'true') { |
|
|
|
|
67
|
|
|
$product->getDBQuery()->useStored(true); |
68
|
|
|
$debug2 .= 'use_stored true'; |
69
|
|
|
} else { |
70
|
|
|
if (isset($mixed['search']) and array_key_exists('search', $mixed) and !empty($mixed['search'])) { |
|
|
|
|
71
|
|
|
$product->getDBQuery()->setFilter('search', $mixed['search']); |
72
|
|
|
$debug2 .= 'search ' . $mixed['search']; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
if (isset($mixed['keywords']) and array_key_exists('keywords', $mixed) and !empty($mixed['keywords'])) { |
|
|
|
|
76
|
|
|
$product->getDBQuery()->setFilter('keywords', $mixed['keywords']); |
77
|
|
|
$debug2 .= 'keyword ' . $mixed['keywords']; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
if (isset($mixed['ids']) and array_key_exists('ids', $mixed) and is_array($mixed['ids'])) { |
|
|
|
|
81
|
|
|
$product->getDBQuery()->setFilter('ids', $mixed['ids']); |
82
|
|
|
$debug2 .= 'ids ' . implode(', ', $mixed['ids']); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
if (isset($mixed['sorting']) and array_key_exists('sorting', $mixed) and !empty($mixed['sorting'])) { |
|
|
|
|
86
|
|
|
$product->getDBQuery()->setFilter('sorting', $mixed['sorting']); |
87
|
|
|
$debug2 .= 'sorting ' . $mixed['sorting']; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return array( |
92
|
|
|
'parameter' => $mixed, |
93
|
|
|
'debug2' => $debug2, |
94
|
|
|
'products' => $product->getList('webshop'), |
95
|
|
|
'paging' => $product->getDBQuery()->getPaging(), |
96
|
|
|
'search' => array(), |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Gets one product |
103
|
|
|
* |
104
|
|
|
* @param struct $credentials Credentials to use the server |
105
|
|
|
* @param integer $id Product id |
106
|
|
|
* |
107
|
|
|
* @return array |
108
|
|
|
*/ |
109
|
|
|
public function getProduct($credentials, $id) |
110
|
|
|
{ |
111
|
|
|
$this->checkCredentials($credentials); |
112
|
|
|
|
113
|
|
|
$this->_factoryWebshop(); |
114
|
|
|
|
115
|
|
|
$id = intval($id); |
116
|
|
|
|
117
|
|
|
if (!is_numeric($id)) { |
118
|
|
|
require_once 'XML/RPC2/Exception.php'; |
119
|
|
|
throw new XML_RPC2_FaultException('product id must be an integer', -5); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
$product = new Product($this->kernel, $id); |
123
|
|
|
$product->getPictures(); |
124
|
|
|
if (!$product->get('has_variation')) { |
125
|
|
|
// loads stock information to array; |
126
|
|
|
$product->getStock(); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
return $product->get(); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Gets related products |
134
|
|
|
* |
135
|
|
|
* @param struct $credentials Credentials to use the server |
136
|
|
|
* @param integer $id Product id |
137
|
|
|
* |
138
|
|
|
* @return array |
139
|
|
|
*/ |
140
|
|
View Code Duplication |
public function getRelatedProducts($credentials, $id) |
|
|
|
|
141
|
|
|
{ |
142
|
|
|
$this->checkCredentials($credentials); |
143
|
|
|
|
144
|
|
|
$this->_factoryWebshop(); |
145
|
|
|
|
146
|
|
|
$product_id = intval($id); |
147
|
|
|
|
148
|
|
|
if (!is_numeric($product_id)) { |
149
|
|
|
require_once 'XML/RPC2/Exception.php'; |
150
|
|
|
throw new XML_RPC2_FaultException('product id must be an integer', -5); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
$product = new Product($this->kernel, $product_id); |
154
|
|
|
return $product->getRelatedProducts(); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Gets featured products |
159
|
|
|
* |
160
|
|
|
* Method is experimental and only used by discimport.dk. If you need to use it |
161
|
|
|
* as well, please contact [email protected]. |
162
|
|
|
* |
163
|
|
|
* @param struct $credentials Credentials to use the server |
164
|
|
|
* |
165
|
|
|
* @return array |
166
|
|
|
*/ |
167
|
|
|
public function getFeaturedProducts($credentials) |
168
|
|
|
{ |
169
|
|
|
$related_products = array(); |
|
|
|
|
170
|
|
|
|
171
|
|
|
$this->checkCredentials($credentials); |
172
|
|
|
|
173
|
|
|
$this->_factoryWebshop(); |
174
|
|
|
|
175
|
|
|
$db = MDB2::singleton(DB_DSN); |
176
|
|
|
|
177
|
|
|
if (PEAR::isError($db)) { |
178
|
|
|
require_once 'XML/RPC2/Exception.php'; |
179
|
|
|
throw new XML_RPC2_FaultException($db->getMessage() . $db->getUserInfo(), -1); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
$featured = new Intraface_Webshop_FeaturedProducts($this->kernel->intranet, $db); |
183
|
|
|
$all = $featured->getAll(); |
184
|
|
|
|
185
|
|
|
$related_products = array(); |
186
|
|
|
|
187
|
|
|
foreach ($all as $row) { |
188
|
|
|
$product = new Product($this->kernel); |
189
|
|
|
// 265 |
190
|
|
|
$product->getDBQuery()->setFilter('keywords', array($row['keyword_id'])); |
191
|
|
|
|
192
|
|
|
$related_products[] = array( |
193
|
|
|
'title' => $row['headline'], |
194
|
|
|
'products' => $product->getList() |
195
|
|
|
); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
return $related_products; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Gets product keywords which can be used to sort ones webshop |
203
|
|
|
* |
204
|
|
|
* Method is experimental and only used by nylivsstil.dk. If you need to use it |
205
|
|
|
* as well, please contact [email protected]. |
206
|
|
|
* |
207
|
|
|
* @param struct $credentials Credentials to use the server |
208
|
|
|
* |
209
|
|
|
* @return array with id and keywords |
210
|
|
|
*/ |
211
|
|
View Code Duplication |
function getProductKeywords($credentials) |
|
|
|
|
212
|
|
|
{ |
213
|
|
|
|
214
|
|
|
$this->checkCredentials($credentials); |
215
|
|
|
$this->_factoryWebshop(); |
216
|
|
|
|
217
|
|
|
$product = new Product($this->kernel); |
218
|
|
|
$keywords = $product->getKeywordAppender(); |
219
|
|
|
return $keywords->getUsedKeywords(); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Add product to basket |
224
|
|
|
* |
225
|
|
|
* @param struct $credentials Credentials to use the server |
226
|
|
|
* @param integer $id Product id to add |
227
|
|
|
* @param integer $quantity Optional quantity |
228
|
|
|
* @param string $text Extra text to the itemline |
229
|
|
|
* @param integer $product_detail_id Product detail id |
230
|
|
|
* |
231
|
|
|
* @return boolean |
232
|
|
|
*/ |
233
|
|
|
public function addProductToBasket($credentials, $id, $quantity = 1, $text = '', $product_detail_id = 0) |
234
|
|
|
{ |
235
|
|
|
if (is_object($return = $this->checkCredentials($credentials))) { |
236
|
|
|
return $return; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
$this->_factoryWebshop(); |
240
|
|
|
|
241
|
|
|
$product_id = intval($id); |
242
|
|
|
|
243
|
|
|
if (!is_numeric($product_id)) { |
244
|
|
|
require_once 'XML/RPC2/Exception.php'; |
245
|
|
|
throw new XML_RPC2_FaultException('product id must be an integer', -5); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
$text = $this->utf8Decode($text); |
249
|
|
|
return $this->webshop->basket->add(intval($product_id), intval($quantity), $text, $product_detail_id); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Change the quantity of one product in basket |
254
|
|
|
* |
255
|
|
|
* @param struct $credentials Credentials to use the server |
256
|
|
|
* @param integer $product_id Product id to change |
257
|
|
|
* @param integer $quantity New quantity |
258
|
|
|
* @param string $text Extra text to the itemline |
259
|
|
|
* @param integer $product_detail_id Product detail id |
260
|
|
|
* |
261
|
|
|
* @return mixed |
262
|
|
|
*/ |
263
|
|
|
public function changeProductInBasket($credentials, $product_id, $quantity, $text = '', $product_detail_id = 0) |
264
|
|
|
{ |
265
|
|
|
$this->checkCredentials($credentials); |
266
|
|
|
|
267
|
|
|
$this->_factoryWebshop(); |
268
|
|
|
|
269
|
|
|
$product_id = intval($product_id); |
270
|
|
|
$quantity = intval($quantity); |
271
|
|
|
|
272
|
|
|
if (!is_numeric($product_id) and !is_numeric($quantity)) { |
|
|
|
|
273
|
|
|
require_once 'XML/RPC2/Exception.php'; |
274
|
|
|
throw new XML_RPC2_FaultException('product id and quantity must be integers', -5); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
$text = $this->utf8Decode($text); |
278
|
|
|
if (!$this->webshop->basket->change($product_id, $quantity, $text, $product_detail_id)) { |
279
|
|
|
return false; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
return true; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* Gets an array with the current basket |
287
|
|
|
* |
288
|
|
|
* @param struct $credentials Credentials to use the server |
289
|
|
|
* @param struct $customer customer values |
290
|
|
|
* |
291
|
|
|
* @return array |
292
|
|
|
*/ |
293
|
|
|
public function getBasket($credentials, $customer = array()) |
294
|
|
|
{ |
295
|
|
|
$this->checkCredentials($credentials); |
296
|
|
|
|
297
|
|
|
$this->_factoryWebshop(); |
298
|
|
|
|
299
|
|
|
// we put the possibility for BasketEvaluation not to be run. |
300
|
|
|
if (is_string($customer) && $customer == 'no_evaluation') { |
|
|
|
|
301
|
|
|
// nothing happens |
302
|
|
|
} elseif (is_array($customer)) { |
303
|
|
|
require_once 'Intraface/modules/webshop/BasketEvaluation.php'; |
304
|
|
|
$basketevaluation = new BasketEvaluation($this->webshop->kernel); |
305
|
|
|
if (!$basketevaluation->run($this->webshop->basket, $customer)) { |
|
|
|
|
306
|
|
|
// We should see to return the result in some way. |
307
|
|
|
} |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
return array( |
311
|
|
|
'items' => $this->webshop->basket->getItems(), |
312
|
|
|
'price_total' => $this->webshop->basket->getTotalPrice(), |
313
|
|
|
'weight' => $this->webshop->basket->getTotalWeight() |
314
|
|
|
); |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* Places an order in Intraface based on the current basket |
319
|
|
|
* |
320
|
|
|
* <code> |
321
|
|
|
* |
322
|
|
|
* </code> |
323
|
|
|
* |
324
|
|
|
* @param struct $credentials Credentials to use the server |
325
|
|
|
* @param struct $values Values to save |
326
|
|
|
* |
327
|
|
|
* @return integer $order_id |
328
|
|
|
*/ |
329
|
|
|
public function placeOrder($credentials, $values) |
330
|
|
|
{ |
331
|
|
|
$this->checkCredentials($credentials); |
332
|
|
|
|
333
|
|
|
$this->_factoryWebshop(); |
334
|
|
|
|
335
|
|
|
if (!is_array($this->webshop->basket->getItems()) or count($this->webshop->basket->getItems()) <= 0) { |
|
|
|
|
336
|
|
|
require_once 'XML/RPC2/Exception.php'; |
337
|
|
|
throw new XML_RPC2_FaultException('order could not be sent - cart is empty', -4); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
if (empty($values['description'])) { |
341
|
|
|
$values['description'] = 'Onlineshop'; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
$values = $this->utf8Decode($values); |
345
|
|
|
|
346
|
|
|
if (!$order_id = $this->webshop->placeOrder($values)) { |
347
|
|
|
require_once 'XML/RPC2/Exception.php'; |
348
|
|
|
throw new XML_RPC2_FaultException('order could not be placed. It returned the following error: ' . strtolower(implode(', ', $this->webshop->error->getMessage())), -4); |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
return $order_id; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* Saves details for a processed onlineoayment |
357
|
|
|
* |
358
|
|
|
* |
359
|
|
|
* @param struct $credentials Credentials to use the server |
360
|
|
|
* @param struct $values Values to save |
361
|
|
|
* |
362
|
|
|
* @return integer $payment_id |
363
|
|
|
*/ |
364
|
|
|
public function saveOnlinePayment($credentials, $values) |
365
|
|
|
{ |
366
|
|
|
$this->checkCredentials($credentials); |
367
|
|
|
|
368
|
|
|
$this->_factoryWebshop(); |
369
|
|
|
|
370
|
|
|
if (!$this->kernel->intranet->hasModuleAccess('onlinepayment')) { |
|
|
|
|
371
|
|
|
require_once 'XML/RPC2/Exception.php'; |
372
|
|
|
throw new XML_RPC2_FaultException('The intranet did not have access to OnlinePayment', -4); |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
$this->kernel->useModule('onlinepayment', true); // true: ignores user access; |
376
|
|
|
|
377
|
|
|
if (isset($values['payment_id']) && intval($values['payment_id']) > 0) { |
378
|
|
|
$onlinepayment = OnlinePayment::factory($this->kernel, 'id', intval($values['payment_id'])); |
379
|
|
|
} else { |
380
|
|
|
$onlinepayment = OnlinePayment::factory($this->kernel); |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
if (!$payment_id = $onlinepayment->save($values)) { |
|
|
|
|
384
|
|
|
require_once 'XML/RPC2/Exception.php'; |
385
|
|
|
throw new XML_RPC2_FaultException('Onlinebetaling kunne ikke blive gemt' . strtolower(implode(', ', $onlinepayment->error->getMessage())), -4); |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
return $payment_id; |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* Returns an onlinepayment id to be processed to the id can be used in payment |
394
|
|
|
* |
395
|
|
|
* @param struct $credentials Credentials to use the server |
396
|
|
|
* |
397
|
|
|
* @return integer $payment_id |
398
|
|
|
*/ |
399
|
|
|
public function createOnlinePayment($credentials) |
400
|
|
|
{ |
401
|
|
|
$this->checkCredentials($credentials); |
402
|
|
|
|
403
|
|
|
$this->_factoryWebshop(); |
404
|
|
|
|
405
|
|
|
if (!$this->kernel->intranet->hasModuleAccess('onlinepayment')) { |
|
|
|
|
406
|
|
|
require_once 'XML/RPC2/Exception.php'; |
407
|
|
|
throw new XML_RPC2_FaultException('The intranet did not have access to OnlinePayment', -4); |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
$this->kernel->useModule('onlinepayment', true); // true: ignores user access; |
411
|
|
|
|
412
|
|
|
$onlinepayment = OnlinePayment::factory($this->kernel); |
413
|
|
|
|
414
|
|
|
if (!$payment_id = $onlinepayment->create()) { |
415
|
|
|
require_once 'XML/RPC2/Exception.php'; |
416
|
|
|
throw new XML_RPC2_FaultException('onlinepayment could not be created' . strtolower(implode(', ', $onlinepayment->error->getMessage())), -4); |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
return $payment_id; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* Saves buyer details |
424
|
|
|
* |
425
|
|
|
* @param struct $credentials Credentials to use the server |
426
|
|
|
* @param struct $values Values to save |
427
|
|
|
* |
428
|
|
|
* @return boolean true or false |
429
|
|
|
*/ |
430
|
|
View Code Duplication |
public function saveAddress($credentials, $values) |
|
|
|
|
431
|
|
|
{ |
432
|
|
|
$this->checkCredentials($credentials); |
433
|
|
|
|
434
|
|
|
$this->_factoryWebshop(); |
435
|
|
|
|
436
|
|
|
if (!is_array($values)) { |
437
|
|
|
require_once 'XML/RPC2/Exception.php'; |
438
|
|
|
throw new XML_RPC2_FaultException('details could not be saved - nothing to save', -4); |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
$values = $this->utf8Decode($values); |
442
|
|
|
|
443
|
|
|
if (!$this->webshop->basket->saveAddress($values)) { |
444
|
|
|
require_once 'XML/RPC2/Exception.php'; |
445
|
|
|
throw new XML_RPC2_FaultException('datails could not be saved ' . strtolower(implode(', ', $this->webshop->error->getMessage())), -4); |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
return true; |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
/** |
452
|
|
|
* Get buyer details |
453
|
|
|
* |
454
|
|
|
* @param struct $credentials Credentials to use the server |
455
|
|
|
* |
456
|
|
|
* @return array |
457
|
|
|
*/ |
458
|
|
|
public function getAddress($credentials) |
459
|
|
|
{ |
460
|
|
|
$this->checkCredentials($credentials); |
461
|
|
|
|
462
|
|
|
$this->_factoryWebshop(); |
463
|
|
|
|
464
|
|
|
return $this->webshop->basket->getAddress(); |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
/** |
468
|
|
|
* Saves customer coupon |
469
|
|
|
* |
470
|
|
|
* @param struct $credentials Credentials to use the server |
471
|
|
|
* @param string $customer_coupon Customer coupon to save |
472
|
|
|
* |
473
|
|
|
* @return boolean true or false |
474
|
|
|
*/ |
475
|
|
View Code Duplication |
public function saveCustomerCoupon($credentials, $customer_coupon) |
|
|
|
|
476
|
|
|
{ |
477
|
|
|
$this->checkCredentials($credentials); |
478
|
|
|
|
479
|
|
|
$this->_factoryWebshop(); |
480
|
|
|
|
481
|
|
|
$customer_coupon = $this->utf8Decode($customer_coupon); |
482
|
|
|
if (!$this->webshop->basket->saveCustomerCoupon($customer_coupon)) { |
483
|
|
|
require_once 'XML/RPC2/Exception.php'; |
484
|
|
|
throw new XML_RPC2_FaultException('datails could not be saved ' . strtolower(implode(', ', $this->webshop->error->getMessage())), -4); |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
return true; |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
|
491
|
|
|
/** |
492
|
|
|
* Get customer coupon |
493
|
|
|
* |
494
|
|
|
* @param struct $credentials Credentials to use the server |
495
|
|
|
* |
496
|
|
|
* @return array |
497
|
|
|
*/ |
498
|
|
|
public function getCustomerCoupon($credentials) |
499
|
|
|
{ |
500
|
|
|
$this->checkCredentials($credentials); |
501
|
|
|
|
502
|
|
|
$this->_factoryWebshop(); |
503
|
|
|
|
504
|
|
|
return $this->webshop->basket->getCustomerCoupon(); |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
/** |
508
|
|
|
* Saves customer EAN location number |
509
|
|
|
* |
510
|
|
|
* @param struct $credentials Credentials to use the server |
511
|
|
|
* @param string $customer_ean Customer EAN to save |
512
|
|
|
* |
513
|
|
|
* @return boolean true or false |
514
|
|
|
*/ |
515
|
|
View Code Duplication |
public function saveCustomerEan($credentials, $customer_ean) |
|
|
|
|
516
|
|
|
{ |
517
|
|
|
$this->checkCredentials($credentials); |
518
|
|
|
|
519
|
|
|
$this->_factoryWebshop(); |
520
|
|
|
|
521
|
|
|
$customer_ean = $this->utf8Decode($customer_ean); |
522
|
|
|
if (!$this->webshop->basket->saveCustomerEan($customer_ean)) { |
523
|
|
|
require_once 'XML/RPC2/Exception.php'; |
524
|
|
|
throw new XML_RPC2_FaultException('ean could not be saved ' . strtolower(implode(', ', $this->webshop->error->getMessage())), -4); |
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
return true; |
528
|
|
|
} |
529
|
|
|
|
530
|
|
|
|
531
|
|
|
/** |
532
|
|
|
* Get customer EAN location number |
533
|
|
|
* |
534
|
|
|
* @param struct $credentials Credentials to use the server |
535
|
|
|
* |
536
|
|
|
* @return array |
537
|
|
|
*/ |
538
|
|
|
public function getCustomerEan($credentials) |
539
|
|
|
{ |
540
|
|
|
$this->checkCredentials($credentials); |
541
|
|
|
|
542
|
|
|
$this->_factoryWebshop(); |
543
|
|
|
|
544
|
|
|
return $this->webshop->basket->getCustomerEan(); |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
/** |
548
|
|
|
* Saves customer comment |
549
|
|
|
* |
550
|
|
|
* @param struct $credentials Credentials to use the server |
551
|
|
|
* @param string $customer_comment Customer coupon to save |
552
|
|
|
* |
553
|
|
|
* @return boolean true or false |
554
|
|
|
*/ |
555
|
|
View Code Duplication |
public function saveCustomerComment($credentials, $customer_comment) |
|
|
|
|
556
|
|
|
{ |
557
|
|
|
$this->checkCredentials($credentials); |
558
|
|
|
|
559
|
|
|
$this->_factoryWebshop(); |
560
|
|
|
|
561
|
|
|
$customer_comment = $this->utf8Decode($customer_comment); |
562
|
|
|
if (!$this->webshop->basket->saveCustomerComment($customer_comment)) { |
563
|
|
|
require_once 'XML/RPC2/Exception.php'; |
564
|
|
|
throw new XML_RPC2_FaultException('datails could not be saved ' . strtolower(implode(', ', $this->webshop->error->getMessage())), -4); |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
return true; |
568
|
|
|
} |
569
|
|
|
|
570
|
|
|
|
571
|
|
|
/** |
572
|
|
|
* Get customer comment |
573
|
|
|
* |
574
|
|
|
* @param struct $credentials Credentials to use the server |
575
|
|
|
* |
576
|
|
|
* @return array |
577
|
|
|
*/ |
578
|
|
|
public function getCustomerComment($credentials) |
579
|
|
|
{ |
580
|
|
|
$this->checkCredentials($credentials); |
581
|
|
|
|
582
|
|
|
$this->_factoryWebshop(); |
583
|
|
|
|
584
|
|
|
return $this->webshop->basket->getCustomerComment(); |
585
|
|
|
} |
586
|
|
|
|
587
|
|
|
/** |
588
|
|
|
* Get receipt text |
589
|
|
|
* |
590
|
|
|
* @param struct $credentials Credentials to use the server |
591
|
|
|
* |
592
|
|
|
* @return array |
593
|
|
|
*/ |
594
|
|
|
public function getReceiptText($credentials) |
595
|
|
|
{ |
596
|
|
|
$this->checkCredentials($credentials); |
597
|
|
|
|
598
|
|
|
$this->_factoryWebshop(); |
599
|
|
|
|
600
|
|
|
return $this->webshop->getReceiptText(); |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
/** |
604
|
|
|
* Checks credentials |
605
|
|
|
* |
606
|
|
|
* @param struct $credentials Credentials to use the server |
607
|
|
|
* |
608
|
|
|
* @return array |
609
|
|
|
*/ |
610
|
|
|
private function checkCredentials($credentials) |
611
|
|
|
{ |
612
|
|
|
$this->credentials = $credentials; |
613
|
|
|
|
614
|
|
|
if (count($credentials) != 2) { // -4 |
615
|
|
|
require_once 'XML/RPC2/Exception.php'; |
616
|
|
|
throw new XML_RPC2_FaultException('wrong argument count in $credentials - got ' . count($credentials) . ' arguments - need 2', -4); |
617
|
|
|
} |
618
|
|
|
if (empty($credentials['private_key'])) { // -5 |
619
|
|
|
require_once 'XML/RPC2/Exception.php'; |
620
|
|
|
throw new XML_RPC2_FaultException('supply a private_key', -5); |
621
|
|
|
} |
622
|
|
|
if (empty($credentials['session_id'])) { // -5 |
623
|
|
|
require_once 'XML/RPC2/Exception.php'; |
624
|
|
|
throw new XML_RPC2_FaultException('supply a session_id', -5); |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
$auth_adapter = new Intraface_Auth_PrivateKeyLogin(MDB2::singleton(DB_DSN), $credentials['session_id'], $credentials['private_key']); |
628
|
|
|
$weblogin = $auth_adapter->auth(); |
629
|
|
|
|
630
|
|
|
if (!$weblogin) { |
631
|
|
|
require_once 'XML/RPC2/Exception.php'; |
632
|
|
|
throw new XML_RPC2_FaultException('access to intranet denied', -2); |
633
|
|
|
} |
634
|
|
|
|
635
|
|
|
$this->kernel = new Intraface_Kernel($credentials['session_id']); |
636
|
|
|
$this->kernel->weblogin = $weblogin; |
|
|
|
|
637
|
|
|
$this->kernel->intranet = new Intraface_Intranet($weblogin->getActiveIntranetId()); |
638
|
|
|
$this->kernel->setting = new Intraface_Setting($this->kernel->intranet->get('id')); |
639
|
|
|
|
640
|
|
|
return true; |
641
|
|
|
} |
642
|
|
|
|
643
|
|
|
/** |
644
|
|
|
* Initialize the webshop |
645
|
|
|
* |
646
|
|
|
* @return void |
647
|
|
|
*/ |
648
|
|
|
private function _factoryWebshop() |
649
|
|
|
{ |
650
|
|
|
if (!$this->kernel->intranet->hasModuleAccess('webshop')) { |
|
|
|
|
651
|
|
|
require_once 'XML/RPC2/Exception.php'; |
652
|
|
|
throw new XML_RPC2_FaultException('The intranet does not have access to the module webshop', -2); |
653
|
|
|
} |
654
|
|
|
$this->kernel->module('webshop'); |
655
|
|
|
|
656
|
|
|
$this->webshop = new Webshop($this->kernel, $this->credentials['session_id']); |
657
|
|
|
} |
658
|
|
|
|
659
|
|
|
private function utf8Decode($values) |
660
|
|
|
{ |
661
|
|
|
if (is_array($values)) { |
662
|
|
|
return array_map('utf8_decode', $values); |
663
|
|
|
} elseif (is_string($values)) { |
664
|
|
|
return utf8_decode($values); |
665
|
|
|
} else { |
666
|
|
|
return $values; |
667
|
|
|
} |
668
|
|
|
} |
669
|
|
|
} |
670
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.