PHP code example of bitbull / magento-2-tooso-search

1. Go to this page and download the library: Download bitbull/magento-2-tooso-search library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bitbull / magento-2-tooso-search example snippets




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

}



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



    /**
     * Execute service
     */
    protected function execute()
    {
        $client = $this->getClient();
        $result = $client->doRequest('/path/to/service', \Tooso\SDK\Client::HTTP_METHOD_GET, [
            'param1' => 'value1',
            'param2' => 'value2'
        ]);
    }


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

<a href="<?= /* @escapeNotVerified */ $_product->getProductUrl() 


$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Tooso\SDK\Search\Result $searchResult */
$searchResult = $objectManager->get('Magento\Framework\Registry')->registry(\Bitbull\Tooso\Model\Service\Search::SEARCH_RESULT_REGISTRY_KEY);