- Gally version: 2.1.x
- Sylius version: 2.0.x
- Install the
gally/sylius-pluginbundle- Run
composer require gally/sylius-plugin - Add the bundle in
config/bundles.php. You must put it afterSyliusGridBundle[...] Gally\SyliusPlugin\GallySyliusPlugin::class => ['all' => true],
- Import the Gally Sylius bundle configuration by adding the following lines to the imports section of
config/packages/_sylius.yaml- { resource: "@GallySyliusPlugin/Resources/config/config.yml" } - Import admin routes by creating a file
config/routes/gally_admin.yamlgally_admin: resource: "@GallySyliusPlugin/Resources/config/admin_routing.yml" prefix: /admin
- Import shop routes by creating a file
config/routes/gally_shop.yamlgally_shop: resource: "@GallySyliusPlugin/Resources/config/shop_routing.yml" prefix: /{_locale}
- Implement the
Gally\SyliusPlugin\Model\GallyChannelInterfaceandGally\SyliusPlugin\Model\GallyChannelTraitin your Channel Entitysrc/App/Entity/Channel/Channel.php.
<?php declare(strict_types=1); namespace App\Entity\Channel; use Doctrine\ORM\Mapping as ORM; use Gally\SyliusPlugin\Model\GallyChannelInterface; use Gally\SyliusPlugin\Model\GallyChannelTrait; use Sylius\Component\Core\Model\Channel as BaseChannel; #[ORM\Entity] #[ORM\Table(name: 'sylius_channel')] class Channel extends BaseChannel implements GallyChannelInterface { use GallyChannelTrait; }
- Install assets via Webpack Encore:
- Add the plugin and its JS SDK as npm dependencies in your app's
package.json:{ "dependencies": { "@gally/sylius-plugin": "link:vendor/gally/sylius-plugin", "@elastic-suite/gally-sdk": "2.2.2-alpha.0" } }Why
link:instead offile:?
Yarn v1 has a known bug withfile:local packages that declare their own npm dependencies (such as@elastic-suite/gally-sdk): it tries to scan anode_modulesfolder inside its cache copy of the package, which does not exist, causing anEACCES/ENOENTerror.
Usinglink:creates a simple symlink tovendor/gally/sylius-pluginwithout going through the cache.@elastic-suite/gally-sdkmust then be declared explicitly at the root level so that webpack can resolve it.Development only: if you are working on the plugin sources directly (i.e. pointing to
link:packages/GallyPlugininstead oflink:vendor/gally/sylius-plugin), you must also add apostinstallscript to build the@elastic-suite/gally-sdkdist files, which are not pre-compiled on the GitHub branch:{ "scripts": { "postinstall": "cd node_modules/@elastic-suite/gally-sdk && yarn install" } } - Add the Gally shop entry point and the SDK IIFE copy in your app's
webpack.config.js:Encore // ... your existing shop config .addEntry('gally-shop-entry', './vendor/gally/sylius-plugin/src/Resources/assets/shop/entrypoint.js') .copyFiles({ from: './node_modules/@elastic-suite/gally-sdk/dist/browser/iife', to: 'gally/[name].[ext]', pattern: /gally-sdk\.global\.js/, }) ;
The
copyFiles()call exposesgally-sdk.global.jsas a standalone IIFE script (available aswindow.GallySDK) for use in Twig templates via{{ asset('build/app/shop/gally/gally-sdk.global.js') }}. - Register the plugin's Stimulus controllers in your app's root
assets/controllers.json:{ "controllers": { "@gally/sylius-plugin": { "range-slider": { "main": "src/Resources/assets/shop/controllers/RangeSliderController.js", "enabled": true, "fetch": "eager" }, "search-autocomplete": { "main": "src/Resources/assets/shop/controllers/SearchAutocompleteController.js", "enabled": true, "fetch": "eager" }, "search-bar-mover": { "main": "src/Resources/assets/shop/controllers/SearchBarMoverController.js", "enabled": true, "fetch": "eager" }, "view-more": { "main": "src/Resources/assets/shop/controllers/ViewMoreController.js", "enabled": true, "fetch": "eager" } } } }This step is required because
@gally/sylius-pluginis installed as a localpathrepository rather than a real registered npm/Symfony UX package: Symfony Flex normally adds a package's Stimulus controllers to your app'sassets/controllers.jsonautomatically via that package's recipe when you runcomposer require, but localpathpackages have no such recipe. This entry must therefore mirror thesymfony.controllerssection of the plugin's ownpackage.jsonand be kept in sync manually if a future version of the plugin adds, renames, or removes a controller. - Install JS dependencies and build assets:
- Without Docker (from the Sylius root directory):
yarn install yarn build
- With Docker (via the
nodejscontainer):docker compose run --rm nodejs
The
nodejscontainer automatically runsyarn install && yarn buildand mounts the project into/srv/sylius.
- Without Docker (from the Sylius root directory):
- Add the plugin and its JS SDK as npm dependencies in your app's
- Run
php bin/console doctrine:migrations:migrateto update the database schema - Open Sylius Admin, head to Configuration > Gally and configure the Gally endpoint (URL, credentials), after that enable Gally on your channel (Configuration > Channel > Edit)
- Run
- Run this commands from your Sylius instance. This commands must be runned only once to synchronize the structure.
bin/console gally:structure:sync # Sync catalog et source field data with gally - Run a full index from Sylius to Gally. This command can be run only once. Afterwards, the modified products are automatically synchronized.
bin/console gally:index # Index category and product entity to gally - At this step, you should be able to see your product and source field in the Gally backend.
- They should also appear in your Sylius frontend when searching or browsing categories.
- And you're done !
- You can also run the command to clean data that are not present in sylius anymore:
bin/console gally:structure:clean
This bundle includes the noUiSlider distribution files. noUiSlider is "a lightweight, ARIA-accessible JavaScript range slider with multi-touch and keyboard support" which is used in this project for the price slider implementation.