-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8884a95
commit 361606a
Showing
6 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Add custom values to your indexed entity | ||
|
||
## Add custom value for a product | ||
|
||
In our example we will add the `short_description` product field to the indexed content. | ||
|
||
First, declares your services : | ||
|
||
```yaml | ||
App\Search\EventListener\AppendProductMappingSubscriber: | ||
autoconfigure: true | ||
|
||
App\Search\Automapper\DecorateProductMapperConfiguration: | ||
autowire: true | ||
decorates: MonsieurBiz\SyliusSearchPlugin\AutoMapper\ProductMapperConfiguration | ||
arguments: | ||
- '@.inner' | ||
``` | ||
```php | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Search\EventListener; | ||
|
||
use MonsieurBiz\SyliusSearchPlugin\Event\MappingProviderEvent; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
final class AppendProductMappingSubscriber implements EventSubscriberInterface | ||
{ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
MappingProviderEvent::EVENT_NAME => 'onMappingProvider', | ||
]; | ||
} | ||
|
||
public function onMappingProvider(MappingProviderEvent $event): void | ||
{ | ||
// We work on products, ignore the rest | ||
if ('monsieurbiz_product' !== $event->getIndexCode()) { | ||
return; | ||
} | ||
|
||
$mapping = $event->getMapping(); | ||
if (null === $mapping || !$mapping->offsetExists('mappings')) { | ||
return; | ||
} | ||
|
||
$mappings['properties']['short_description'] = [ | ||
'type' => 'text', | ||
]; | ||
|
||
$mapping->offsetSet('mappings', $mappings); | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# SyliusSearchPlugin | ||
|
||
@TODO Description | ||
|
||
## Menu | ||
|
||
- [Add custom sorts](./add_custom_sorts.md) | ||
- [Add custom values](./add_custom_values.md) | ||
- [Index custom entities](./index_custom_entities.md) | ||
- [Nested fields limit](./nested_fields_limit.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
@TODO | ||
|
||
```php | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Search\EventListener; | ||
|
||
use MonsieurBiz\SyliusSearchPlugin\Event\MappingProviderEvent; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
final class AppendProductMappingSubscriber implements EventSubscriberInterface | ||
{ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
MappingProviderEvent::EVENT_NAME => 'onMappingProvider', | ||
]; | ||
} | ||
|
||
public function onMappingProvider(MappingProviderEvent $event): void | ||
{ | ||
if ('monsieurbiz_product' !== $event->getIndexCode()) { | ||
return; | ||
} | ||
|
||
$mapping = $event->getMapping(); | ||
if (null === $mapping || !$mapping->offsetExists('mappings')) { | ||
return; | ||
} | ||
|
||
$settings = $mapping->offsetGet('settings') ?? []; | ||
$mapping->offsetSet('settings', array_merge($settings, ['mapping.nested_fields.limit' => 100])); // Increase the limit of nested fields | ||
} | ||
} | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.