@@ -142,6 +142,11 @@ class ShopifySDK
142
142
*/
143
143
public static $ timeAllowedForEachApiCall = .5 ;
144
144
145
+ /**
146
+ * @var string Default Shopify API version
147
+ */
148
+ public static $ defaultApiVersion = '2022-07 ' ;
149
+
145
150
/**
146
151
* Shop / API configurations
147
152
*
@@ -223,8 +228,7 @@ class ShopifySDK
223
228
public function __construct ($ config = array ())
224
229
{
225
230
if (!empty ($ config )) {
226
- $ this ->config = $ config ;
227
- $ this ->setAdminUrl ();
231
+ ShopifySDK::config ($ config );
228
232
}
229
233
}
230
234
@@ -285,6 +289,13 @@ public function __call($resourceName, $arguments)
285
289
*/
286
290
public function config ($ config )
287
291
{
292
+ /**
293
+ * Reset config to it's initial values
294
+ */
295
+ $ this ->config = array (
296
+ 'ApiVersion ' => self ::$ defaultApiVersion ,
297
+ );
298
+
288
299
foreach ($ config as $ key => $ value ) {
289
300
$ this ->config [$ key ] = $ value ;
290
301
}
@@ -313,6 +324,7 @@ public function setAdminUrl()
313
324
314
325
//Remove https:// and trailing slash (if provided)
315
326
$ shopUrl = preg_replace ('#^https?://|/$# ' , '' , $ shopUrl );
327
+ $ apiVersion = $ this ->config ['ApiVersion ' ];
316
328
317
329
if (isset ($ this ->config ['ApiKey ' ]) && isset ($ this ->config ['Password ' ])) {
318
330
$ apiKey = $ this ->config ['ApiKey ' ];
@@ -323,6 +335,7 @@ public function setAdminUrl()
323
335
}
324
336
325
337
$ this ->config ['AdminUrl ' ] = $ adminUrl ;
338
+ $ this ->config ['ApiUrl ' ] = $ adminUrl . "api/ $ apiVersion/ " ;
326
339
327
340
return $ adminUrl ;
328
341
}
@@ -336,6 +349,15 @@ public function getAdminUrl() {
336
349
return $ this ->config ['AdminUrl ' ];
337
350
}
338
351
352
+ /**
353
+ * Get the api url of the configured shop
354
+ *
355
+ * @return string
356
+ */
357
+ public function getApiUrl () {
358
+ return $ this ->config ['ApiUrl ' ];
359
+ }
360
+
339
361
/**
340
362
* Maintain maximum 2 calls per second to the API
341
363
*
0 commit comments