diff --git a/src/Actions/CheckMagentoExistence.php b/src/Actions/CheckMagentoExistence.php index f8fcd9f..de3b18c 100644 --- a/src/Actions/CheckMagentoExistence.php +++ b/src/Actions/CheckMagentoExistence.php @@ -36,7 +36,7 @@ public function exists(string $sku): bool protected function getMagentoProduct(string $sku): Response { - return $this->magento->get("products/$sku", ['fields' => 'sku']); + return $this->magento->get('products/' . urlencode($sku), ['fields' => 'sku']); } public static function bind(): void diff --git a/src/Actions/RetrieveProductData.php b/src/Actions/RetrieveProductData.php index 453cc93..7592b49 100644 --- a/src/Actions/RetrieveProductData.php +++ b/src/Actions/RetrieveProductData.php @@ -58,7 +58,7 @@ protected function getMagentoProduct(string $sku, string $store = null): Respons { return $this->magento ->store($store) - ->get("products/$sku"); + ->get('products/'.urlencode($sku)); } public static function bind(): void diff --git a/tests/Actions/CheckMagentoExistenceTest.php b/tests/Actions/CheckMagentoExistenceTest.php index 2e2bb5d..5e714a5 100644 --- a/tests/Actions/CheckMagentoExistenceTest.php +++ b/tests/Actions/CheckMagentoExistenceTest.php @@ -23,7 +23,8 @@ protected function setUp(): void Http::fake([ '*products/123?fields=sku' => Http::response(['data']), '*products/456?fields=sku' => Http::response([], 404), - ]); + '*products/123%2B456?fields=sku' => Http::response(['data']), + ])->preventStrayRequests(); } public function test_existing_product(): void @@ -33,6 +34,11 @@ public function test_existing_product(): void $this->assertTrue($this->action->exists('123')); } + public function test_urlencode(): void + { + $this->assertTrue($this->action->exists('123+456')); + } + public function test_new_existing_product(): void { $this->assertTrue($this->action->exists('123')); diff --git a/tests/Actions/RetrieveProductDataTest.php b/tests/Actions/RetrieveProductDataTest.php index 6819ffd..e76559f 100644 --- a/tests/Actions/RetrieveProductDataTest.php +++ b/tests/Actions/RetrieveProductDataTest.php @@ -22,7 +22,7 @@ protected function setUp(): void Http::fake([ '*/products/123' => Http::response(['123']), - '*/products/456' => Http::response(['456']), + '*/products/123%2B456' => Http::response(['456']), '*/some_store/V1/products/789' => Http::response(['789']), '*/products/404' => Http::response([], 404), ]); @@ -39,12 +39,12 @@ public function test_it_retrieves_existing_product(): void public function test_it_retrieves_new_product(): void { - $data = $this->action->retrieve('456'); + $data = $this->action->retrieve('123+456'); $this->assertEquals(['456'], $data); Http::assertSent(function (Request $request) { - return $request->url() == 'rest/all/V1/products/456'; + return $request->url() == 'rest/all/V1/products/123%2B456'; }); }