1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\MagentoBundle\Provider\Transport; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
6
|
|
|
|
7
|
|
|
use Oro\Bundle\IntegrationBundle\Entity\Transport; |
8
|
|
|
use Oro\Bundle\IntegrationBundle\Provider\SOAPTransport as BaseSOAPTransport; |
9
|
|
|
use Oro\Bundle\IntegrationBundle\Utils\ConverterUtils; |
10
|
|
|
use Oro\Bundle\SecurityBundle\Encoder\Mcrypt; |
11
|
|
|
|
12
|
|
|
use OroCRM\Bundle\MagentoBundle\Entity\MagentoSoapTransport; |
13
|
|
|
use OroCRM\Bundle\MagentoBundle\Exception\ExtensionRequiredException; |
14
|
|
|
use OroCRM\Bundle\MagentoBundle\Provider\Iterator\CartsBridgeIterator; |
15
|
|
|
use OroCRM\Bundle\MagentoBundle\Provider\Iterator\CustomerBridgeIterator; |
16
|
|
|
use OroCRM\Bundle\MagentoBundle\Provider\Iterator\CustomerGroupSoapIterator; |
17
|
|
|
use OroCRM\Bundle\MagentoBundle\Provider\Iterator\CustomerSoapIterator; |
18
|
|
|
use OroCRM\Bundle\MagentoBundle\Provider\Iterator\NewsletterSubscriberBridgeIterator; |
19
|
|
|
use OroCRM\Bundle\MagentoBundle\Provider\Iterator\OrderBridgeIterator; |
20
|
|
|
use OroCRM\Bundle\MagentoBundle\Provider\Iterator\OrderSoapIterator; |
21
|
|
|
use OroCRM\Bundle\MagentoBundle\Provider\Iterator\RegionSoapIterator; |
22
|
|
|
use OroCRM\Bundle\MagentoBundle\Provider\Iterator\StoresSoapIterator; |
23
|
|
|
use OroCRM\Bundle\MagentoBundle\Provider\Iterator\WebsiteSoapIterator; |
24
|
|
|
use OroCRM\Bundle\MagentoBundle\Service\WsdlManager; |
25
|
|
|
use OroCRM\Bundle\MagentoBundle\Utils\WSIUtils; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Magento SOAP transport |
29
|
|
|
* used to fetch and pull data to/from Magento instance |
30
|
|
|
* with sessionId param using SOAP requests |
31
|
|
|
* |
32
|
|
|
* @package OroCRM\Bundle\MagentoBundle |
33
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity) |
34
|
|
|
*/ |
35
|
|
|
class SoapTransport extends BaseSOAPTransport implements MagentoTransportInterface, ServerTimeAwareInterface |
36
|
|
|
{ |
37
|
|
|
const REQUIRED_EXTENSION_VERSION = '1.2.0'; |
38
|
|
|
|
39
|
|
|
const ACTION_CUSTOMER_LIST = 'customerCustomerList'; |
40
|
|
|
const ACTION_CUSTOMER_INFO = 'customerCustomerInfo'; |
41
|
|
|
const ACTION_CUSTOMER_UPDATE = 'customerCustomerUpdate'; |
42
|
|
|
const ACTION_CUSTOMER_DELETE = 'customerCustomerDelete'; |
43
|
|
|
const ACTION_CUSTOMER_CREATE = 'customerCustomerCreate'; |
44
|
|
|
const ACTION_CUSTOMER_ADDRESS_LIST = 'customerAddressList'; |
45
|
|
|
const ACTION_CUSTOMER_ADDRESS_INFO = 'customerAddressInfo'; |
46
|
|
|
const ACTION_CUSTOMER_ADDRESS_UPDATE = 'customerAddressUpdate'; |
47
|
|
|
const ACTION_CUSTOMER_ADDRESS_DELETE = 'customerAddressDelete'; |
48
|
|
|
const ACTION_CUSTOMER_ADDRESS_CREATE = 'customerAddressCreate'; |
49
|
|
|
const ACTION_ADDRESS_LIST = 'customerAddressList'; |
50
|
|
|
const ACTION_GROUP_LIST = 'customerGroupList'; |
51
|
|
|
const ACTION_STORE_LIST = 'storeList'; |
52
|
|
|
const ACTION_ORDER_LIST = 'salesOrderList'; |
53
|
|
|
const ACTION_ORDER_INFO = 'salesOrderInfo'; |
54
|
|
|
const ACTION_CART_INFO = 'shoppingCartInfo'; |
55
|
|
|
const ACTION_COUNTRY_LIST = 'directoryCountryList'; |
56
|
|
|
const ACTION_REGION_LIST = 'directoryRegionList'; |
57
|
|
|
const ACTION_PING = 'oroPing'; |
58
|
|
|
|
59
|
|
|
const ACTION_ORO_CART_LIST = 'oroQuoteList'; |
60
|
|
|
const ACTION_ORO_ORDER_LIST = 'oroOrderList'; |
61
|
|
|
const ACTION_ORO_ORDER_INFO = 'oroOrderInfo'; |
62
|
|
|
const ACTION_ORO_CUSTOMER_LIST = 'oroCustomerList'; |
63
|
|
|
const ACTION_ORO_CUSTOMER_INFO = 'oroCustomerInfo'; |
64
|
|
|
const ACTION_ORO_CUSTOMER_ADDRESS_LIST = 'oroCustomerAddressList'; |
65
|
|
|
const ACTION_ORO_CUSTOMER_ADDRESS_INFO = 'oroCustomerAddressInfo'; |
66
|
|
|
const ACTION_ORO_CUSTOMER_CREATE = 'oroCustomerCreate'; |
67
|
|
|
const ACTION_ORO_CUSTOMER_UPDATE = 'oroCustomerUpdate'; |
68
|
|
|
const ACTION_ORO_NEWSLETTER_SUBSCRIBER_LIST = 'newsletterSubscriberList'; |
69
|
|
|
const ACTION_ORO_NEWSLETTER_SUBSCRIBER_CREATE = 'newsletterSubscriberCreate'; |
70
|
|
|
const ACTION_ORO_NEWSLETTER_SUBSCRIBER_UPDATE = 'newsletterSubscriberUpdate'; |
71
|
|
|
const ACTION_ORO_WEBSITE_LIST = 'oroWebsiteList'; |
72
|
|
|
|
73
|
|
|
const SOAP_FAULT_ADDRESS_DOES_NOT_EXIST = 102; |
74
|
|
|
|
75
|
|
|
/** @var string */ |
76
|
|
|
protected $sessionId; |
77
|
|
|
|
78
|
|
|
/** @var Mcrypt */ |
79
|
|
|
protected $encoder; |
80
|
|
|
|
81
|
|
|
/** @var bool */ |
82
|
|
|
protected $isExtensionInstalled; |
83
|
|
|
|
84
|
|
|
/** @var string */ |
85
|
|
|
protected $magentoVersion; |
86
|
|
|
|
87
|
|
|
/** @var string */ |
88
|
|
|
protected $extensionVersion; |
89
|
|
|
|
90
|
|
|
/** @var bool */ |
91
|
|
|
protected $isWsiMode = false; |
92
|
|
|
|
93
|
|
|
/** @var string */ |
94
|
|
|
protected $adminUrl; |
95
|
|
|
|
96
|
|
|
/** @var string */ |
97
|
|
|
protected $serverTime; |
98
|
|
|
|
99
|
|
|
/** @var array */ |
100
|
|
|
protected $dependencies = []; |
101
|
|
|
|
102
|
|
|
/** @var WsdlManager */ |
103
|
|
|
protected $wsdlManager; |
104
|
|
|
|
105
|
|
|
/** @var array */ |
106
|
|
|
protected $auth = []; |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @var array |
110
|
|
|
*/ |
111
|
|
|
protected $bundleConfig; |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param Mcrypt $encoder |
115
|
|
|
* @param WsdlManager $wsdlManager |
116
|
|
|
* @param array $bundleConfig |
117
|
|
|
*/ |
118
|
|
|
public function __construct(Mcrypt $encoder, WsdlManager $wsdlManager, array $bundleConfig = []) |
119
|
|
|
{ |
120
|
|
|
$this->encoder = $encoder; |
121
|
|
|
$this->wsdlManager = $wsdlManager; |
122
|
|
|
$this->bundleConfig = $bundleConfig; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* {@inheritdoc} |
127
|
|
|
*/ |
128
|
|
|
public function init(Transport $transportEntity) |
129
|
|
|
{ |
130
|
|
|
/** |
131
|
|
|
* Cache WSDL and force transport entity to use it instead of original URL. |
132
|
|
|
* This should be done before parent::init as settings will be cached there. |
133
|
|
|
*/ |
134
|
|
|
if ($transportEntity instanceof MagentoSoapTransport) { |
135
|
|
|
$wsdlUrl = $transportEntity->getWsdlUrl(); |
136
|
|
|
|
137
|
|
|
// Save auth information to be able to perform requests. |
138
|
|
|
$urlParts = parse_url($wsdlUrl); |
139
|
|
|
if (isset($urlParts['user'], $urlParts['pass'])) { |
140
|
|
|
$this->auth['login'] = $urlParts['user']; |
141
|
|
|
$this->auth['password'] = $urlParts['pass']; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
// Load WSDL to local cache. |
145
|
|
|
if (!$this->wsdlManager->isCacheLoaded($wsdlUrl)) { |
146
|
|
|
$this->wsdlManager->loadWsdl($wsdlUrl); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
// Set cached WSDL path to transport entity. |
150
|
|
|
$transportEntity->setWsdlCachePath($this->wsdlManager->getCachedWsdlPath($wsdlUrl)); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
parent::init($transportEntity); |
154
|
|
|
|
155
|
|
|
$wsiMode = $this->settings->get('wsi_mode', false); |
156
|
|
|
$apiUser = $this->settings->get('api_user', false); |
157
|
|
|
$apiKey = $this->settings->get('api_key', false); |
158
|
|
|
$apiKey = $this->encoder->decryptData($apiKey); |
159
|
|
|
|
160
|
|
|
if (!$apiUser || !$apiKey) { |
161
|
|
|
throw new InvalidConfigurationException( |
162
|
|
|
"Magento SOAP transport require 'api_key' and 'api_user' settings to be defined." |
163
|
|
|
); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
// revert initial state |
167
|
|
|
$this->isExtensionInstalled = null; |
168
|
|
|
$this->adminUrl = null; |
169
|
|
|
$this->isWsiMode = $wsiMode; |
170
|
|
|
|
171
|
|
|
/** @var string sessionId returned by Magento API login method */ |
172
|
|
|
$this->sessionId = null; |
173
|
|
|
$this->sessionId = $this->call('login', ['username' => $apiUser, 'apiKey' => $apiKey]); |
174
|
|
|
|
175
|
|
|
$this->checkExtensionFunctions(); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
protected function checkExtensionFunctions() |
179
|
|
|
{ |
180
|
|
|
$functions = (array)$this->client->__getFunctions(); |
181
|
|
|
|
182
|
|
|
$isExtensionInstalled = (bool)array_filter( |
183
|
|
|
$functions, |
184
|
|
|
function ($definition) { |
185
|
|
|
return false !== strpos($definition, self::ACTION_PING); |
186
|
|
|
} |
187
|
|
|
); |
188
|
|
|
|
189
|
|
|
if (!$isExtensionInstalled) { |
190
|
|
|
$this->isExtensionInstalled = false; |
191
|
|
|
$this->adminUrl = false; |
|
|
|
|
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Disable wsdl caching by PHP. |
197
|
|
|
* |
198
|
|
|
* {@inheritdoc} |
199
|
|
|
*/ |
200
|
|
|
protected function getSoapClient($wsdlUrl, array $options = []) |
201
|
|
|
{ |
202
|
|
|
$options['cache_wsdl'] = WSDL_CACHE_NONE; |
203
|
|
|
if (!isset($options['login'], $options['password'])) { |
204
|
|
|
$options = array_merge($options, $this->auth); |
205
|
|
|
} |
206
|
|
|
if (!empty($this->bundleConfig['sync_settings']['skip_ssl_verification'])) { |
207
|
|
|
$context = stream_context_create( |
208
|
|
|
[ |
209
|
|
|
'ssl' => [ |
210
|
|
|
'verify_peer' => false, |
211
|
|
|
'verify_peer_name' => false, |
212
|
|
|
'allow_self_signed' => true |
213
|
|
|
] |
214
|
|
|
] |
215
|
|
|
); |
216
|
|
|
|
217
|
|
|
$options['stream_context'] = $context; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
return parent::getSoapClient($wsdlUrl, $options); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* {@inheritdoc} |
225
|
|
|
*/ |
226
|
|
|
public function call($action, $params = []) |
227
|
|
|
{ |
228
|
|
|
if (null !== $this->sessionId) { |
229
|
|
|
$params = array_merge(['sessionId' => $this->sessionId], (array)$params); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
if ($this->logger) { |
233
|
|
|
$this->logger->debug( |
234
|
|
|
sprintf( |
235
|
|
|
'[%.1fMB/%.1fMB] Call %s action with %s parameters', |
236
|
|
|
memory_get_usage() / 1024 / 1024, |
237
|
|
|
memory_get_peak_usage() / 1024 / 1024, |
238
|
|
|
$action, |
239
|
|
|
json_encode($params) |
240
|
|
|
) |
241
|
|
|
); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
if ($this->isWsiMode) { |
245
|
|
|
$result = parent::call($action, [(object)$params]); |
246
|
|
|
$result = WSIUtils::parseWSIResponse($result); |
|
|
|
|
247
|
|
|
} else { |
248
|
|
|
$result = parent::call($action, $params); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
$this->lookUpForServerTime(); |
252
|
|
|
|
253
|
|
|
return $result; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* {@inheritdoc} |
258
|
|
|
*/ |
259
|
|
|
protected function makeNewAttempt($action, $params) |
260
|
|
|
{ |
261
|
|
|
$this->logAttempt(); |
262
|
|
|
sleep($this->getSleepBetweenAttempt()); |
263
|
|
|
++$this->attempted; |
264
|
|
|
|
265
|
|
|
// in case if we have WsiMode enabled we should convert object parameters to array to avoid |
266
|
|
|
// not correct parameters during the next attempt call |
267
|
|
|
return $this->call( |
268
|
|
|
$action, |
269
|
|
|
$this->isWsiMode ? (array)array_shift($params) : $params |
270
|
|
|
); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* {@inheritdoc} |
275
|
|
|
*/ |
276
|
|
|
public function isExtensionInstalled() |
277
|
|
|
{ |
278
|
|
|
if (null === $this->isExtensionInstalled) { |
279
|
|
|
$this->pingMagento(); |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
return $this->isExtensionInstalled; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* {@inheritdoc} |
287
|
|
|
*/ |
288
|
|
|
public function getMagentoVersion() |
289
|
|
|
{ |
290
|
|
|
if (null === $this->isExtensionInstalled) { |
291
|
|
|
$this->pingMagento(); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
return $this->magentoVersion; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* {@inheritdoc} |
299
|
|
|
*/ |
300
|
|
|
public function getExtensionVersion() |
301
|
|
|
{ |
302
|
|
|
if (null === $this->isExtensionInstalled) { |
303
|
|
|
$this->pingMagento(); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
return $this->extensionVersion; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* {@inheritdoc} |
311
|
|
|
*/ |
312
|
|
|
public function isSupportedExtensionVersion() |
313
|
|
|
{ |
314
|
|
|
return $this->isExtensionInstalled() |
315
|
|
|
&& version_compare($this->getExtensionVersion(), self::REQUIRED_EXTENSION_VERSION, 'ge'); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* Pings magento and fill data related to Bridge Extension. |
320
|
|
|
* |
321
|
|
|
* @return $this |
322
|
|
|
*/ |
323
|
|
|
protected function pingMagento() |
324
|
|
|
{ |
325
|
|
|
if (null === $this->isExtensionInstalled && null === $this->adminUrl) { |
326
|
|
|
try { |
327
|
|
|
$result = $this->call(self::ACTION_PING); |
328
|
|
|
$this->isExtensionInstalled = !empty($result->version); |
329
|
|
|
if ($this->isExtensionInstalled) { |
330
|
|
|
$this->extensionVersion = $result->version; |
331
|
|
|
} |
332
|
|
|
if (!empty($result->mage_version)) { |
333
|
|
|
$this->magentoVersion = $result->mage_version; |
334
|
|
|
} |
335
|
|
|
if (!empty($result->admin_url)) { |
336
|
|
|
$this->adminUrl = $result->admin_url; |
337
|
|
|
} else { |
338
|
|
|
$this->adminUrl = false; |
|
|
|
|
339
|
|
|
} |
340
|
|
|
} catch (\Exception $e) { |
341
|
|
|
$this->isExtensionInstalled |
342
|
|
|
= $this->adminUrl |
343
|
|
|
= false; |
344
|
|
|
} |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
return $this; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* {@inheritdoc} |
352
|
|
|
*/ |
353
|
|
|
public function getAdminUrl() |
354
|
|
|
{ |
355
|
|
|
if (null === $this->adminUrl) { |
356
|
|
|
$this->pingMagento(); |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
return $this->adminUrl; |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* {@inheritdoc} |
364
|
|
|
*/ |
365
|
|
|
public function getServerTime() |
366
|
|
|
{ |
367
|
|
|
return $this->serverTime; |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* {@inheritdoc} |
372
|
|
|
*/ |
373
|
|
|
public function getOrders() |
374
|
|
|
{ |
375
|
|
|
$settings = $this->settings->all(); |
376
|
|
|
|
377
|
|
|
if ($this->isExtensionInstalled()) { |
378
|
|
|
return new OrderBridgeIterator($this, $settings); |
379
|
|
|
} else { |
380
|
|
|
return new OrderSoapIterator($this, $settings); |
381
|
|
|
} |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* {@inheritdoc} |
386
|
|
|
*/ |
387
|
|
|
public function getOrderInfo($incrementId) |
388
|
|
|
{ |
389
|
|
|
if ($this->isSupportedExtensionVersion()) { |
390
|
|
|
$endpoint = self::ACTION_ORO_ORDER_INFO; |
391
|
|
|
} else { |
392
|
|
|
$endpoint = self::ACTION_ORDER_INFO; |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
return $this->call($endpoint, ['orderIncrementId' => $incrementId]); |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* {@inheritdoc} |
400
|
|
|
*/ |
401
|
|
|
public function getCarts() |
402
|
|
|
{ |
403
|
|
|
if ($this->isExtensionInstalled()) { |
404
|
|
|
return new CartsBridgeIterator($this, $this->settings->all()); |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
throw new ExtensionRequiredException(); |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* {@inheritdoc} |
412
|
|
|
*/ |
413
|
|
|
public function getCustomers() |
414
|
|
|
{ |
415
|
|
|
$settings = $this->settings->all(); |
416
|
|
|
|
417
|
|
|
if ($this->isExtensionInstalled()) { |
418
|
|
|
return new CustomerBridgeIterator($this, $settings); |
419
|
|
|
} else { |
420
|
|
|
return new CustomerSoapIterator($this, $settings); |
421
|
|
|
} |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
/** |
425
|
|
|
* {@inheritdoc} |
426
|
|
|
*/ |
427
|
|
|
public function getCustomerGroups() |
428
|
|
|
{ |
429
|
|
|
return new CustomerGroupSoapIterator($this); |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* {@inheritdoc} |
434
|
|
|
*/ |
435
|
|
|
public function getStores() |
436
|
|
|
{ |
437
|
|
|
return new StoresSoapIterator($this); |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
/** |
441
|
|
|
* {@inheritdoc} |
442
|
|
|
*/ |
443
|
|
|
public function getWebsites() |
444
|
|
|
{ |
445
|
|
|
return new WebsiteSoapIterator($this); |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
/** |
449
|
|
|
* {@inheritdoc} |
450
|
|
|
*/ |
451
|
|
|
public function getRegions() |
452
|
|
|
{ |
453
|
|
|
return new RegionSoapIterator($this, $this->settings->all()); |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
/** |
457
|
|
|
* {@inheritdoc} |
458
|
|
|
*/ |
459
|
|
|
public function getCustomerAddresses($originId) |
460
|
|
|
{ |
461
|
|
|
if ($this->isSupportedExtensionVersion()) { |
462
|
|
|
$endpoint = SoapTransport::ACTION_ORO_CUSTOMER_ADDRESS_LIST; |
463
|
|
|
} else { |
464
|
|
|
$endpoint = SoapTransport::ACTION_CUSTOMER_ADDRESS_LIST; |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
$addresses = $this->call($endpoint, ['customerId' => $originId]); |
468
|
|
|
$addresses = WSIUtils::processCollectionResponse($addresses); |
469
|
|
|
|
470
|
|
|
return ConverterUtils::objectToArray($addresses); |
|
|
|
|
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
/** |
474
|
|
|
* {@inheritdoc} |
475
|
|
|
*/ |
476
|
|
|
public function createCustomer(array $customerData) |
477
|
|
|
{ |
478
|
|
|
if ($this->isSupportedExtensionVersion()) { |
479
|
|
|
$createEndpoint = SoapTransport::ACTION_ORO_CUSTOMER_CREATE; |
480
|
|
|
} else { |
481
|
|
|
$createEndpoint = SoapTransport::ACTION_CUSTOMER_CREATE; |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
return $this->call($createEndpoint, ['customerData' => $customerData]); |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
/** |
488
|
|
|
* {@inheritdoc} |
489
|
|
|
*/ |
490
|
|
|
public function updateCustomer($customerId, array $customerData) |
491
|
|
|
{ |
492
|
|
|
if ($this->isSupportedExtensionVersion()) { |
493
|
|
|
$updateEndpoint = SoapTransport::ACTION_ORO_CUSTOMER_UPDATE; |
494
|
|
|
} else { |
495
|
|
|
$updateEndpoint = SoapTransport::ACTION_CUSTOMER_UPDATE; |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
return $this->call($updateEndpoint, ['customerId' => $customerId, 'customerData' => $customerData]); |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
/** |
502
|
|
|
* {@inheritdoc} |
503
|
|
|
*/ |
504
|
|
|
public function createCustomerAddress($customerId, array $item) |
505
|
|
|
{ |
506
|
|
|
return $this->call( |
507
|
|
|
SoapTransport::ACTION_CUSTOMER_ADDRESS_CREATE, |
508
|
|
|
['customerId' => $customerId, 'addressData' => $item] |
509
|
|
|
); |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
/** |
513
|
|
|
* {@inheritdoc} |
514
|
|
|
*/ |
515
|
|
|
public function updateCustomerAddress($customerAddressId, array $item) |
516
|
|
|
{ |
517
|
|
|
return $this->call( |
518
|
|
|
SoapTransport::ACTION_CUSTOMER_ADDRESS_UPDATE, |
519
|
|
|
['addressId' => $customerAddressId, 'addressData' => $item] |
520
|
|
|
); |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
/** |
524
|
|
|
* {@inheritdoc} |
525
|
|
|
*/ |
526
|
|
|
public function getCustomerAddressInfo($customerAddressId) |
527
|
|
|
{ |
528
|
|
|
if ($this->isSupportedExtensionVersion()) { |
529
|
|
|
$endpoint = SoapTransport::ACTION_ORO_CUSTOMER_ADDRESS_INFO; |
530
|
|
|
} else { |
531
|
|
|
$endpoint = SoapTransport::ACTION_CUSTOMER_ADDRESS_INFO; |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
return ConverterUtils::objectToArray($this->call($endpoint, ['addressId' => $customerAddressId])); |
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
/** |
538
|
|
|
* {@inheritdoc} |
539
|
|
|
*/ |
540
|
|
|
public function getCustomerInfo($originId) |
541
|
|
|
{ |
542
|
|
|
if ($this->isSupportedExtensionVersion()) { |
543
|
|
|
$endpoint = SoapTransport::ACTION_ORO_CUSTOMER_INFO; |
544
|
|
|
} else { |
545
|
|
|
$endpoint = SoapTransport::ACTION_CUSTOMER_INFO; |
546
|
|
|
} |
547
|
|
|
|
548
|
|
|
return ConverterUtils::objectToArray($this->call($endpoint, ['customerId' => $originId])); |
549
|
|
|
} |
550
|
|
|
|
551
|
|
|
/** |
552
|
|
|
* {@inheritdoc} |
553
|
|
|
*/ |
554
|
|
|
public function getNewsletterSubscribers() |
555
|
|
|
{ |
556
|
|
|
if ($this->isSupportedExtensionVersion()) { |
557
|
|
|
return new NewsletterSubscriberBridgeIterator($this, $this->settings->all()); |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
throw new ExtensionRequiredException(); |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
/** |
564
|
|
|
* {@inheritdoc} |
565
|
|
|
*/ |
566
|
|
View Code Duplication |
public function createNewsletterSubscriber(array $subscriberData) |
|
|
|
|
567
|
|
|
{ |
568
|
|
|
if ($this->isExtensionInstalled()) { |
569
|
|
|
$result = $this->call( |
570
|
|
|
SoapTransport::ACTION_ORO_NEWSLETTER_SUBSCRIBER_CREATE, |
571
|
|
|
['subscriberData' => $subscriberData] |
572
|
|
|
); |
573
|
|
|
|
574
|
|
|
return ConverterUtils::objectToArray($result); |
575
|
|
|
} |
576
|
|
|
|
577
|
|
|
throw new ExtensionRequiredException(); |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
/** |
581
|
|
|
* {@inheritdoc} |
582
|
|
|
*/ |
583
|
|
View Code Duplication |
public function updateNewsletterSubscriber($subscriberId, array $subscriberData) |
|
|
|
|
584
|
|
|
{ |
585
|
|
|
if ($this->isExtensionInstalled()) { |
586
|
|
|
$result = $this->call( |
587
|
|
|
SoapTransport::ACTION_ORO_NEWSLETTER_SUBSCRIBER_UPDATE, |
588
|
|
|
['subscriberId' => $subscriberId, 'subscriberData' => $subscriberData] |
589
|
|
|
); |
590
|
|
|
|
591
|
|
|
return ConverterUtils::objectToArray($result); |
592
|
|
|
} |
593
|
|
|
|
594
|
|
|
throw new ExtensionRequiredException(); |
595
|
|
|
} |
596
|
|
|
|
597
|
|
|
/** |
598
|
|
|
* {@inheritdoc} |
599
|
|
|
*/ |
600
|
|
|
public function getErrorCode(\Exception $e) |
601
|
|
|
{ |
602
|
|
|
if ($e instanceof \SoapFault) { |
603
|
|
|
switch ($e->faultcode) { |
|
|
|
|
604
|
|
|
case self::SOAP_FAULT_ADDRESS_DOES_NOT_EXIST: |
605
|
|
|
return self::TRANSPORT_ERROR_ADDRESS_DOES_NOT_EXIST; |
606
|
|
|
} |
607
|
|
|
} |
608
|
|
|
} |
609
|
|
|
|
610
|
|
|
/** |
611
|
|
|
* {@inheritdoc} |
612
|
|
|
*/ |
613
|
|
|
public function getLabel() |
614
|
|
|
{ |
615
|
|
|
return 'orocrm.magento.transport.soap.label'; |
616
|
|
|
} |
617
|
|
|
|
618
|
|
|
/** |
619
|
|
|
* {@inheritdoc} |
620
|
|
|
*/ |
621
|
|
|
public function getSettingsFormType() |
622
|
|
|
{ |
623
|
|
|
return 'orocrm_magento_soap_transport_setting_form_type'; |
624
|
|
|
} |
625
|
|
|
|
626
|
|
|
/** |
627
|
|
|
* {@inheritdoc} |
628
|
|
|
*/ |
629
|
|
|
public function getSettingsEntityFQCN() |
630
|
|
|
{ |
631
|
|
|
return 'OroCRM\\Bundle\\MagentoBundle\\Entity\\MagentoSoapTransport'; |
632
|
|
|
} |
633
|
|
|
|
634
|
|
|
/** |
635
|
|
|
* Tries to fetch date from response headers |
636
|
|
|
*/ |
637
|
|
|
protected function lookUpForServerTime() |
638
|
|
|
{ |
639
|
|
|
if (null === $this->serverTime) { |
640
|
|
|
$parsedResponse = $this->getLastResponseHeaders(); |
641
|
|
|
|
642
|
|
|
if (isset($parsedResponse['headers']['Date'])) { |
643
|
|
|
$this->serverTime = $parsedResponse['headers']['Date']; |
644
|
|
|
} else { |
645
|
|
|
$this->serverTime = false; |
|
|
|
|
646
|
|
|
} |
647
|
|
|
} |
648
|
|
|
} |
649
|
|
|
} |
650
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.