Copied!

CatalogResolveEvent

CatalogResolveEvent.php : 53
Extends Event

Event allowing to customize the catalog resolving logic.

The following example assigns employees catalog to users with email ending with '[at]ibexa.co':

namespace App\EventSubscriber;

use Ibexa\Contracts\ProductCatalog\CatalogServiceInterface;
use Ibexa\Contracts\Storefront\Repository\Event\CatalogResolveEvent;
use Ibexa\Contracts\Storefront\Menu\Event\ConfigureMenuEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

final readonly class CatalogSubscriber implements EventSubscriberInterface
{
   public function __construct(
       private CatalogServiceInterface $catalogService
   ) }

   public static function getSubscribedEvents(): array
   {
       return [
           CatalogResolveEvent::class => 'onCatalogResolve',
       ];
   }

   public function onCatalogResolve(CatalogResolveEvent $event): void
   {
       if (str_ends_with($event->getUser()->email, '[at]ibexa.co')) {
            // Custom catalog for Ibexa employees
            $event->setCatalog($this->catalogService->getCatalogByIdentifier('employees'));
       }
   }
}
Tags
See
CatalogResolverInterface

Methods

public__construct()

CatalogResolveEvent.php : 59
public __construct(User $user, CatalogInterface|null $catalog)

Parameters

Name Type Default value Description
$user User - -
$catalog CatalogInterface|null - -

publicgetCatalog()

CatalogResolveEvent.php : 73
public getCatalog() : CatalogInterface|null

Return values

CatalogInterface|null

publicgetUser()

CatalogResolveEvent.php : 68

Returns the user for which the catalog is resolved.

public getUser() : User

Return values

User

publicisPropagationStopped()

Event.php : 38
public isPropagationStopped() : bool

Return values

bool

publicsetCatalog()

CatalogResolveEvent.php : 78
public setCatalog(CatalogInterface|null $catalog) : void

Parameters

Name Type Default value Description
$catalog CatalogInterface|null - -

publicstopPropagation()

Event.php : 50

Stops the propagation of the event to further event listeners.

public stopPropagation() : void

If multiple event listeners are connected to the same event, no further event listener will be triggered once any trigger calls stopPropagation().