fond-of-spryker / google-custom-search
Implements Google Search into the Spryker Suite
Installs: 17 695
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
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
Implements Google Search into the Spryker Suite
Install
composer require fond-of-spryker/google-custom-search
Configuration
First, you should complete the configuration of the Google API in your configuration, e.g. under 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;
For more information, see the official documentation at https://developers.google.com/custom-search/json-api/v1/overview
You can add different CX_KEYs for locales by extending the key with the locale, in example:
$config[GoogleCustomSearchConstants::CX_KEY . '_fr_FR']
Dont forget the underscore between the key and locale!
The default route for search is localed with /de, you change this in the GoogleCustomSearchControllerProvider. If you dont need any localized route just remove the language parameter in URL.
->value(
GoogleCustomSearchConstants::ROUTE_SEARCH_URL_VARIABLE,
'/de/' . GoogleCustomSearchConstants::ROUTE_SEARCH_URL_VARIABLE
);
Add GoogleCustomSearchWidget::class to ShopApplicationDependencyProvider
protected function getGlobalWidgets(): array
{
return [
...
GoogleCustomSearchWidget::class,
];
}
Add GoogleCustomSearchControllerProviderPlugin to RouterDependencyProvider
protected function getRouteProvider(): array
{
return [
...
new GoogleCustomSearchControllerProviderPlugin(),
];
}
Render the form
To render the search form use the following code. If you want to change the routes, expand the module as you like using the Spryker workflow
{% widget 'GoogleCustomSearchWidget' only %}{% endwidget %}
Results
The search results are displayed under the URL
/search (route name google-search-results).
If you need a different route, just expand the module how you like
Under /Yves/Theme/default/ search you will find two example templates. Feed free to implement your own.
Changelog
2.0.0 - added Support for 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 }}