diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c10c84c..f7bc88df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## Unreleased +- [#370](https://github.com/Shopify/shopify-api-php/pull/370) [Patch] Fix params set to zero being removed from request payload ## v5.6.1 - 2024-09-06 diff --git a/src/Rest/Base.php b/src/Rest/Base.php index b30e4c37..67a7d390 100644 --- a/src/Rest/Base.php +++ b/src/Rest/Base.php @@ -178,7 +178,10 @@ protected static function request( $client = new Rest($session->getShop(), $session->getAccessToken()); - $params = array_filter($params); + $params = array_filter($params, function ($value) { + return $value !== ""; + }); + switch ($httpMethod) { case "get": $response = $client->get( diff --git a/tests/Clients/BaseRestResourceTest.php b/tests/Clients/BaseRestResourceTest.php index 435d8fac..5346258d 100644 --- a/tests/Clients/BaseRestResourceTest.php +++ b/tests/Clients/BaseRestResourceTest.php @@ -63,6 +63,24 @@ public function testFindsWithParam() $this->assertEquals([1, "attribute"], [$resource->id, $resource->attribute]); } + public function testFindsWithFalseyParams() + { + $body = ["fake_resource" => ["id" => 1, "attribute" => "attribute"]]; + + $this->mockTransportRequests([ + new MockRequest( + $this->buildMockHttpResponse(200, $body), + "{$this->prefix}/fake_resources/1.json?zero_param=0", + "GET", + null, + ["X-Shopify-Access-Token: access-token"], + ), + ]); + + $resource = FakeResource::find($this->session, 1, ["zero_param" => "0", "empty_param" => ""]); + $this->assertEquals([1, "attribute"], [$resource->id, $resource->attribute]); + } + public function testFindsResourceAndChildrenById() { $body = ["fake_resource" => [