setono/sylius-algolia-plugin

Algolia integration for your Sylius store

Fund package maintenance!
Setono

Installs: 1 115

Dependents: 0

Suggesters: 0

Security: 0

Stars: 4

Watchers: 1

Forks: 0

Open Issues: 11

Type:sylius-plugin

v0.1.1 2022-05-24 11:49 UTC

This package is auto-updated.

Last update: 2024-02-19 14:04:40 UTC


README

Latest Version Software License Build Status Code Coverage

Use Algolia search and recommendations in your Sylius store.

Installation

composer require setono/sylius-algolia-plugin

Import configuration

# config/packages/setono_sylius_algolia.yaml
imports:
    - { resource: "@SetonoSyliusAlgoliaPlugin/Resources/config/app/config.yaml" }

setono_sylius_algolia:
    credentials:
        app_id: '%env(ALGOLIA_APP_ID)%'
        search_only_api_key: '%env(ALGOLIA_SEARCH_ONLY_API_KEY)%'
        admin_api_key: '%env(ALGOLIA_ADMIN_API_KEY)%'
    indexes:
        products:
            document: 'Setono\SyliusAlgoliaPlugin\Document\Product'
            resources: [ 'sylius.product' ]
        taxons:
            document: 'Setono\SyliusAlgoliaPlugin\Document\Taxon'
            resources: [ 'sylius.taxon' ]
    search:
        indexes:
            - 'products'

In your .env.local add your parameters:

###> setono/sylius-algolia-plugin ###
ALGOLIA_APP_ID=YOUR_APPLICATION_ID
ALGOLIA_ADMIN_API_KEY=YOUR_ADMIN_API_KEY
ALGOLIA_SEARCH_ONLY_API_KEY=YOUR_SEARCH_ONLY_KEY
###< setono/sylius-algolia-plugin ###

Import routing

# config/routes/setono_sylius_algolia.yaml
setono_sylius_algolia:
    resource: "@SetonoSyliusAlgoliaPlugin/Resources/config/routes.yaml"

or if your app doesn't use locales:

# config/routes/setono_sylius_algolia.yaml
setono_sylius_algolia:
    resource: "@SetonoSyliusAlgoliaPlugin/Resources/config/routes_no_locale.yaml"

Move plugin class in your bundles.php

Move the plugin at the top of your bundles list, else you might have an exception like You have requested a non-existent parameter "setono_sylius_algolia.cache.adapter"

<?php
$bundles = [
    Setono\SyliusAlgoliaPlugin\SetonoSyliusAlgoliaPlugin::class => ['all' => true],
    // ...
];

Implement the IndexableInterface in your configured indexable resources

You have to implement the Setono\SyliusAlgoliaPlugin\Model\IndexableInterface in the indexable resources you configured in setono_sylius_algolia.indexable_resources. In a typical Sylius application for the Product entity it could look like this:

<?php
declare(strict_types=1);

namespace App\Entity\Product;

use Doctrine\ORM\Mapping as ORM;
use Setono\SyliusAlgoliaPlugin\Model\IndexableAwareTrait;
use Setono\SyliusAlgoliaPlugin\Model\IndexableInterface;
use Sylius\Component\Core\Model\Product as BaseProduct;

/**
 * @ORM\Entity
 * @ORM\Table(name="sylius_product")
 */
class Product extends BaseProduct implements IndexableInterface
{
    use IndexableAwareTrait;
}

Implement the IndexableResourceRepositoryInterface in applicable repositories

The configured indexable resources' associated repositories has to implement the Setono\SyliusAlgoliaPlugin\Repository\IndexableResourceRepositoryInterface. If you're configuring the sylius.product there is a trait available you can use: Setono\SyliusAlgoliaPlugin\Repository\ProductRepositoryTrait.

Usage

TODO