Pimcore guides &amp; How to 2 min read

# How to Create a Custom CountryBased Store Context Resolver for coreshop

Find out how to create a custom CountryBased store context resolver.

Last updated on 29 August, 2025

## Key takeaways

1. In CoreShop, StoreContext loads the current store from a request resolver, which finds the correct store for each request.
2. A custom country-based resolver helps when a project has several stores, such as one for EEA countries and one for the rest of the world.
3. The custom RequestBased store context must be registered in services.yaml, with every constructor dependency also defined as an argument.
4. Country detection uses GeoLiteBasedRequestResolver, which needs the GeoLite2 database file and its path set in parameters.yaml, followed by clearing the cache.
5. Because the resolver ignores private IP addresses such as localhost, local testing requires temporarily setting a real IP address in the resolver's findCountry method.

![CoreShop store configuration named Standard: euro currency, Croatia as base country, allowed countries list](https://factory.dev/wp-content/uploads/2026/11/how_to_coreshop_standard.jpg)

## What you’ll learn with this guide

Context and context resolver are used for CoreShop to determine the current store the user comes from. StoreContext loads a store from a given request resolver, while the resolver takes care of finding the correct store for the current request. This guide will teach you how to create a **custom CountryBased store context resolver**.

## Where to use

Let’s assume you already have CoreShop installed on your Pimcore project. If not, follow the instructions [here](https://docs.coreshop.org/3.0.0/Gettings_Started/Installation.html).

CoreShop already has **two resolvers for determining the store based** [on a pimcore frontend side](https://github.com/coreshop/CoreShop/blob/master/src/CoreShop/Component/Store/Context/RequestBased/SiteBasedRequestResolver.php) and [on a document in the backend](https://github.com/coreshop/CoreShop/blob/master/src/CoreShop/Component/Store/Context/RequestBased/PimcoreAdminSiteBasedRequestResolver.php). If you have more than one store and specific rules you need to follow to determine the store, for example, based on a country — this guide is exactly what you need.

## Solution

Every CoreShop installation has **one default store called Standard**. For the purpose of this guide, we will update that store and create one additional.

In our example, the Standard store will represent EEA countries, while the second one, called the Rest of the world, will represent all other countries from Europe and other continents. Store property that we’re interested in is called Allowed Countries. This list consists of all countries, and we will choose those available in our Standard store.

We will do the same for the second store except for the countries we choose in the default one. Other store properties are not important in this guide, and you can configure them based on your project’s specifications.

![CoreShop store configuration named Standard: euro currency, Croatia as base country, allowed countries list](https://factory.dev/wp-content/uploads/2026/11/how_to_coreshop_standard.jpg)

![CoreShop store configuration named Rest of the world: US dollar currency, United States as base country](https://factory.dev/wp-content/uploads/2026/11/how_to_coreshop_rest_of_the_world.jpg)

The first step is to create our **RequestBased Store Context**:

Second, we have to configure the service in **services.yaml**, which can be found in the config folder in your Pimcore project.

**Important note:** Make sure that every dependency that you inject into the class constructor is also defined as an argument.

For country detection based on the user’s IP address, CountryContext uses GeoLiteBasedRequestResolver. To be able to use this resolver, you have to obtain the GeoIP database. Follow the [official instructions](https://dev.maxmind.com/geoip/updating-databases) to do that. Store the database file at the location of your choice. The default location used by geoipupdate is **/usr/share/GeoIP/GeoLite2-City.mmdb**.

Now set the path to the database file in your **parameters.yaml** to enable the geo support. As you can see, I stored the database in the **var/config folder** so make sure you set the correct path depending on the location of your file.

Since we configured config files, make sure to delete the cache to apply the changes.

## Does it work?

Due to **GeoLiteBasedRequestResolver** detecting private IP addresses (localhost is one of them), testing this feature on your local environment can seem tricky, but it’s not impossible.

What I would do — find the GeoLiteBasedRequestResolver file in **CoreShop\\Component\\Address\\Context\\RequestBased** in vendor files and simply change the **$clientIp** variable in the **findCountry** method to the desired IP address.

![PHP code that sets a fixed client IP and throws CountryNotFoundException for private IP addresses](https://factory.dev/wp-content/uploads/2026/11/coreshop_clientip.jpg)

Now, if you open your project in the browser and show the Symfony toolbar, you should see **information about the country and store**. You can see an example in the screenshot below.

![Symfony debug toolbar showing an empty cart, country Croatia, store Standard and currency Euro](https://factory.dev/wp-content/uploads/2026/11/symfony-toolbar.jpg)

**Do you have more questions or issues while implementing this? Feel free to contact us; we’d be happy to help!**

## Related

[Pimcore guides &amp; How to **Pimcore Studio Setup Guide: Backend &amp; Infrastructure for Developers** Step-by-step overview of Pimcore Studio backend setup, including required services, DDEV configuration, bundle installation, indexing, and production considerations. 34 min read](https://factory.dev/pimcore-knowledge-base/tutorial/pimcore-studio-setup-guide-backend-infrastructure) [Pimcore guides &amp; How to **Customizing Pimcore Classification Store: Removing Grid View Duplicates and Simplifying DataHub Imports** Shared Classification Store attributes can clutter Pimcore grid views and make DataHub imports harder to maintain. This article shows how a custom implementation creates one logical attribute view… 10 min read](https://factory.dev/pimcore-knowledge-base/how-to/customizing-pimcore-classification-store) [Pimcore guides &amp; How to **Using named API routes in separated Vue CLI generated Applications** Discover how to use named, and exposed routes via Symfony FOSJsRoutingBundle in separated Vue CLI generated Applications. 2 min read](https://factory.dev/pimcore-knowledge-base/how-to/named-api-routes-in-separated-vue-cli-generated-applications)

---

Source: https://factory.dev/pimcore-knowledge-base/how-to/creating-custom-countrybased-store-context-resolver-coreshop
