diff --git a/features/admin/addressing/managing_zones/zone_validation.feature b/features/admin/addressing/managing_zones/zone_validation.feature
index e16c5bc2b3..545aaa394b 100644
--- a/features/admin/addressing/managing_zones/zone_validation.feature
+++ b/features/admin/addressing/managing_zones/zone_validation.feature
@@ -99,3 +99,13 @@ Feature: Zone validation
And I try to add it
Then I should be notified that "NA" is not a valid zone code
And zone with name "America" should not be added
+
+ @api @no-ui
+ Scenario: Trying to add a zone with wrong type
+ When I want to create a new zone consisting of wrong_type
+ And I name it "European Union"
+ And I specify its code as "EU"
+ And I add a country "France"
+ And I try to add it
+ Then I should be notified that "wrong_type" is not a valid zone type
+ And zone with name "European Union" should not be added
diff --git a/src/Sylius/Behat/Context/Api/Admin/ManagingZonesContext.php b/src/Sylius/Behat/Context/Api/Admin/ManagingZonesContext.php
index 2afc7484de..18d6be4266 100644
--- a/src/Sylius/Behat/Context/Api/Admin/ManagingZonesContext.php
+++ b/src/Sylius/Behat/Context/Api/Admin/ManagingZonesContext.php
@@ -485,6 +485,17 @@ final readonly class ManagingZonesContext implements Context
);
}
+ /**
+ * @Then I should be notified that :type is not a valid zone type
+ */
+ public function iShouldBeNotifiedThatIsNotAValidZoneType(string $type): void
+ {
+ Assert::contains(
+ $this->responseChecker->getError($this->client->getLastResponse()),
+ sprintf('Type "%s" is invalid. Allowed types are:', $type),
+ );
+ }
+
private function removeZoneMember(CountryInterface|ProvinceInterface|ZoneInterface $objectToRemove): void
{
$members = $this->client->getContent()['members'];
diff --git a/src/Sylius/Bundle/AddressingBundle/Resources/config/validation/Zone.xml b/src/Sylius/Bundle/AddressingBundle/Resources/config/validation/Zone.xml
index 77d3006281..7eec9e67a6 100644
--- a/src/Sylius/Bundle/AddressingBundle/Resources/config/validation/Zone.xml
+++ b/src/Sylius/Bundle/AddressingBundle/Resources/config/validation/Zone.xml
@@ -34,6 +34,13 @@
+
+
+
+
+
+
+
diff --git a/src/Sylius/Bundle/AddressingBundle/Resources/translations/validators.en.yml b/src/Sylius/Bundle/AddressingBundle/Resources/translations/validators.en.yml
index 350245b6ca..82a05aa1d4 100644
--- a/src/Sylius/Bundle/AddressingBundle/Resources/translations/validators.en.yml
+++ b/src/Sylius/Bundle/AddressingBundle/Resources/translations/validators.en.yml
@@ -51,6 +51,8 @@ sylius:
not_blank: Please enter zone code.
regex: Zone code can only be comprised of letters, numbers, dashes and underscores.
unique: Zone code must be unique.
+ type:
+ invalid: "Type {{ value }} is invalid. Allowed types are: {{ choices }}."
members:
min_count: Please add at least {{ limit }} zone member.
name:
diff --git a/src/Sylius/Component/Addressing/Model/Zone.php b/src/Sylius/Component/Addressing/Model/Zone.php
index e7935d6e9e..dd4c9b7a58 100644
--- a/src/Sylius/Component/Addressing/Model/Zone.php
+++ b/src/Sylius/Component/Addressing/Model/Zone.php
@@ -82,15 +82,8 @@ class Zone implements ZoneInterface, \Stringable
return $this->type;
}
- /**
- * @throws \InvalidArgumentException
- */
public function setType(?string $type): void
{
- if (!in_array($type, static::getTypes(), true)) {
- throw new \InvalidArgumentException('Wrong zone type supplied.');
- }
-
$this->type = $type;
}