Getting Started | Quick Start - findologic/findologic-api GitHub Wiki
This page provides a quick introduction to the FINDOLOGIC-API with easy examples you can copy & paste into your project.
Creating a client
// A config is always required in order to create a client.
$config = new Config();
$config->setServiceId('ABCDABCDABCDABCDABCDABCDABCDABCD');
// Client used for requests
$client = new Client($config);
When creating a Client
a Config
object is always required. Most of the time you will only need to set the ServiceId aka. the Shopkey, but if you are interested in what you can set, check out this page.
Config
instance:
Minimum requirements for a setServiceId
($value string
):
This parameter is required in order to determine on which service the search should be triggered. You can find the shopkey in your customer account.
...
Optional other parameters
Any other additional optional parameters that you can set see here.
Sending requests
$searchRequest = new SearchRequest();
$searchRequest
->setQuery('shirt') // Users search query
->setShopUrl('blubbergurken.de') // Url of the shop
->setUserIp('127.0.0.1') // Users IP
->setReferer($_SERVER['HTTP_REFERER']) // Page where search was fired
->setRevision('1.0.0'); // Version of your API wrapper
/** @var Xml20Response $xmlResponse */
$xmlResponse = $client->send($searchRequest);
In order to send requests you always need some kind of request builder (in this example a SearchRequest
). Based on the request builder you may need some defaults. You can see the minimum defaults for a SearchRequest
in the code example above.
Retrieving data (XML 2.0)
/** @var Xml20Response $xmlResponse */
$response = $client->send($searchRequest);
// Server data (see which servers handled the request)
echo $response->getServers()->getFrontend();
echo $response->getServers()->getBackend()
// Query data
echo $response->getQuery()->getDidYouMeanQuery(); // May be null if there is nothing to suggest or you do not have Smart Did-You-Mean enabled.
echo $response->getQuery()->getSearchedWordCount();
echo $response->getQuery()->getFoundWordsCount();
echo $response->getQuery()->getAlternativeQuery();
// Query string
echo $response->getQuery()->getQueryString()->getValue();
echo $response->getQuery()->getQueryString()->getType()); // Either null or 'forced'.
// Limiting params
echo $response->getQuery()->getLimit()->getFirst();
echo $response->getQuery()->getLimit()->getCount();
// Landingpage and Promotion
echo $response->getLandingPage()->getLink();
echo $response->getPromotion()->getLink();
echo $response->getPromotion()->getImage();
// Results
echo $response->getResults()->getCount();
// Products
foreach ($response->getProducts() as $product) {
echo $product->getId();
echo $product->getDirect();
echo $product->getRelevance();
var_dump($product->getProperties());
}
// Filters
foreach ($response->getFilters() as $filter) {
echo $filter->getDisplay();
echo $filter->getType();
echo $filter->getName();
echo $filter->getSelect();
echo $filter->getSelectedItems();
echo $response->getFilterCount();
// Do stuff for range-slider only (you could for example show a real range slider).
if ($filter->getType() === 'range-slider') {
$filter->getAttributes()->getSelectedRange();
$filter->getAttributes()->getTotalRange();
$filter->getAttributes()->getStepSize();
$filter->getAttributes()->getUnit();
}
if ($filter->hasItems() {
// Go through all sub-filters.
}
}
This example may seem a bit big for a "Quick Start", but it is rather a cheat sheet than a real example.