GENERAL
BACKEND
FRONTEND
ADDITIONAL
Note: This Plugin supports ElasticSearch 7.0 and above. If you're looking for ElasticSearch Plugin for older versions check SyliusElasticSearchPlugin in version 1.x.
We work on stable, supported and up-to-date versions of packages. We recommend you to do the same.
Package | Version |
---|---|
PHP | >=8.1 |
sylius/sylius | 1.12.x - 1.13.x |
MySQL | >= 5.7 |
NodeJS | >= 18.x |
ElasticSearch | >= 7.x |
composer require bitbag/elasticsearch-plugin --no-scripts
Add plugin dependencies to your config/bundles.php
file:
# config/bundles.php
return [
...
FOS\ElasticaBundle\FOSElasticaBundle::class => ['all' => true],
BitBag\SyliusElasticsearchPlugin\BitBagSyliusElasticsearchPlugin::class => ['all' => true],
];
Import required config in your config/packages/_sylius.yaml
file:
# config/packages/_sylius.yaml
imports:
...
- { resource: "@BitBagSyliusElasticsearchPlugin/Resources/config/config.yml" }
Import routing on top of your config/routes.yaml
file:
# config/routes.yaml
bitbag_sylius_elasticsearch_plugin:
resource: "@BitBagSyliusElasticsearchPlugin/Resources/config/routing.yml"
...and set up the redirection from the default Sylius shop products index page on top of your config/routes/sylius_shop.yaml file.
# config/routes/sylius_shop.yaml
redirect_sylius_shop_product_index:
path: /{_locale}/taxons/{slug}
controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction
defaults:
route: bitbag_sylius_elasticsearch_plugin_shop_list_products
permanent: true
requirements:
_locale: ^[a-z]{2}(?:_[A-Z]{2})?$
slug: .+
Remove the default ElasticSearch index (app
) defined by FOSElasticaBundle
in config/packages/fos_elastica.yaml
:
# config/packages/fos_elastica.yaml
fos_elastica:
clients:
default: { url: '%env(ELASTICSEARCH_URL)%' }
indexes:
app: ~
should become:
fos_elastica:
clients:
default: { url: '%env(ELASTICSEARCH_URL)%' }
Use BitBag\SyliusElasticsearchPlugin\Model\ProductVariantTrait
and BitBag\SyliusElasticsearchPlugin\Model\ProductVariantInterface
in an overridden ProductVariant entity class.
The configuration, depending on the mapping used, may vary.
bin/console assets:install
bin/console cache:clear
bin/console fos:elastica:populate
Note: If you are running it on production, add the -e prod
flag to this command. Elastic are created with environment suffix.
Please setup your webpack.config.js
file to require the plugin's webpack configuration. To do so, please put the line below somewhere on top of your webpack.config.js file:
const [ bitbagElasticSearchShop ] = require('./vendor/bitbag/elasticsearch-plugin/webpack.config.js')
As next step, please add the imported consts into final module exports:
module.exports = [..., bitbagElasticSearchShop];
Add the asset configuration into config/packages/assets.yaml
:
framework:
assets:
packages:
...
elasticsearch_shop:
json_manifest_path: '%kernel.project_dir%/public/build/bitbag/elasticsearch/shop/manifest.json'
Add the webpack configuration into config/packages/webpack_encore.yaml
:
webpack_encore:
output_path: '%kernel.project_dir%/public/build/default'
builds:
...
elasticsearch_shop: '%kernel.project_dir%/public/build/bitbag/elasticsearch/shop'
Add encore functions to your templates:
SyliusShopBundle:
{# @SyliusShopBundle/_scripts.html.twig #}
{{ encore_entry_script_tags('bitbag-elasticsearch-shop', null, 'elasticsearch_shop') }}
{# @SyliusShopBundle/_styles.html.twig #}
{{ encore_entry_link_tags('bitbag-elasticsearch-shop', null, 'elasticsearch_shop') }}
yarn install
yarn encore dev # or prod, depends on your environment
Elasticsearch's port settings can be found in the .env
file.
###> friendsofsymfony/elastica-bundle ###
ELASTICSEARCH_URL=http://localhost:9200/
###< friendsofsymfony/elastica-bundle ###
For incorrectly displayed translations, execute the command:
bin/console cache:clear