diff --git a/src/ApiPlatform/Resources/CustomerGroup.php b/src/ApiPlatform/Resources/CustomerGroup.php index 77ed229..2bc3048 100644 --- a/src/ApiPlatform/Resources/CustomerGroup.php +++ b/src/ApiPlatform/Resources/CustomerGroup.php @@ -66,6 +66,7 @@ ], // Here, we use command mapping to adapt the normalized command result for the CQRS query CQRSCommandMapping: [ + '[_context][shopIds]' => '[shopIds]', '[groupId]' => '[customerGroupId]', ], ), diff --git a/tests/Integration/ApiPlatform/CustomerGroupApiTest.php b/tests/Integration/ApiPlatform/CustomerGroupApiTest.php index 4c2d7ef..e984f49 100644 --- a/tests/Integration/ApiPlatform/CustomerGroupApiTest.php +++ b/tests/Integration/ApiPlatform/CustomerGroupApiTest.php @@ -105,6 +105,46 @@ public function testAddCustomerGroup(): int return $customerGroupId; } + public function testAddCustomerGroupWithoutShopIds(): int + { + $numberOfGroups = count(\Group::getGroups(\Context::getContext()->language->id)); + + $bearerToken = $this->getBearerToken(['customer_group_write']); + $response = static::createClient()->request('POST', '/customers/group', [ + 'auth_bearer' => $bearerToken, + 'json' => [ + 'localizedNames' => [ + 1 => 'test1', + ], + 'reductionPercent' => 10.3, + 'displayPriceTaxExcluded' => true, + 'showPrice' => true, + ], + ]); + self::assertResponseStatusCodeSame(201); + self::assertCount($numberOfGroups + 1, \Group::getGroups(\Context::getContext()->language->id)); + + $decodedResponse = json_decode($response->getContent(), true); + $this->assertNotFalse($decodedResponse); + $this->assertArrayHasKey('customerGroupId', $decodedResponse); + $customerGroupId = $decodedResponse['customerGroupId']; + $this->assertEquals( + [ + 'customerGroupId' => $customerGroupId, + 'localizedNames' => [ + 1 => 'test1', + ], + 'reductionPercent' => 10.3, + 'displayPriceTaxExcluded' => true, + 'showPrice' => true, + 'shopIds' => [1], + ], + $decodedResponse + ); + + return $customerGroupId; + } + /** * @depends testAddCustomerGroup *