Tutorial Extension  1.0.0
SellerDeck Extensions - Tutorial Extension
CSDApiSoapJobs.php
1 <?php
2 
3 /**
4  * CSDApiSoapJobs.php - Implementation file for SellerDeck SOAP API Jobs class.
5  *
6  * @package SellerDeck Extensions
7  *
8  * @author Péter Erdődi
9  * @copyright © SellerDeck Ltd 2015. All rights reserved.
10  */
11 
12 namespace SDExtension;
13 
15  {
16 
17  /**
18  * @var SyncService Sync Service Object
19  */
20  private $m_oSyncService;
21 
22  /**
23  * @var string $m_sApiKey API Key
24  */
25  private $m_sApiKey;
26 
27  /**
28  * __construct - Object constructor method
29  *
30  * Initializes the member variables
31  *
32  * @access public
33  * @param SyncService $oSyncService Sync Service Object
34  * @return void
35  */
36  public function __construct($oSyncService = null, $sApiKey = "")
37  {
38  $this->m_sApiKey = $sApiKey;
39  $this->m_oSyncService = new CSDApiSoapClient($oSyncService, true);
40  }
41 
42  /**
43  * CommonCommand - Common part of API calls
44  *
45  * @access public
46  * @param string $sApi API
47  * @param string $sType Type
48  * @param string $sApiKey API Key
49  * @param array $aParameters Parameters
50  * @param string $sMode Mode: single/all
51  * @return string XML
52  */
53  public function CommonCommand($sApi, $sType, $aParameters = [], $sMode = '')
54  {
55  $aRequest = [
56  'api' => $sApi,
57  'apikey' => $this->m_sApiKey,
58  'command' =>
59  [
60  'type' => $sType,
61  ],
62  ];
63  if (!empty($sMode))
64  {
65  $aRequest['command']['mode'] = $sMode;
66  }
67  if (!empty($aParameters))
68  {
69  $aRequest['command']['parameters'] = $aParameters;
70  }
71  $sXML = Helper\Array2XML::createXML('request', $aRequest, ['version' => "1"])->saveXML();
72  \SDExtension\Helper\CLogger::get(LOG_CHANNEL_NAME)->addDebug($sXML);
73  $oReturnValue = $this->m_oSyncService->InvokeApi($sXML);
74  $aXML = Helper\XML2Array::createArray($oReturnValue);
75  \SDExtension\Helper\CLogger::get(LOG_CHANNEL_NAME)->addDebug(print_r($oReturnValue, true));
76  return $aXML;
77  }
78 
79  /**
80  * ConfigurationReload - Configuration Reload API call
81  *
82  * @access public
83  * @return string XML
84  */
85  public function ConfigurationReload()
86  {
87  return $this->CommonCommand('sdd', 'sdereloadconfig');
88  }
89 
90  /**
91  * BulkStockUpdate - Bulk Stock Update
92  *
93  * @access public
94  * @param array $aProducts Product list
95  * @return string XML
96  */
97  public function BulkStockUpdate($aProducts = [])
98  {
99  $aParameters = [];
100  foreach ($aProducts as $aProduct)
101  {
102  $aParameters['product'][] = [
103  'mode' => 'relative',
104  'prodref' => $aProduct['sProductReference'],
105  'stocktoupdate' => $aProduct['nQuantityOrdered'],
106  ];
107  if (!empty($aProduct['sPermutation']))
108  {
109  $aParameters['product'][] = [
110  'mode' => 'relative',
111  'prodref' => $aProduct['sPermutation'],
112  'stocktoupdate' => $aProduct['nQuantityOrdered'],
113  ];
114  }
115  }
116  return $this->CommonCommand('stock', 'update', $aParameters);
117  }
118 
119  /**
120  * BulkRefreshOrders - Bulk Refresh Orders
121  *
122  * @access public
123  * @param array $aOrders Order list
124  * @return string XML
125  */
126  public function BulkRefreshOrders($aOrders = [])
127  {
128  $aParameters = [];
129  foreach ($aOrders as $sOrderNumber)
130  {
131  $aParameters['order'][] = ['reference' => $sOrderNumber];
132  }
133  return $this->CommonCommand('order', 'display', $aParameters);
134  }
135 
136  /**
137  * CommonLockAndUnlock - Common part of Lock and Unlock API calls
138  *
139  * @access public
140  * @param string $sReference Product Reference
141  * @param array|string $vItemOrGroup Item definition
142  * @param string $sLockOrUnlock Action: 'lock' or 'unlock'
143  * @return string XML
144  */
145  public function CommonLockAndUnlock($sReference, $vItemOrGroup, $sLockOrUnlock = "lock")
146  {
147  if (is_array($vItemOrGroup))
148  {
149  $aParameters = ['item' => $vItemOrGroup];
150  $sReference = arr_get($vItemOrGroup, 'reference', $sReference);
151  }
152  else
153  {
154  $aParameters['item']['group'] = $vItemOrGroup;
155  }
156  if ("unlock" == $sLockOrUnlock)
157  {
158  $aParameters['item']['editaction'] = 'claimed';
159  }
160  $aParameters['item']['reference'] = $sReference;
161  return $this->CommonCommand('sync', $sLockOrUnlock, $aParameters, 'single');
162  }
163 
164  /**
165  * ProductLockAndUnlock - Common part of Lock and Unlock API calls
166  *
167  * @access public
168  * @param string $sProductReference Product Reference
169  * @param string $sLockOrUnlock Action: 'lock' or 'unlock'
170  * @return string XML
171  */
172  public function ProductLockAndUnlock($sProductReference, $sLockOrUnlock = "lock")
173  {
174  $aItem = [
175  'group' => 'content',
176  'content' => 'product',
177  ];
178  return $this->CommonLockAndUnlock($sProductReference, $aItem, $sLockOrUnlock);
179  }
180 
181  /**
182  * CommonOrderLockAndUnlock - Common part of Lock and Unlock API calls
183  *
184  * @access private
185  * @param string $sOrderNumber Order Number
186  * @param string $sLockOrUnlock Action: 'lock' or 'unlock'
187  * @return string XML
188  */
189  private function CommonOrderLockAndUnlock($sOrderNumber, $sLockOrUnlock = "lock")
190  {
191  return $this->CommonLockAndUnlock($sOrderNumber, 'order', $sLockOrUnlock);
192  }
193 
194  /**
195  * Lock - Locking an item in EC
196  *
197  * @access public
198  * @param string $sOrderNumber Order Number
199  * @return string XML
200  */
201  public function Lock($sOrderNumber)
202  {
203  return $this->CommonOrderLockAndUnlock($sOrderNumber, "lock");
204  }
205 
206  /**
207  * Unlock - Unlocking an item in EC
208  *
209  * @access public
210  * @param string $sOrderNumber Order Number
211  * @return string XML
212  */
213  public function Unlock($sOrderNumber)
214  {
215  return $this->CommonOrderLockAndUnlock($sOrderNumber, "unlock");
216  }
217 
218  }
static get($sChannel="default", $sLogRoot="")
Definition: CLogger.php:90
ProductLockAndUnlock($sProductReference, $sLockOrUnlock="lock")
CommonCommand($sApi, $sType, $aParameters=[], $sMode= '')
BulkStockUpdate($aProducts=[])
CommonLockAndUnlock($sReference, $vItemOrGroup, $sLockOrUnlock="lock")
__construct($oSyncService=null, $sApiKey="")