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
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
setCatalog() ¶
CatalogResolveEvent.php
:
78
|
|
Parameters
Name | Type | Default value | Description |
---|---|---|---|
$catalog | CatalogInterface|null | - | - |