{"id":27166279,"url":"https://github.com/code-rhapsodie/syliusextendedelasticsearchplugin","last_synced_at":"2025-04-09T03:39:08.452Z","repository":{"id":54784315,"uuid":"318483225","full_name":"code-rhapsodie/SyliusExtendedElasticsearchPlugin","owner":"code-rhapsodie","description":null,"archived":false,"fork":false,"pushed_at":"2021-02-01T11:13:25.000Z","size":268,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2023-04-27T11:28:55.536Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/code-rhapsodie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-04T10:35:14.000Z","updated_at":"2021-01-11T10:22:16.000Z","dependencies_parsed_at":"2022-08-14T02:51:27.640Z","dependency_job_id":null,"html_url":"https://github.com/code-rhapsodie/SyliusExtendedElasticsearchPlugin","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-rhapsodie%2FSyliusExtendedElasticsearchPlugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-rhapsodie%2FSyliusExtendedElasticsearchPlugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-rhapsodie%2FSyliusExtendedElasticsearchPlugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code-rhapsodie%2FSyliusExtendedElasticsearchPlugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/code-rhapsodie","download_url":"https://codeload.github.com/code-rhapsodie/SyliusExtendedElasticsearchPlugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247974590,"owners_count":21026742,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-09T03:39:07.830Z","updated_at":"2025-04-09T03:39:08.444Z","avatar_url":"https://github.com/code-rhapsodie.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Code Rhapsodie SyliusExtendedElasticsearchPlugin\n\nWorking [Sylius](https://sylius.com/) [Elasticsearch](https://www.elastic.co/products/elasticsearch) integration based on [FOSElasticaBundle](https://github.com/FriendsOfSymfony/FOSElasticaBundle). The main goal of this plugin is to support filtering products by \noptions, attributes, taxons, channels and name in the front product list page. It totally replaces the default Sylius `sylius_shop_product_index`\nroute.\n\nWhat is more, the plugin has a nice Sylius-oriented architecture that allows mapping resources to the Elastic document easier. It is flexible as well,\nso that you can customize the existing features for your specific business needs.   \n\nThis project is based on [BitBag SyliusElasticsearchPlugin](https://github.com/BitBagCommerce/SyliusElasticsearchPlugin)\n\n## Installation\n\n*Note*: This Plugin currently supports ElasticSearch 5.3.x up to 6.8.x.  ElasticSearch ^7.x is not currently supported.\n\n```bash\n$ composer require code-rhapsodie/extended-elasticsearch-plugin\n```\n    \n    \nAdd plugin dependencies to your `config/bundles.php` file:\n```php\nreturn [\n    ...\n\n    FOS\\ElasticaBundle\\FOSElasticaBundle::class =\u003e ['all' =\u003e true],\n    CodeRhapsodie\\SyliusExtendedElasticsearchPlugin\\CodeRhapsodieSyliusExtendedElasticsearchPlugin::class =\u003e ['all' =\u003e true],\n];\n```\n\nImport required config in your `config/packages/_sylius.yaml` file:\n```yaml\n# config/packages/_sylius.yaml\n\nimports:\n    ...\n    \n    - { resource: \"@CodeRhapsodieSyliusExtendedElasticsearchPlugin/Resources/config/config.yml\" }\n```\n\nImport routing **on top** of your `config/routes.yaml` file:\n```yaml\n# config/routes.yaml\n\ncr_sylius_extended_elasticsearch_plugin:\n    resource: \"@CodeRhapsodieSyliusExtendedElasticsearchPlugin/Resources/config/routing.yml\"\n```\n\nCreate a file named `bit_bag_sylius_elasticsearch.yaml` in `config/packages` \nin which you will add this code to have the default configuration services : \n```\ncode_rhapsodie_sylius_extended_elasticsearch:\n    excluded_filter:\n        options: ['option1']\n        attributes: ['attribute1']\n    filter_attributes_max: 30\n    filter_options_max: 30\n```\n\n\n...and set up the redirection from the default Sylius shop products index page on top of your `config/routes/sylius_shop.yaml`\nfile.\n```\n# config/routes/sylius_shop.yaml\n\nredirect_sylius_shop_product_index:\n    path: /{_locale}/taxons/{slug}\n    controller: Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController::redirectAction\n    defaults:\n        route: cr_sylius_extended_elasticsearch_plugin_shop_list_products\n        permanent: true\n    requirements:\n        _locale: ^[a-z]{2}(?:_[A-Z]{2})?$\n        slug: .+\n```\n...and update installed assets with the following command:\n```\n$ bin/console assets:install\n```\n...and remove the default ElasticSearch index (`app`) defined by `FOSElasticaBundle` in `config/packages/fos_elastica.yaml`:\n```\n\nfos_elastica:\n    clients:\n        default: { host: localhost, port: 9200 }\n    indexes:\n        app: ~\n```\nshould become:\n```\n\nfos_elastica:\n    clients:\n        default: { host: localhost, port: 9200 }\n```\nIn the end, with an elasticsearch server running, execute following command:\n```\n$ bin/console fos:elastica:populate\n```\n\n**Note:** If you are running it on production, add the `-e prod` flag to this command. Elastic are created with environment suffix.\n\n## Usage\n\n### Rendering the shop products list\n\nWhen you go now to the `/{_locale}/products/taxon/{slug}` page, you should see a totally new set of filters. You should see something like this:\n\n\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/bitbager/BitBagCommerceAssets/master/BitBagElasticesearchProductIndex.jpg\" /\u003e\n\u003c/div\u003e\n\nYou might also want to refer the horizontal menu to a new product list page. Follow below instructions to do so:\n\n1. If you haven't done it yet, create two files:\n    * `_horizontalMenu.html.twig` in `templates/bundles/SyliusShopBundle/Taxon` directory\n    * `_breadcrumb.html.twig` in `templates/bundles/SyliusShopBundle/Product/Show` directory\n2. Paste into those files content of respectively `vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/Resources/views/Taxon/_horizontalMenu.html.twig` and `vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/Resources/views/Product/Show/_breadcrumb.html.twig` files, replacing `sylius_shop_product_index` with `cr_sylius_extended_elasticsearch_plugin_shop_list_products` in both of them.\n3. Clean your cache with `bin/console cache:clear` command.\n4. :tada:\n\nIf you're using vertical menu - follow steps above with `_verticalMenu.html.twig` file instead. It's in the same directory as the `horizontal_menu.html.twig` file.\n\n**Be aware! Elasticsearch does not handle dashes well. This plugin depends on the code field in Sylius resources. Please use underscores instead of dashes in your code fields.**\n\n### Excluding options and attributes in the filter menu\n\nYou might not want to show some specific options or attributes in the menu. You can set specific parameters for that:\n```yml\nparameters:\n    cr_ees_excluded_filter_options: []\n    cr_ees_excluded_filter_attributes: ['book_isbn', 'book_pages']\n```\n\nBy default all options and attributes are indexed. After you change these parameters, remember to run `bin/console fo:el:po` command again\n(a shortcut for `fos:elastica:populate`).\n\n### Exclude attributes and options dynamically from the search filter \n\nTo allow dynamic exclusion of product attributes (or product options) in admin menu page, the `App\\Entity\\Product\\ProductAttribute` class must implement the` CodeRhapsodie\\SyliusExtendedElasticsearchPlugin\\Finder\\FinderExcludable`interface\nFor example:\n\n```\n\u003c?php\n//...\nuse CodeRhapsodie\\SyliusExtendedElasticsearchPlugin\\Finder\\FinderExcludable\n\nclass ProductAttribute implements FinderExcludable\n{\n    //...\n}\n```\n\nIf it's not the case (`ProductAttribute` doesn't implement `FinderExcludable`), the product attribute exclusion menu list will not be visible and will not appear.\n\nIt works the same way if you want to allow dynamic exclusion of product options\n\n\n\n\n\n### Reindexing\n\nBy default, current indexes listen on all Doctrine events. You can override this setting for each index by overriding index definition in your `config.yml` file:\n```yml\nfos_elastica:\n    indexes:\n        bitbag_attribute_taxons:\n            types:\n                default:\n                    persistence:\n                        listener:\n                            insert: true\n                            update: false\n                            delete: true\n```\n\nIndexes with `bitbag_shop_product`, `bitbag_attribute_taxons` and `bitbag_option_taxons` keys are available so far.\n\n### Site-wide search\n\nThis plugin offers a site-wide search feature as well. You have a search box field where you query all products indexed on ElasticSearch. When you enter a query in the search box the results will appear in the search results page.\n\nYou can also add search facets (a.k.a. filters) to your search results page. To do so you have to add facets to the `cr_sylius_extended_elasticsearch_plugin.facet.registry` service (see an example of this service definition [here](https://github.com/code-rhapsodie/SyliusExtendedElasticsearchPlugin/blob/master/tests/Application/config/services.yaml)). A facet is a service which implements the `CodeRhapsodie\\SyliusExtendedElasticsearchPlugin\\Facet\\FacetInterface`. You can implement your own facets from scratch or you can [decorate](https://symfony.com/doc/current/service_container/service_decoration.html) one of the basic facet implementation included in this plugin, which are:\n\n* [`TaxonFacet`](https://github.com/code-rhapsodie/SyliusExtendedElasticsearchPlugin/blob/master/src/Facet/TaxonFacet.php) which allows to filter your search results by taxons using the ElasticSearch [`Terms`](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html) aggregation.\n* [`AttributeFacet`](https://github.com/code-rhapsodie/SyliusExtendedElasticsearchPlugin/blob/master/src/Facet/AttributeFacet.php) which allows to filter your search results by product attributes values using the ElasticSearch [`Terms`](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html) aggregation.\n* [`OptionFacet`](https://github.com/code-rhapsodie/SyliusExtendedElasticsearchPlugin/blob/master/src/Facet/OptionFacet.php) which is the same as `AttributeFacet` but for product options.\n* [`PriceFacet`](https://github.com/code-rhapsodie/SyliusExtendedElasticsearchPlugin/blob/master/src/Facet/PriceFacet.php) which allows to filter search results by price range the ElasticSearch [`Histogram`](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html) aggregation.\n\nYou can see an example of the definition of all of these facets [here](https://github.com/code-rhapsodie/SyliusExtendedElasticsearchPlugin/blob/master/tests/Application/config/services.yaml).\n\n## Customization\n\n### Available services you can [decorate](https://symfony.com/doc/current/service_container/service_decoration.html) and forms you can [extend](http://symfony.com/doc/current/form/create_form_type_extension.html)\n```bash\n$ bin/console debug:container | grep cr_sylius_extendedelasticsearch_plugin\n```\n\n### Parameters you can override in your parameters.yml(.dist) file\n```bash\n$ bin/console debug:container --parameters | grep cr_ees_\n```\n\n## Testing\n```bash\n$ composer install\n$ cd tests/Application\n$ yarn install\n$ yarn build\n$ bin/console assets:install public -e test\n$ bin/console doctrine:schema:create -e test\n$ bin/console server:run 127.0.0.1:8080 -d public -e test\n$ elasticsearch\n$ open http://localhost:8080\n$ vendor/bin/behat\n$ vendor/bin/phpspec run\n```\n\n## Contribution\n\nLearn more about our contribution workflow on http://docs.sylius.org/en/latest/contributing/.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-rhapsodie%2Fsyliusextendedelasticsearchplugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcode-rhapsodie%2Fsyliusextendedelasticsearchplugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode-rhapsodie%2Fsyliusextendedelasticsearchplugin/lists"}