Basic Usage


We’re sorry but this documentation section is outdated. Please have that in mind when trying to use it. You can help us making documentation up to date via Sylius Github. Thank you!


Zones are not very useful by themselves, but they can take part in e.g. a complex taxation/shipping system. This service is capable of getting a Zone specific for given Address.

It uses a collaborator implementing Doctrine’s ObjectRepository interface to obtain all available zones, compare them with given Address and return best fitted Zone.

First lets make some preparations.


use Sylius\Component\Addressing\Model\Address;
use Sylius\Component\Addressing\Model\Zone;
use Sylius\Component\Addressing\Model\ZoneInterface;
use Sylius\Component\Addressing\Model\ZoneMember;
use Sylius\Component\Resource\Repository\InMemoryRepository;

$zoneRepository = new InMemoryRepository(ZoneInterface::class);
$zone = new Zone();
$zoneMember = new ZoneMember();

$address = new Address();




Now that we have all the needed parts lets match something.


use Sylius\Component\Addressing\Matcher\ZoneMatcher;

$zoneMatcher = new ZoneMatcher($zoneRepository);

$zoneMatcher->match($address); // returns the best matching zone
                               // for the address given, in this case $zone

ZoneMatcher can also return all zones containing given Address.


$zoneMatcher->matchAll($address); // returns all zones containing given $address

To be more specific you can provide a scope which will narrow the search only to zones with same corresponding property.



$zoneMatcher->match($address, 'earth'); // returns $zone
$zoneMatcher->matchAll($address, 'mars'); // returns null as there is no
                                          // zone with 'mars' scope


This service implements the ZoneMatcherInterface.


Throws \InvalidArgumentException.