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
Methods¶
__construct() ¶
CatalogResolveEvent.php
:
59
|
|
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$user | User | - | - |
$catalog | CatalogInterface|null | - | - |
getCatalog() ¶
CatalogResolveEvent.php
:
73
|
|
Return values
CatalogInterface|null
getUser() ¶
CatalogResolveEvent.php
:
68
Returns the user for which the catalog is resolved.
|
|
Return values
isPropagationStopped() ¶
Event.php
:
38
|
|
Return values
bool
setCatalog() ¶
CatalogResolveEvent.php
:
78
|
|
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$catalog | CatalogInterface|null | - | - |
stopPropagation() ¶
Event.php
:
50
Stops the propagation of the event to further event listeners.
|
|
If multiple event listeners are connected to the same event, no further event listener will be triggered once any trigger calls stopPropagation().