setono/sylius-algolia-plugin

Sylius 商店集成 Algolia

资助包维护!
Setono

安装数: 1,125

依赖者: 0

建议者: 0

安全性: 0

星标: 4

关注者: 1

分支: 0

开放问题: 12

类型:sylius-plugin

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

This package is auto-updated.

Last update: 2024-09-18 08:13:56 UTC


README

Latest Version Software License Build Status Code Coverage

在您的 Sylius 商店中使用 Algolia 搜索和建议。

安装

composer require setono/sylius-algolia-plugin

导入配置

# 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'

在您的 .env.local 中添加您的参数

###> 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 ###

导入路由

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

或者如果您的应用程序不使用区域设置

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

将插件类移动到您的 bundles.php

将插件移动到您的捆绑列表顶部,否则您可能会遇到如 您请求了一个不存在的参数 "setono_sylius_algolia.cache.adapter" 的异常

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

在您的配置资源中实现 IndexableInterface

您必须在 setono_sylius_algolia.indexable_resources 中配置的索引资源中实现 Setono\SyliusAlgoliaPlugin\Model\IndexableInterface。在一个典型的 Sylius 应用程序中,对于 Product 实体,它可能看起来像这样

<?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;
}

在适用的存储库中实现 IndexableResourceRepositoryInterface

配置的索引资源相关联的存储库必须实现 Setono\SyliusAlgoliaPlugin\Repository\IndexableResourceRepositoryInterface。如果您正在配置 sylius.product,有一个可用的特性您可以使用:Setono\SyliusAlgoliaPlugin\Repository\ProductRepositoryTrait

用法

待办事项