koenreiniers/bol-sdk

Bol Plaza API 的 SDK

1.1.2 2016-02-12 20:18 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:31:37 UTC


README

Bol API 的 SDK

关于

由于 Bol Plaza API 的新部分(报价管理)还没有可用的 SDK,我决定自己创建一个。这意味着这个 SDK 不支持订单和 Open Api。但是,它们将来可能会被添加。您可以自由地扩展这个 SDK 以满足您的需求,甚至可以提交 pull request。

安装

composer require koenreiniers/bol-sdk

使用方法

使用 SDK 有两种方式。推荐的方式是使用 Kr\Bol\Plaza,它为每个 API 调用提供了预定义的方法。您可以按以下方式使用它

use \Kr\Bol\Plaza;
use \Kr\Model\Offer;

$plaza = new Plaza($publicKey, $privateKey);
// Create an offer
// Note you can also create an Offer model the old fashioned way using getters/setters
$offer = Offer::toCreate($id, $ean, $condition, $price, $deliveryCode, $quantityInStock, $publish, $referenceCode, $description);
$plaza->createOffer($offer);

// Update an offer
$offer = Offer::toUpdate($id, $price, $deliveryCode, $publish, $referenceCode, $description);
$plaza->updateOffer($offer);

// Update an offer's stock
$offer = Offer::toUpdate($id, $quantityInStock);
$plaza->updateOfferStock($offer);
// Alternatively:
$plaza->updateOfferStock($id, $quantityInStock);

// Delete an offer
$offer = Offer::toDelete($id);
$plaza->deleteOffer($offer);
// Alternatively:
$plaza->deleteOffer($id);

// Request an export of your offers
$exportFilename = $plaza->requestExport($filter);
// Try to read an export
$offers = $plaza->readExport($exportFilename);

PlazaClient

或者您也可以使用 \Kr\Bol\Http\PlazaClient,它可以用于任何 Plaza API 调用

use \Kr\Bol\Http\PlazaClient;

$plazaClient = new PlazaClient($publicKey, $privateKey);
$plazaClient->get("/offers/v1");
$plazaClient->post("/offers/v1", $content);
$plazaClient->put("/offers/v1", $content);
$plazaClient->delete("/offers/v1");

使用 \Kr\Bol\PlazaClient 的缺点是它不会验证您的报价是否符合 Bol.com 预定义的规则,而 \Kr\Bol\Plaza 会。

其他

还有一些其他的东西,比如条件和配送代码的枚举。它们主要用于验证报价,但您也可以使用它们来列出所有可用的条件和配送代码

use \Kr\Bol\Enum\Condition;
use \Kr\Bol\Enum\DeliveryCode;

$conditions = Condition::all();
$deliveryCodes = DeliveryCode::all();

别忘了 HeaderGenerator

$headerGenerator = new \Kr\Bol\Http\HeaderGenerator();
$headers = $headerGenerator->generateHeaders($publicKey, $privateKey, $target, $method);

测试

目前的覆盖率约为 70%。