Location based properties

Various operation support location bansed properties in order for making a searched depanding on location provided by three parameters: 

  • latitude - latitude coordinates from geolocation system
  • longitude  - longitude  coordinates from geolocation system
  • distance - the distance from the provided location for which to include stores.

Below is an example of calling the api using these parameter.

 

Sample code: 

<?php

/**
 * In the first example we are using Query By Example applied on two fields 'chain_id' and 'store_id'
 * The 'limit' and 'page' parameters are optional
 */

//set filters
$filters = array(
     "chain_id" => array("conditional" => "EQUAL_TO", "values" => "7290055700007"),
    "item_code" => array("conditional" => "IN", "values" => array("7290010429554",
        "7290000072753",
        "7290000099941",
        "7290000207162",
        "7290000208329",
        "7290003643004",
        "7290006764072",
        "7290010237623",
        "7290011473211",
        "7290106448995",
        "7290108350531"
    )),
);

//set fields to return n result set
$fields = array("chain_id", "store_id", "promotion_id", "description");

//set sorting
$sorts = array("id" => "ASC");


$params = array(
    "api_key" => "#####-prod", 
    "filters" => $filters,
    "fields" => $fields,
    "sorts" => $sorts,
    "limit" => 500,
    "include_store_data" => true,
    "latitude" => 32.0737979,
    "longitude" => "34.7693458",
    "distance" => 10000,

);
$url = "http://api.priceli.co.il/v1/priceli/product-promotions";
$response = curlGET($url, $params);
$data = json_decode($response);
echoResponse($response);

if ($data->status == 1) {
    //do something with product data
} else {
    if ($data->status == 2) {
        //no data! do something
    } else {
        echo "Error occur: " . $data->message;
    }
}

function echoResponse($response) {
    echo '<html><head><meta charset="UTF-8"></head><body>';
    echo $response;
    echo '</body></html>';
}

function curlGET($url, $data, &$errorBuf = null) {
    if ($data == null) {
        $data = array();
    }
    $url = $url . "?" . http_build_query($data);

    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_URL => $url,
    ));
    $response = curl_exec($curl);
    if (!$response) {
        $response = false;
        if ($errorBuf != null) {
            $errorBuf = curl_error($curl);
        }
    }
    curl_close($curl);
    return $response;
}

?>