bitbull / magento-2-tooso-search
Tooso 集成模块,适用于 Magento 2
Requires
- php: ~7.0.0|~7.1.0|~7.2.0|~7.3.0
- ext-json: *
- bitbull/tooso-sdk: 1.3.*
- magento/framework: 101.0.*|102.0.*
- magento/module-catalog-search: ^100.2.4|101.0.*
- dev-master
- 1.8.1
- 1.8.1-rc
- 1.8.0-rc
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.1
- 1.6.0
- 1.5.0
- 1.4.0
- 1.3.8
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.2
- 1.0.1
- 1.0.0
- dev-develop
- dev-feature/fix-page-tracking-first-landing
- dev-feature/external-custom-integrations
- dev-use-proxy-instead-of-factory
This package is auto-updated.
Last update: 2024-08-29 04:54:37 UTC
README
Tooso 是一款基于云的多语言电子商务搜索工具。
此扩展将 Magento 的默认搜索替换为 Tooso 支持的容错、快速且相关的搜索体验。
描述
此扩展将默认的 Magento 搜索引擎替换为基于 Tooso API 的搜索引擎。它提供以下功能
- 目录产品全文搜索(目前不支持高级搜索)
- 目录产品计划索引(开发中)
- 自动错别字纠正(开发中)
- 搜索关键词建议(开发中)
要求
- PHP > 7.0
- Composer
- Magento >= 2.2.6
安装说明
最新版本
使用 composer 安装最新版本
composer require bitbull/magento-2-tooso-search
特定版本
使用 composer 安装特定版本
composer require bitbull/magento-2-tooso-search:1.0.0
开发版本
设置 "minimum-stability" 为 "dev" 并关闭 "prefer-stable" 配置
composer config minimum-stability dev
composer config prefer-stable false
使用 composer 安装最新开发版本
composer require bitbull/magento-2-tooso-search:dev-develop
模块配置
请求您的 API 密钥
发送电子邮件至 info@tooso.ai 请求您的 API 密钥
设置您的 API 密钥
- 在 API 配置 下
- 将您的 API 密钥输入到 API 密钥 字段
- 将 http://v{apiVersionWithNoDot}.api.tooso.ai 输入到 API 基础 URL 字段。当前支持的版本是 1,因此占位符 {apiVersionWithNoDot} 应替换为 1。
- 发送报告:将 YES 设置为在发生 API 错误时向 Tooso 发送报告
- 调试模式:将 Yes 设置为启用更详细的日志记录,以便进行调试
- 保存配置
以编程方式使用 Tooso 服务
如果您想调用当前插件不支持的服务,我们建议此配置。
在您的类中添加对 Bitbull\Tooso\Api\Service\ClientInterface
的依赖关系,并让 DI 系统完成剩余工作
<?php use Tooso\SDK\ClientBuilder; use Bitbull\Tooso\Api\Service\ConfigInterface; use Bitbull\Tooso\Api\Service\TrackingInterface; use Bitbull\Tooso\Api\Service\LoggerInterface; class MyServiceClass { /** * @var ConfigInterface */ protected $config; /** * @var TrackingInterface */ protected $tracking; /** * @var ClientBuilder */ protected $clientBuilder; /** * @var LoggerInterface */ protected $logger; /** * Search constructor. * * @param ConfigInterface $config * @param TrackingInterface $tracking * @param ClientBuilder $clientBuilder * @param LoggerInterface $logger */ public function __construct( ConfigInterface $config, TrackingInterface $tracking, ClientBuilder $clientBuilder, LoggerInterface $logger ) { $this->config = $config; $this->tracking = $tracking; $this->clientBuilder = $clientBuilder; $this->logger = $logger; } }
使用 Tooso\SDK\ClientBuilder
实例构建客户端实例
<?php /** * Get Client * * @return \Tooso\SDK\Client */ protected function getClient() { return $this->clientBuilder ->withApiKey($this->config->getApiKey()) ->withApiVersion($this->config->getApiVersion()) ->withApiBaseUrl($this->config->getApiBaseUrl()) ->withLanguage($this->config->getLanguage()) ->withStoreCode($this->config->getStoreCode()) ->withAgent($this->tracking->getApiAgent()) //optional ->withLogger($this->logger) //optional ->build(); }
这允许您创建一个 Tooso\SDK\Client
实例,以使用预配置的必需参数对 Tooso API 进行任何 HTTP 调用
<?php /** * Execute service */ protected function execute() { $client = $this->getClient(); $result = $client->doRequest('/path/to/service', \Tooso\SDK\Client::HTTP_METHOD_GET, [ 'param1' => 'value1', 'param2' => 'value2' ]); }
从 doRequest
方法返回的 Tooso\SDK\Response
类型对象中访问响应数据
<?php $result = $client->doRequest('/path/to/service', \Tooso\SDK\Client::HTTP_METHOD_GET, [ 'param1' => 'value1', 'param2' => 'value2' ]); $responseData = $result->getResponse();
所需的主题更改
搜索后产品点击跟踪
为了使搜索后的产品点击跟踪正常工作,前端脚本需要找到具有产品链接的 a
标签上的属性 data-product-sku
。为此,请编辑您的主题文件 view/frontend/templates/product/list.phtml
,在产品列表循环中,按照以下方式
<a href="<?= /* @escapeNotVerified */ $_product->getProductUrl() ?>" data-product-sku="<?= $block->escapeHtml($_product->getSku()) ?>" class="product photo product-item-photo" tabindex="-1"> <?= $productImage->toHtml() ?> </a> <div class="product details product-item-details"> <!-- here the product details -->
如果您使用 AJAX 分页方法(例如无限滚动加载),您还必须在具有产品链接的 a
标签上添加一个属性 data-search-id
。为此,请编辑您的主题文件 view/frontend/templates/product/list.phtml
以从注册表密钥 tooso_search_response
(从 \Bitbull\Tooso\Model\Service\Search
类的常量 SEARCH_RESULT_REGISTRY_KEY
中可用)加载 Tooso 搜索 ID 值,如下所示
<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); /** @var \Tooso\SDK\Search\Result $searchResult */ $searchResult = $objectManager->get('Magento\Framework\Registry')->registry(\Bitbull\Tooso\Model\Service\Search::SEARCH_RESULT_REGISTRY_KEY); ?> <!-- your product collection loop --> <a href="<?= /* @escapeNotVerified */ $_product->getProductUrl() ?>" data-product-sku="<?= $block->escapeHtml($_product->getSku()) ?>" data-search-id="<?= $searchResult->getSearchId() ?>" class="product photo product-item-photo" tabindex="-1"> <?= $productImage->toHtml() ?> </a> <div class="product details product-item-details"> <!-- here the product details -->
显然,这只是一个示例,最好使用依赖注入方法在你的产品列表控制器中注入Magento\Framework\Registry
依赖。
前端建议
此模块可以在搜索输入中提供建议,当你启用此功能时,你必须删除默认的Magento建议系统。为了做到这一点,请从你的模板中删除Magento建议初始化,或覆盖默认模板view/frontend/templates/form.mini.phtml
。从搜索输入中删除此初始化属性
data-mage-init='{"quickSearch":{ "formSelector":"#search_mini_form", "url":"<?= /* @escapeNotVerified */ $helper->getSuggestUrl()?>", "destinationSelector":"#search_autocomplete"} }'
并从模板中删除建议容器
<div id="search_autocomplete" class="search-autocomplete"></div>