diff --git a/lib/ShopifyResource.php b/lib/ShopifyResource.php index c06bf96..2949fee 100644 --- a/lib/ShopifyResource.php +++ b/lib/ShopifyResource.php @@ -121,7 +121,7 @@ public function __construct($config, $id = null, $parentResourceUrl = '') $this->config = $config; $this->id = $id; - $this->resourceUrl = ($parentResourceUrl ? $parentResourceUrl . '/' : $config['AdminUrl']) . $this->getResourcePath() . ($this->id ? '/' . $this->id : ''); + $this->resourceUrl = ($parentResourceUrl ? $parentResourceUrl . '/' : $config['ApiUrl']) . $this->getResourcePath() . ($this->id ? '/' . $this->id : ''); if (isset($config['AccessToken'])) { $this->httpHeaders['X-Shopify-Access-Token'] = $config['AccessToken']; diff --git a/lib/ShopifySDK.php b/lib/ShopifySDK.php index 32bb9da..3ce8886 100644 --- a/lib/ShopifySDK.php +++ b/lib/ShopifySDK.php @@ -142,6 +142,11 @@ class ShopifySDK */ public static $timeAllowedForEachApiCall = .5; + /** + * @var string Default Shopify API version + */ + public static $defaultApiVersion = '2022-07'; + /** * Shop / API configurations * @@ -223,8 +228,7 @@ class ShopifySDK public function __construct($config = array()) { if(!empty($config)) { - $this->config = $config; - $this->setAdminUrl(); + ShopifySDK::config($config); } } @@ -285,6 +289,13 @@ public function __call($resourceName, $arguments) */ public function config($config) { + /** + * Reset config to it's initial values + */ + $this->config = array( + 'ApiVersion' => self::$defaultApiVersion, + ); + foreach ($config as $key => $value) { $this->config[$key] = $value; } @@ -313,6 +324,7 @@ public function setAdminUrl() //Remove https:// and trailing slash (if provided) $shopUrl = preg_replace('#^https?://|/$#', '', $shopUrl); + $apiVersion = $this->config['ApiVersion']; if(isset($this->config['ApiKey']) && isset($this->config['Password'])) { $apiKey = $this->config['ApiKey']; @@ -323,6 +335,7 @@ public function setAdminUrl() } $this->config['AdminUrl'] = $adminUrl; + $this->config['ApiUrl'] = $adminUrl . "api/$apiVersion/"; return $adminUrl; } @@ -336,6 +349,15 @@ public function getAdminUrl() { return $this->config['AdminUrl']; } + /** + * Get the api url of the configured shop + * + * @return string + */ + public function getApiUrl() { + return $this->config['ApiUrl']; + } + /** * Maintain maximum 2 calls per second to the API *