fond-of-spryker/google-custom-search

Implements Google Search into the Spryker Suite

3.1.0 2023-03-17 08:48 UTC

This package is auto-updated.

Last update: 2024-12-17 13:04:37 UTC


README

license

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