From 5bd83b36d442c2ffa561c5752fac08bba266884e Mon Sep 17 00:00:00 2001 From: Doug Niccum Date: Thu, 12 May 2022 08:25:37 -0500 Subject: [PATCH 1/4] Fixes an issue where certain versions of PHP would throw an error $customers variable was an empty array, thus the index of 0 would not exist. --- src/BigCommerce/Api/Customers/CustomersApi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BigCommerce/Api/Customers/CustomersApi.php b/src/BigCommerce/Api/Customers/CustomersApi.php index 5acdc7bb..980ed6f3 100644 --- a/src/BigCommerce/Api/Customers/CustomersApi.php +++ b/src/BigCommerce/Api/Customers/CustomersApi.php @@ -33,7 +33,7 @@ public function getByEmail(string $email): ?Customer { $customers = $this->getAll([self::FILTER__EMAIL_IN => $email])->getCustomers(); - if (!$customers[0]) { + if (count($customers) === 0) { return null; } elseif (count($customers) > 1) { throw new UnexpectedValueException("There are more than one customer with the email address $email"); From a83b61974b1d52c1487f332cfbae9f22ee66d7e5 Mon Sep 17 00:00:00 2001 From: Doug Niccum Date: Thu, 12 May 2022 08:44:14 -0500 Subject: [PATCH 2/4] Adds unit test for the empty result. --- tests/BigCommerce/Api/Customers/CustomersApiTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/BigCommerce/Api/Customers/CustomersApiTest.php b/tests/BigCommerce/Api/Customers/CustomersApiTest.php index d92e1e0a..47e724d1 100644 --- a/tests/BigCommerce/Api/Customers/CustomersApiTest.php +++ b/tests/BigCommerce/Api/Customers/CustomersApiTest.php @@ -38,6 +38,14 @@ public function testCanGetCustomerByEmail() $this->assertEquals('John', $customer->first_name); } + public function testUnknownCustomerReturnsEmptyResult() + { + $this->setReturnData('customers__get_all_no_results.json'); + $customer = $this->getApi()->customers()->getByEmail('wade.wilson@spam.me'); + + $this->assertNull($customer); + } + public function testCanGetCustomerById() { $this->setReturnData('customers__get_all.json'); From 1b6e40a78c1b1b404eb941b95dab97f430df9f78 Mon Sep 17 00:00:00 2001 From: Jarrod Swift Date: Mon, 16 May 2022 13:35:44 +0930 Subject: [PATCH 3/4] Clear release notes for 1.8.1 release --- RELEASE_NOTES.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 7608e453..d47f0195 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,7 +1,5 @@ ### New Features -- Implement V2 Order Products API -- Implement V2 Order Shipping Addresses API (read-only) From 94397930b86cb3b5b449e27f6d79ce6a47d35af6 Mon Sep 17 00:00:00 2001 From: Jarrod Swift Date: Tue, 17 May 2022 09:23:54 +0930 Subject: [PATCH 4/4] Update release notes with fix --- RELEASE_NOTES.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index d47f0195..739c9916 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,4 +1,6 @@ -### New Features +### Fixes + +- Fixes _Undefined index within customer getByEmail method_ (thanks @dniccum)