Product Promotions - חיפוש מבצעים המקושרים למוצר

Get the promotions related with specific product. A product may relate with zero or more promotions. In this operation toy provide item_code  and optionally addition filters and you get as result the list of all the promotions related with this product. The first example below is basic one. The second example shows how you can add addition filter fields and/or request for custom list of fields to be return in the result set. 

 

Request parameters: 

Required: "item_code"  

The item_code can be provided as standalone or within "filters" array. Anyway it must be provided in order to make the relation between promotion product items, and a product. 

Optional parameters: If you need addition filters you sould construct a "filters" array. See the second example below.  Note that these are the same fields you can use to set a custom list of fields to be return in the result set. 

"id"
"chain_id",
"store_id",
"promotion_id",
"description",
"update_date",
"update_date_sec",
"start_date",
"start_hour",
"end_date",
"end_hour",
"reward_type",
"allow_multiple_discounts",
"is_weighted_promo",
"restriction_is_coupon",
"restriction_gift_count",
"restriction_is_total",
"restriction_is_active",
"min_qty",
"max_qty",
"discounted_price",
"discounted_price_per_mida",
"min_no_of_item_ofered",
"club_ids",

 

Sample code: 

Basic Example

<php

$params = array(
    "api_key" => "API_KEY", // or "access_token" => "some-token"
    "item_code" => "7290000042855",
);
$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;
}
?>

Example with filters, custom list of fields and sorting

<php

/set filters
$filters = array(
    "chain_id" => array("conditional" => "EQUAL_TO", "values" => "7290492000005"),
    "store_id" => array("conditional" => "EQUAL_TO", "values" => "501"),
    "item_code" => array("conditional" => "EQUAL_TO", "values" => "7290000042855"),
);

//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" => "API_KEY", // or "access_token" => "some-token"
    "filters" => $filters,
    "fields" => $fields,
    "sorts" => $sorts,
);
$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>';
}


?>

Example with store/location based data

<php
//set filters
$filters = array(
    "item_code" => array("conditional" => "IN", "values" => array("7290000042855", "7290002421504")),
);

//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" => "API_KEY", // or "access_token" => "some-token"
    "filters" => $filters,
    "fields" => $fields,
    "sorts" => $sorts,
    "include_store_data" => "true",
    "longitude" => "34.7693458",
    "latitude" => "32.0737979",
    "distance" => 1000,
    "XDEBUG_SESSION_START" => "14235",

);
$url = "http://local.api.priceli.co.il:8080/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>';
}

?>
Sample Response : 
Response with all fields:
{
  "status": 1,
  "count": 14,
  "total": 14,
  "pageLimit": 100,
  "pageNum": 1,
  "data": [
    {
      "id": "464",
      "chain_id": "7290492000005",
      "store_id": "501",
      "promotion_id": "13001730",
      "description": "×‘×§× ×™×” מעל30 ש ×— מגבת × ×™×™×¨ ב8.90 ש ×—",
      "update_date": "2015-01-01 00:00:00",
      "update_date_sec": "1447153043",
      "start_date": "2015-08-16",
      "start_hour": "00:00:00",
      "end_date": "2015-12-31",
      "end_hour": "23:59:00",
      "reward_type": "11",
      "allow_multiple_discounts": "1",
      "is_weighted_promo": "0",
      "restriction_is_coupon": "0",
      "restriction_gift_count": "0",
      "restriction_is_total": "0",
      "restriction_is_active": "1",
      "min_qty": null,
      "max_qty": null,
      "discounted_price": null,
      "discounted_price_per_mida": null,
      "min_no_of_item_ofered": "10",
      "club_ids": null,
      "sys_updated_date": "2015-11-10 12:59:56",
      "sys_updated_date_sec": "1447153196",
      "item_code": "7290000042855"
    },
    .....
  ],
 
}

Response with custom list of fields

{
  "status": 1,
  "count": 14,
  "total": 14,
  "pageLimit": 100,
  "pageNum": 1,
  "data": [
    {
      "id": "235",
      "chain_id": "7290492000005",
      "store_id": "501",
      "item_code": "7290000042855"
    },
    {
      "id": "448",
      "chain_id": "7290492000005",
      "store_id": "501",
      "item_code": "7290000042855"
    },
    ........
  ],
  
}