bitbull/magento-2-tooso-search 1.1.0

Tooso integration module for Magento 2

Type

magento2-module

License

None

Requires
Requires (dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

Tooso Search for Magento 2

Tooso is a cloud-based, multi-language search tool for e-commerce.

This extension replaces the default search of Magento with a typo-tolerant, fast & relevant search experience backed by Tooso.

Description

This extension replaces the default Magento search engine with one based on Tooso API. It provide the following features:

  • Fulltext search for catalog products (currently advanced search is not supported)
  • Scheduled indexing of catalog products (under development)
  • Automatic typo correction (under development)
  • Search keywords suggest (under development)

Requirements

Installation Instructions

Latest version

Install latest version using composer:

composer require bitbull/magento-2-tooso-search

Specific version

Install a specific version using composer:

composer require bitbull/magento-2-tooso-search:1.0.0

Development version

Set "minimum-stability" to "dev" and switch off the "prefer-stable" config:

composer config minimum-stability dev
composer config prefer-stable false

Install latest development version using composer:

composer require bitbull/magento-2-tooso-search:dev-develop

Module Configuration

Request your API KEY

Send an email to [email protected] to request your APIKEY

Set your API KEY:

  1. Under API Configuration

* Insert your API key into API key field * Insert http://v{apiVersionWithNoDot}.api.tooso.ai into API base url field. The current supported version is 1, so the placeholder {apiVersionWithNoDot} should be replaced by 1. * Send report: YES to send a report to Tooso when an API error occourred
* Debug mode: Yes to enable more verbose logging for debug purpose 2. Save configuration

Programmatically use Tooso service

If you would like to call Tooso service that currently are not supported with the plugin we suggest this configuration.

Include in your class a dependency from Bitbull\Tooso\Api\Service\ClientInterface and let DI system do the rest:

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

}

build the client instance using a Tooso\SDK\ClientBuilder instance

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

this allow you to create a Tooso\SDK\Client instance to made any HTTP call to Tooso API with the pre-configured required parameters:

<?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'
        ]);
    }

access response data from the object of type Tooso\SDK\Response returned by doRequest method:

<?php
$result = $client->doRequest('/path/to/service', \Tooso\SDK\Client::HTTP_METHOD_GET, [
    'param1' => 'value1',
    'param2' => 'value2'
]);
$responseData = $result->getResponse();

Required theme changes

Product click after search tracking

In order to make product click after search tracking work the frontend script need to find an attribute data-product-sku on the a tag with the product's link valorized with the product SKU. To do this edit your theme file view/frontend/templates/product/list.phtml, inside the product list cycle, in the following way:

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

Suggestion frontend

This module can provide a suggestion on the search input, when you enable this feature you have to remove the default Magento suggestions system. In order to do this remove the Magento suggestion initialization from your template or override the default template view/frontend/templates/form.mini.phtml. Remove this initialization attribute from the search input:

data-mage-init='{"quickSearch":{
    "formSelector":"#search_mini_form",
    "url":"<?= /* @escapeNotVerified */ $helper->getSuggestUrl()?>",
    "destinationSelector":"#search_autocomplete"}
}'

and remove the suggestions container from the template:

<div id="search_autocomplete" class="search-autocomplete"></div>