priceva/priceva-sdk-php

v0.7.0 2018-10-16 07:10 UTC

This package is auto-updated.

Last update: 2024-09-26 17:26:55 UTC


README

Priceva API (PHP) 的 SDK

入门指南

要求

  • PHP >= 5.4
  • cURL 库
  • JSON 库

安装

通过 Composer

进入项目根目录并运行

php composer require priceva/priceva-sdk-php

或在你的 composer.json 文件的 require 部分添加此字符串

"priceva/priceva-sdk-php": "dev-master"

然后运行 composer install

不使用 Composer

  1. 下载我们的库。
  2. 在你的 PHP 根文件中包含文件
    include_once '/path/to/lib/PricevaAPI.php';
    include_once '/path/to/lib/PricevaException.php';
    include_once '/path/to/lib/Request.php';
    include_once '/path/to/lib/Result.php';
    // ...and other our files if it needed

使用

最简单的示例

use Priceva\PricevaAPI;


try{
    // or include our files directly, if you don't want to use Composer
    require_once __DIR__ . "/../vendor/autoload.php";

    $api = new PricevaAPI('your_api_key');

    $result = $api->main_ping();

}catch( \Exception $e ){
    // error handler
}

获取产品列表

try{
    // or include our files directly, if you don't want to use Composer
    require_once __DIR__ . "/../vendor/autoload.php";

    $api = new PricevaAPI('your_api_key');

    $filters = new \Priceva\Params\Filters();
    $sources = new \Priceva\Params\Sources();

    $filters[ 'page' ]      = 1;
    $filters[ 'region_id' ] = 'a';

    $sources[ 'add' ]      = true;
    $sources[ 'add_term' ] = true;

    $products = $api->product_list($filters, $sources);
}catch( \Exception $e ){
    // error handler
}

获取报告列表

try{
    // or include our files directly, if you don't want to use Composer
    require_once __DIR__ . "/../vendor/autoload.php";

    $api = new PricevaAPI('your_api_key');

    $filters        = new \Priceva\Params\Filters();
    $product_fields = new \Priceva\Params\ProductFields();

    $filters[ 'page' ]      = 1;
    $filters[ 'region_id' ] = 'a';
    
    // we use 'flat model' of parameters here
    $product_fields[] = 'client_code';
    $product_fields[] = 'articul';

    $reports = $api->report_list($filters, $product_fields);
}catch( \Exception $e ){
    // error handler
}

使用分页

$api = new PricevaAPI($api_key);

$filters        = new \Priceva\Params\Filters();
$product_fields = new \Priceva\Params\ProductFields();

$filters[ 'limit' ] = '1000'; // for example
$filters[ 'page' ]  = 1; // strong

... // some filters

$product_fields[] = 'client_code'; // if we need it field in answer
$product_fields[] = 'articul';  // if we need it field in answer

... // some product fields

$reports = $api->report_list($filters, $product_fields);

$pages_cnt = (int)$reports->get_result()->pagination->pages_cnt;

$priceva_products = $reports->get_result()->objects;

process_products($priceva_products); // client function for product processing

while( $pages_cnt > 1 ){
  $filters[ 'page' ] = $pages_cnt--;

  $reports = $api->report_list($filters, $product_fields);

  $priceva_products = $reports->get_result()->objects;

  process_products($priceva_products); // client function for product processing
}

API 操作

  • main/ping
  • main/demo
  • product/list
  • report/list

请求参数

过滤器

适用于方法: product/listreport/list。可能的选项

  • page
  • limit
  • category_id
  • brand_id
  • company_id
  • region_id
  • active
  • name
  • articul
  • client_code

来源

适用于方法: product/list。可能的选项

  • add
  • add_term

产品字段

适用于方法: report/list。可能的选项

  • client_code
  • articul
  • name
  • active
  • default_price
  • default_available
  • default_discount_type
  • default_discount
  • repricing_min
  • default_currency

附加信息

了解更多关于我们的 API 的信息 这里