fond-of-spryker / google-custom-search
在Spryker Suite中实现Google搜索
3.1.0
2023-03-17 08:48 UTC
Requires
- php: >=7.4
- fond-of-php/google-custom-search: ^2.2.0
- spryker/glossary: ^3.8.0
- spryker/zed-request: ^3.12.0
Requires (Dev)
README
在Spryker Suite中实现Google搜索
安装
composer require fond-of-spryker/google-custom-search
配置
首先,您应该在配置中完成Google API的配置,例如在config/shared/config_default.php下
$config[GoogleCustomSearchConstants::API_KEY] = 'YOUR_API_KEY';
$config[GoogleCustomSearchConstants::CX_KEY] = 'SEARCH_ENGINE_KEY';
$config[GoogleCustomSearchConstants::CONFIG_TIMEOUT] = 5.0;
$config[GoogleCustomSearchConstants::RESULT_ITEMS_PER_PAGE] = 10;
有关更多信息,请参阅官方文档:https://developers.google.com/custom-search/json-api/v1/overview
您可以通过在密钥中扩展区域设置来为区域设置添加不同的CX_KEY,例如
$config[GoogleCustomSearchConstants::CX_KEY . '_fr_FR']
请记住在密钥和区域设置之间使用下划线!
默认的搜索路由已使用/de本地化,您可以在GoogleCustomSearchControllerProvider中更改此设置。如果您不需要任何本地化路由,只需从URL中删除语言参数即可。
->value(
GoogleCustomSearchConstants::ROUTE_SEARCH_URL_VARIABLE,
'/de/' . GoogleCustomSearchConstants::ROUTE_SEARCH_URL_VARIABLE
);
将GoogleCustomSearchWidget::class添加到ShopApplicationDependencyProvider
protected function getGlobalWidgets(): array
{
return [
...
GoogleCustomSearchWidget::class,
];
}
将GoogleCustomSearchControllerProviderPlugin添加到RouterDependencyProvider
protected function getRouteProvider(): array
{
return [
...
new GoogleCustomSearchControllerProviderPlugin(),
];
}
渲染表单
要渲染搜索表单,请使用以下代码。如果您想更改路由,请使用Spryker工作流程扩展模块
{% widget 'GoogleCustomSearchWidget' only %}{% endwidget %}
结果
搜索结果显示在URL下
/search (route name google-search-results).
如果您需要不同的路由,只需按照您喜欢的样子扩展模块
在/Yves/Theme/default/搜索下,您将找到两个示例模板。请随意实现自己的模板。
变更日志
2.0.0 - 添加了对Spryker 202001.0的支持
use {% widget 'GoogleCustomSearchWidget' only %}{% endwidget %} instead of {{ render(path('gcs/form')) }}
use new router FondOfSpryker\Yves\GoogleCustomSearch\Plugin\Router\GoogleCustomSearchControllerProviderPlugin instead of FondOfSpryker\Yves\GoogleCustomSearch\Plugin\Provider\GoogleCustomSearchControllerProvider }}