Type
magento2-module
Tooso integration module for Magento 2
magento2-module
None
None
None
None
None
None
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.
This extension replaces the default Magento search engine with one based on Tooso API. It provide the following features:
Install latest version using composer:
composer require bitbull/magento-2-tooso-search
Install a specific version using composer:
composer require bitbull/magento-2-tooso-search:1.0.0
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
Send an email to [email protected] to request your APIKEY
* 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
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();
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 -->
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>