SyliusCon 2025
Early Bird Deal
LogoLogo
🛣️ Roadmap💻 Sylius Demo💬 Community Slack
  • Sylius Documentation
  • Sylius Plugins
  • Sylius Stack
  • 📖Sylius 2.0 Documentation
    • Organization
      • Release Cycle
      • Backwards Compatibility Promise
      • Sylius Team
      • Sylius Roadmap
  • Getting Started with Sylius
    • Installation
    • Basic Configuration
    • Shipping & Payment
    • First Product
    • Customizing the Shop
    • Customizing Business Logic
    • Using API
    • Installing Plugins
    • Deployment
    • Summary
  • The Book
    • Introduction to Sylius
    • Installation
      • System Requirements
      • Sylius CE Installation
        • Sylius CE Installation with Docker
      • ➕Sylius Plus Installation
      • Upgrading Sylius CE
      • Upgrading Sylius Plus
    • Architecture
      • Architecture Overview
      • Architectural Drivers
      • Resource Layer
      • State Machine
      • Translations
      • E-Mails
      • Contact
      • Fixtures
      • Events
    • Configuration
      • Channels
      • Locales
      • Currencies
    • Customers
      • Customer & ShopUser
      • ➕Customer Pools
      • AdminUser
      • Addresses
        • Countries
        • Zones
        • Addresses
        • Address Book
    • Products
      • Products
      • Product Reviews
      • Product Associations
      • Attributes
      • Pricing
      • Catalog Promotions
      • Taxons
      • Inventory
      • ➕Multi-Source Inventory
      • Search
    • Carts & Orders
      • Orders
      • Cart flow
      • Taxation
      • Adjustments
      • Cart Promotions
      • Coupons
      • Payments
      • 🧩Invoices
      • Shipments
    • Support
    • Contributing
      • Contributing Code
        • Submitting a Patch
        • ⚠️Security Issues
        • Coding Standards
        • Conventions
        • Sylius License and Trademark
      • Contributing Translations
      • Key Contributors
  • The Customization Guide
    • Customizing Models
      • How to add a custom model?
      • How to add a custom translatable model?
    • Customizing Forms
      • How to add a live form for a custom model?
    • Customizing Styles
    • Customizing Validation
    • Customizing Menus
    • Customizing Templates
    • Customizing Translations
    • Customizing Flashes
    • Customizing State Machines
    • Customizing Grids
    • Customizing Fixtures
    • Customizing API
    • Customizing Serialization of API
    • Customizing Payments
      • How to integrate a Payment Gateway as a Plugin?
  • 🧑‍🍳The Cookbook
  • How to resize images?
  • How to add one image to an entity?
  • How to add multiple images to an entity?
  • Sylius 1.X Documentation
    • 📓Sylius 1.x Documentation
Powered by GitBook
LogoLogo

Developer

  • Community
  • Online Course

About

  • Team

© 2025 Sylius. All Rights Reserved

On this page

Was this helpful?

Edit on GitHub
  1. The Book
  2. Customers
  3. Addresses

Countries

PreviousAddressesNextZones

Last updated 8 months ago

Was this helpful?

Countries are a part of the Addressing concept. The Country entity represents a real country that your shop is willing to sell its goods in (for example the UK). It has an ISO code to be identified easily ().

Countries might also have Provinces, which are in fact a general name for an administrative division, within a country. Therefore we understand provinces as states of the USA, voivodeships of Poland, or Bundesländer of Germany.

How to add a country?

To give you a better insight into Countries, let’s have a look on how to prepare and add a Country to the system programmatically. We will do it with a province at once.

You will need factories for countries and provinces to create them:

/** @var CountryInterface $country */
$country = $this->container->get('sylius.factory.country')->createNew();

/** @var ProvinceInterface $province */
$province = $this->container->get('sylius.factory.province')->createNew();

To the newly created objects assign codes.

// US - the United States of America
$country->setCode('US');
// US_CA - California
$province->setCode('US_CA');

Provinces may be added to a country via a collection. Create one and add the province object to it and using the prepared collection add the province to the Country.

$provinces = new ArrayCollection();
$provinces->add($province);

$country->setProvinces($provinces);

You can of course simply add a single province:

$country->addProvince($province);

Finally, you will need a repository for countries to add the country to your system.

/** @var RepositoryInterface $countryRepository */
$countryRepository = $this->get('sylius.repository.country');

$countryRepository->add($country);

From now on the country will be available to use in your system.

ISO 3166-1 alpha-2