Compare - השוואה בין שני מוצרים

Compare prices for a given product code.

Request parameters: 

Prameters of product 1

  • chain_id_1
  • store_id_1
  • item_code_1

Parameters of product 2

  • chain_id_2
  • store_id_2
  • item_code_2

Other parameters

  • prepare_chain_names - Optional. Sending this parameter with value "true" will add "chain_name" field to returned items
  • prepare_stores_names - Optional. Sending this parameter with value "true" will add "store_name", "address", "city" fields to returned items

 

Sample code: 
<?php

$params = array(
    "api_key" => "YOUR_API_KEY", // or "access_token" => "some-token"

    //product 1
    "chain_id_1" => "7290492000005",
    "store_id_1" => "501",
    "item_code_1" => "4014400901191",

    //product 2
    "chain_id_2" => "7290492000005",
    "store_id_2" => "501",
    "item_code_2" => "7290008464741",
);
$url = "http://api.priceli.co.il/v1/priceli/compare";
$response = curlGET($url, $params);
$data = json_decode($response);
echoResponse($response);

if ($data->status == 1) {
    //do something with product data

} 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;
}
?>
Sample Response : 

The value of "compare_result" field is 0 if prices of two products are equal, 1 if product 1 is more expensive and -1 if product 2 is more expensive. 0 = equal 1 price [product 1] > price [product 2] -1 price [product 1] < price [product 2]

{
  "status": 1,
  "count": 1,
  "total": 1,
  "pageLimit": 1,
  "pageNum": 1,
  "data": {
    "compare_result": -1,
    "product_1": {
      "id": "512",
      "chain_id": "7290492000005",
      "sub_chain_id": "1",
      "store_id": "501",
      "bikoret_no": "9",
      "item_id": null,
      "item_code": "7290008464741",
      "item_code_short": "8464741",
      "item_type": "1",
      "item_name": "בירה גולדסטאר 1\/6",
      "price_update_date": "2015-01-01 00:00:00",
      "price_update_date_sec": "0",
      "manufacturer_name": null,
      "manufacturer_country": null,
      "manufacturer_item_description": null,
      "unit_qty": "ליטרים",
      "quantity": "1.98",
      "unit_of_measure": null,
      "bis_weighted": null,
      "qty_in_package": "6",
      "item_price": "55.50",
      "unit_of_measure_price": "28.03",
      "allow_discount": "1",
      "item_status": "1",
      "text_tokens": "55.50 7290008464741 6 6",
      "sys_updated_date": "2015-06-03 14:45:20",
      "sys_updated_date_sec": "1433331920"
    },
    "product_2": {
      "id": "512",
      "chain_id": "7290492000005",
      "sub_chain_id": "1",
      "store_id": "501",
      "bikoret_no": "9",
      "item_id": null,
      "item_code": "7290008464741",
      "item_code_short": "8464741",
      "item_type": "1",
      "item_name": "בירה גולדסטאר 1\/6",
      "price_update_date": "2015-01-01 00:00:00",
      "price_update_date_sec": "0",
      "manufacturer_name": null,
      "manufacturer_country": null,
      "manufacturer_item_description": null,
      "unit_qty": "ליטרים",
      "quantity": "1.98",
      "unit_of_measure": null,
      "bis_weighted": null,
      "qty_in_package": "6",
      "item_price": "55.50",
      "unit_of_measure_price": "28.03",
      "allow_discount": "1",
      "item_status": "1",
      "text_tokens": "55.50 7290008464741 6 6",
      "sys_updated_date": "2015-06-03 14:45:20",
      "sys_updated_date_sec": "1433331920"
    }
  }
}

Required Creadential: 
API Key
OR Access Token