public function onProductIndex(ResourceControllerEvent $event): void
    {
        $currentRequest = $this->requestStack->getCurrentRequest();
        if (!$currentRequest instanceof Request) {
            return;
        }

        // Only sane way to extract the reference to the taxon
        if (!$currentRequest->attributes->has('slug')) {
            return;
        }

        $taxon = $this->taxonRepository->findOneBySlug(
            $currentRequest->attributes->get('slug'),
            $this->localeContext->getLocaleCode()
        );

        if (!$taxon instanceof TaxonInterface) {
            return;
        }

        $currentRequest->attributes->set('nglayouts_sylius_taxon', $taxon);
        // We set context here instead in a ContextProvider, since sylius.taxon.show
        // event happens too late, after onKernelRequest event has already been executed
        $this->context->set('sylius_taxon_id', (int) $taxon->getId());
    }
public function onProductIndex(ResourceControllerEvent $event): void
    {
        $currentRequest = $this->requestStack->getCurrentRequest();
        if (!$currentRequest instanceof Request) {
            return;
        }

        // Only sane way to extract the reference to the taxon
        if (!$currentRequest->attributes->has('slug')) {
            return;
        }

        $taxon = $this->taxonRepository->findOneBySlug(
            $currentRequest->attributes->get('slug'),
            $this->localeContext->getLocaleCode()
        );

        if (!$taxon instanceof TaxonInterface) {
            return;
        }

        $currentRequest->attributes->set('nglayouts_sylius_taxon', $taxon);
        // We set context here instead in a ContextProvider, since sylius.taxon.show
        // event happens too late, after onKernelRequest event has already been executed
        $this->context->set('sylius_taxon_id', (int) $taxon->getId());
    }
public function onProductIndex ( ResourceControllerEvent $ event ) : void { $ currentRequest = $ this -> requestStack -> getCurrentRequest ( ) ; if ( ! $ currentRequest instanceof Request ) { return ; } // Only sane way to extract the reference to the taxon if ( ! $ currentRequest -> attributes -> has ( 'slug' ) ) { return ; } $ taxon = $ this -> taxonRepository -> findOneBySlug ( $ currentRequest -> attributes -> get ( 'slug' ) , $ this -> localeContext -> getLocaleCode ( ) ) ; if ( ! $ taxon instanceof TaxonInterface ) { return ; } $ currentRequest -> attributes -> set ( 'nglayouts_sylius_taxon' , $ taxon ) ; // We set context here instead in a ContextProvider, since sylius.taxon.show // event happens too late, after onKernelRequest event has already been executed $ this -> context -> set ( 'sylius_taxon_id' , ( int ) $ taxon -> getId ( ) ) ; }
Sets the currently displayed taxon to the request,
to be able to match with layout resolver.
Sets the currently displayed taxon to the request to be able to match with layout resolver .