Skip to content

Commit

Permalink
First draft of docs folder
Browse files Browse the repository at this point in the history
  • Loading branch information
maximehuran committed Jul 24, 2023
1 parent 8884a95 commit 361606a
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/add_custom_sorts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@TODO
58 changes: 58 additions & 0 deletions docs/add_custom_values.md
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);
}
}
```
10 changes: 10 additions & 0 deletions docs/index.md
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)
1 change: 1 addition & 0 deletions docs/index_custom_entities.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@TODO
37 changes: 37 additions & 0 deletions docs/nested_fields_limit.md
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
}
}
```
1 change: 1 addition & 0 deletions src/Resources/public/js/monsieurbiz-search.2f3a873a.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 361606a

Please sign in to comment.