CoreShop Store Context

For CoreShop to determine the current store the visitor or customer comes from it uses a concept called context and context resolver.


Name Priority Tag Description
FixedStoreContext 2 Used for testing purposes
StoreContext 1 Load a store from given request resolver


Name Priority Tag Description
SiteBasedRequestResolver 100 Determines a store by a given pimcore frontend site
PimcoreAdminSiteBasedRequestResolver 200 Determines a store by a given document in backend

These resolver take care about finding the correct store for the current request.

Create a Custom Resolver

A Store Context needs to implement the interface CoreShop\Component\Store\Context\StoreContextInterface. This interface consists of one method called getStore which returns a CoreShop\Component\Store\Model\StoreInterface or throws an CoreShop\Component\Store\Context\StoreNotFoundException.

To register your context, you need to use the tag with an optional priority attribute.

Create a Request based Resolver

CoreShop already implements Request based store context resolver. So if your context depends on the current request, you can create a custom RequestBased resolver. To do that, implement the interface CoreShop\Component\Store\Context\RequestBased\RequestResolverInterface with the method findStore. This method either returns a store or null.

To register this resolver, use the tag: with an optional priority attribute.


We want to a StoreContext to be based on the Pimcore Document. So if we are on site /de, we want to resolve to Store DE, if we are on page /en we want to resolve to Store Store EN:

1: First of all we need to create our RequestBased Store Context:


namespace AppBundle\CoreShop\Store\Context;

use CoreShop\Component\Store\Context\RequestBased\RequestResolverInterface;
use CoreShop\Component\Store\Repository\StoreRepositoryInterface;
use Pimcore\Http\Request\Resolver\DocumentResolver;
use Symfony\Component\HttpFoundation\Request;

final class DocumentBasedRequestRequestResolver implements RequestResolverInterface
     * @var StoreRepositoryInterface
    private $storeRepository;

     * @param StoreRepositoryInterface $storeRepository
    public function __construct(StoreRepositoryInterface $storeRepository)
        $this->storeRepository = $storeRepository;

    public function findStore(Request $request)
        if (substr($request->getPathInfo(), 0, 3) === '/en') {
            return $this->storeRepository->find(1);

        if (substr($request->getPathInfo(), 0, 3) === '/de') {
            return $this->storeRepository->find(2);

        return null;

Now we need to configure the service in src/AppBundle/Resources/config/services.yml

    class: AppBundle\CoreShop\Store\Context\DocumentBasedRequestRequestResolver
      - ''
      - { name:, priority: 300 }

CoreShop now tries to resolve the current Store based on the Pimcore Site we are on.