From a7ffbbd1b29b4a218feb84dd293cacc8de5d1325 Mon Sep 17 00:00:00 2001 From: Naya <69888129+anglerfox-naya@users.noreply.github.com> Date: Fri, 1 Dec 2023 23:13:25 +0530 Subject: [PATCH 1/9] Update composer.json --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 36b3a39..b131c0a 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,11 @@ { - "name": "protechstudio/laravel-prestashop-webservice", + "name": "anglerfox/laravel-prestashop-webservice", "description": "Laravel 5 wrapper for Prestashop Web Service Library", "license": "MIT", "authors": [ { - "name": "Vito Laera", - "email": "vito.laera@protechstudio.it" + "name": "Anglerfox", + "email": "support@anglerfox.com" } ], "autoload": { From 44364ae34af1d17fa54c3b965503e82c823f7c2e Mon Sep 17 00:00:00 2001 From: Naya <69888129+anglerfox-naya@users.noreply.github.com> Date: Fri, 1 Dec 2023 23:14:10 +0530 Subject: [PATCH 2/9] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b131c0a..5016de4 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ }, "require-dev": { "squizlabs/php_codesniffer": "^3.2", - "Orchestra/Testbench": "^3.5" + "orchestra/testbenc": "^3.5" }, "scripts": { "test": "vendor/bin/phpunit", From 79755aaedbd5c5939635846b4feccb56358962f1 Mon Sep 17 00:00:00 2001 From: Naya <69888129+anglerfox-naya@users.noreply.github.com> Date: Fri, 1 Dec 2023 23:16:15 +0530 Subject: [PATCH 3/9] Update PrestashopWebServiceLibrary.php --- src/PrestashopWebServiceLibrary.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PrestashopWebServiceLibrary.php b/src/PrestashopWebServiceLibrary.php index 160f2fa..fba40b9 100644 --- a/src/PrestashopWebServiceLibrary.php +++ b/src/PrestashopWebServiceLibrary.php @@ -29,7 +29,7 @@ class PrestashopWebServiceLibrary /** @var array compatible versions of PrestaShop WebService */ const PS_COMPATIBLE_VERSION_MIN = '1.4.0.0'; - const PS_COMPATIBLE_VERSION_MAX = '1.7.99.99'; + const PS_COMPATIBLE_VERSION_MAX = '9.9.99.99'; /** * PrestaShopWebService constructor. Throw an exception when CURL is not installed/activated From 794df35dec3e22b8114a2a85c429b1a2e3ccb31f Mon Sep 17 00:00:00 2001 From: Naya <69888129+anglerfox-naya@users.noreply.github.com> Date: Fri, 1 Dec 2023 23:16:42 +0530 Subject: [PATCH 4/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 382f4b9..ada55b8 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Installation Require this package with composer using the following command: ```shell -composer require protechstudio/laravel-prestashop-webservice +composer require anglerfox/laravel-prestashop-webservice ``` After updating composer, add the service provider to the `providers` array in `config/app.php` From a83f775c15316049ed4bd3b80786de162871fa8d Mon Sep 17 00:00:00 2001 From: github-hera <105424108+github-hera@users.noreply.github.com> Date: Fri, 29 Dec 2023 14:37:48 +0530 Subject: [PATCH 5/9] Cache requests (#1) --- src/PrestashopWebServiceLibrary.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/PrestashopWebServiceLibrary.php b/src/PrestashopWebServiceLibrary.php index fba40b9..37c0de4 100644 --- a/src/PrestashopWebServiceLibrary.php +++ b/src/PrestashopWebServiceLibrary.php @@ -4,6 +4,7 @@ use Protechstudio\PrestashopWebService\Exceptions\PrestashopWebServiceException; use Protechstudio\PrestashopWebService\Exceptions\PrestashopWebServiceRequestException; +use Illuminate\Support\Facades\Cache; use SimpleXMLElement; /** @@ -365,9 +366,18 @@ public function get($options) throw new PrestashopWebServiceException('Bad parameters given'); } - $request = $this->executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'GET')); - - $this->checkRequest($request);// check the response validity + if(isset($options['cache_key']) && !empty($options['cache_key'])){ + if(Cache::get($options['cache_key'])){ + $request['response'] = Cache::get($options['cache_key']); + }else{ + $request = $this->executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'GET')); + $this->checkRequest($request);// check the response validity + Cache::put($options['cache_key'], $request['response'] , $options['expiration'] ?? 86400); + } + }else{ + $request = $this->executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'GET')); + $this->checkRequest($request);// check the response validity + } return $this->parseXML($request['response']); } From c949dbac182bbd8fc9497f88bd894377c8bf70c0 Mon Sep 17 00:00:00 2001 From: github-hera <105424108+github-hera@users.noreply.github.com> Date: Tue, 23 Jan 2024 08:12:38 +0000 Subject: [PATCH 6/9] Api issue fix --- src/PrestashopWebServiceLibrary.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PrestashopWebServiceLibrary.php b/src/PrestashopWebServiceLibrary.php index 37c0de4..5fbf08d 100644 --- a/src/PrestashopWebServiceLibrary.php +++ b/src/PrestashopWebServiceLibrary.php @@ -153,7 +153,7 @@ protected function executeRequest($url, $curl_params = array()) } } - list($response, $info, $error) = $this->executeCurl($url, $curl_options); + list($response, $info, $error) = $this->executeCurl($url.= '&ws_key=' . $this->key, $curl_options); $status_code = $info['http_code']; if ($status_code === 0 || $error) { From 13482b12398b7591501f26ae7f9c47eb548aae59 Mon Sep 17 00:00:00 2001 From: github-sakshi-jain Date: Wed, 4 Dec 2024 17:00:08 +0530 Subject: [PATCH 7/9] Set default prestashop version when not defined --- src/PrestashopWebServiceLibrary.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/PrestashopWebServiceLibrary.php b/src/PrestashopWebServiceLibrary.php index 5fbf08d..49a71d4 100644 --- a/src/PrestashopWebServiceLibrary.php +++ b/src/PrestashopWebServiceLibrary.php @@ -178,8 +178,9 @@ protected function executeRequest($url, $curl_params = array()) } if (array_key_exists('PSWS-Version', $headerArray)) { - $this->isPrestashopVersionSupported($headerArray['PSWS-Version']); - $this->version = $headerArray['PSWS-Version']; + $version = $headerArray['PSWS-Version'] == 0 ? '1.7.5.1' : $headerArray['PSWS-Version']; + $this->isPrestashopVersionSupported($version); + $this->version = $version; } $this->printDebug('HTTP REQUEST HEADER', $info['request_header']); From f54c6ef640c1d5ca7e7538356f668c2f5138c89f Mon Sep 17 00:00:00 2001 From: github-sakshi-jain Date: Tue, 25 Feb 2025 14:17:17 +0530 Subject: [PATCH 8/9] Message update - Prestashop webservice resource API --- .../PrestashopWebServiceRequestException.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Exceptions/PrestashopWebServiceRequestException.php b/src/Exceptions/PrestashopWebServiceRequestException.php index 74ebea2..e456070 100644 --- a/src/Exceptions/PrestashopWebServiceRequestException.php +++ b/src/Exceptions/PrestashopWebServiceRequestException.php @@ -4,13 +4,17 @@ class PrestashopWebServiceRequestException extends PrestashopWebServiceException { - static protected $label = 'This call to PrestaShop Web Services failed and returned an HTTP status of %d. That means: %s.'; - protected $response; public function __construct($message = null, $code = null, $response = null) { - parent::__construct(sprintf(static::$label, $code, $message), $code); + if ($response instanceof \SimpleXMLElement && isset($response->errors->error->message)) { + $message = (string) $response->errors->error->message; + } + + $finalMessage = $message ?? sprintf("This call to PrestaShop Web Services failed with HTTP status %d.", $code); + + parent::__construct($finalMessage, $code); $this->response = $response; } From 8c61466e74d06253c563047d789e8352779a4246 Mon Sep 17 00:00:00 2001 From: github-sakshi-jain Date: Wed, 12 Mar 2025 10:17:13 +0530 Subject: [PATCH 9/9] API path update & webservice redirect fix --- src/PrestashopWebServiceLibrary.php | 32 +++++++++++++++-------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/PrestashopWebServiceLibrary.php b/src/PrestashopWebServiceLibrary.php index 49a71d4..0136296 100644 --- a/src/PrestashopWebServiceLibrary.php +++ b/src/PrestashopWebServiceLibrary.php @@ -64,7 +64,7 @@ public function __construct($url, $key, $debug = true) $this->key = $key; $this->debug = $debug; $this->version = 'unknown'; - + $this->runningInConsole = app()->runningInConsole(); } @@ -94,12 +94,11 @@ protected function checkRequest($request) if ($request['response']) { $xml = $this->parseXML($request['response'], true); } - throw new PrestashopWebServiceRequestException($messages[$request['status_code']], $request['status_code'], $xml); } else { $exception = 'This call to PrestaShop Web Services returned an unexpected HTTP status of: '; $exception.= $request['status_code']; - throw new PrestashopWebServiceException($exception); + throw new PrestashopWebServiceRequestException($exception, $request['status_code'], null, $request['base_url']); } } @@ -152,7 +151,6 @@ protected function executeRequest($url, $curl_params = array()) $curl_options[$defkey] = $curl_params[$defkey]; } } - list($response, $info, $error) = $this->executeCurl($url.= '&ws_key=' . $this->key, $curl_options); $status_code = $info['http_code']; @@ -167,6 +165,9 @@ protected function executeRequest($url, $curl_params = array()) $header = substr($response, 0, $index); $body = substr($response, $index); + $redirectUrl = isset($info['redirect_url']) ? $info['redirect_url'] : null; + $parsedUrl = parse_url($redirectUrl ?: $url); + $baseUrl = $parsedUrl['scheme'] . '://' . $parsedUrl['host']; $headerArray = array(); foreach (explode("\n", $header) as $headerItem) { @@ -197,7 +198,8 @@ protected function executeRequest($url, $curl_params = array()) 'status_code' => $status_code, 'response' => $body, 'header' => $header, - 'headers' => $headerArray + 'headers' => $headerArray, + 'base_url' => $baseUrl ); } @@ -295,7 +297,7 @@ public function add($options) $xml = ''; if (isset($options['resource'], $options['postXml']) || isset($options['url'], $options['postXml'])) { - $url = (isset($options['resource']) ? $this->url.'/api/'.$options['resource'] : $options['url']); + $url = (isset($options['resource']) ? $this->url.'/webservice/dispatcher.php?url='.$options['resource'] : $options['url']); $xml = $options['postXml']; if (isset($options['id_shop'])) { $url .= '&id_shop='.$options['id_shop']; @@ -315,7 +317,7 @@ public function add($options) /** * Retrieve (GET) a resource *

Unique parameter must take :

- * 'url' => Full URL for a GET request of WebService (ex: http://mystore.com/api/customers/1/)
+ * 'url' => Full URL for a GET request of WebService (ex: http://mystore.com//webservice/dispatcher.php?url=customers/1)
* OR
* 'resource' => Resource name,
* 'id' => ID of a resource you want to get

@@ -346,7 +348,7 @@ public function get($options) if (isset($options['url'])) { $url = $options['url']; } elseif (isset($options['resource'])) { - $url = $this->url.'/api/'.$options['resource']; + $url = $this->url.'/webservice/dispatcher.php?url='.$options['resource']; $url_params = array(); if (isset($options['id'])) { $url .= '/'.$options['id']; @@ -361,7 +363,7 @@ public function get($options) } } if (count($url_params) > 0) { - $url .= '?'.http_build_query($url_params); + $url .= '&'.http_build_query($url_params); } } else { throw new PrestashopWebServiceException('Bad parameters given'); @@ -374,7 +376,7 @@ public function get($options) $request = $this->executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'GET')); $this->checkRequest($request);// check the response validity Cache::put($options['cache_key'], $request['response'] , $options['expiration'] ?? 86400); - } + } }else{ $request = $this->executeRequest($url, array(CURLOPT_CUSTOMREQUEST => 'GET')); $this->checkRequest($request);// check the response validity @@ -394,7 +396,7 @@ public function head($options) if (isset($options['url'])) { $url = $options['url']; } elseif (isset($options['resource'])) { - $url = $this->url.'/api/'.$options['resource']; + $url = $this->url.'/webservice/dispatcher.php?url='.$options['resource']; $url_params = array(); if (isset($options['id'])) { $url .= '/'.$options['id']; @@ -409,7 +411,7 @@ public function head($options) } } if (count($url_params) > 0) { - $url .= '?'.http_build_query($url_params); + $url .= '&'.http_build_query($url_params); } } else { throw new PrestashopWebServiceException('Bad parameters given'); @@ -439,7 +441,7 @@ public function edit($options) if (isset($options['url'])) { $url = $options['url']; } else { - $url = $this->url.'/api/'.$options['resource'].'/'.$options['id']; + $url = $this->url.'/webservice/dispatcher.php?url='.$options['resource'].'/'.$options['id']; } $xml = $options['putXml']; if (isset($options['id_shop'])) { @@ -487,9 +489,9 @@ public function delete($options) $url = $options['url']; } elseif (isset($options['resource']) && isset($options['id'])) { if (is_array($options['id'])) { - $url = $this->url.'/api/'.$options['resource'].'/?id=['.implode(',', $options['id']).']'; + $url = $this->url.'/webservice/dispatcher.php?url='.$options['resource'].'/?id=['.implode(',', $options['id']).']'; } else { - $url = $this->url.'/api/'.$options['resource'].'/'.$options['id']; + $url = $this->url.'/webservice/dispatcher.php?url='.$options['resource'].'/'.$options['id']; } } if (isset($options['id_shop'])) {