anytech/vendapi
最新稳定版本:v2.1
Composer 安装命令:
composer require anytech/vendapi
包简介
Vend API class
关键字:
README 文档
README
This is a basic PHP class for using the API for Vend (vendhq.com). It is at a really basic state but it does exactly what I need at the moment. Feel free to add any issues/bugs and send me any pull requests.
NB: Updating to API 2.0
Installation and Basic Usage
With Composer
The easiest way to install Vend API is via composer. Create the following composer.json file and run the php composer.phar install command to install it.
{
"require": {
"anytech/vendapi": "dev-master"
}
}
Without Composer
Why are you not using composer? Download and extract the zip file from the repo into your project path somewhere.
<?php require 'path/to/src/Anytech/VendApi.php'; $vend = new VendAPI\VendAPI('https://shopname.vendhq.com','VEND_TOKEN_TYPE','VEND_ACCESS_TOKEN'); $products = $vend->getProducts(); //2.0 Api $products = $vend->getProducts20();
API Usage
Get Products
$vend = new VendAPI\VendAPI('https://shopname.vendhq.com','VEND_TOKEN_TYPE','VEND_ACCESS_TOKEN'); $products = $vend->getProducts(); //2.0 Api $products = $vend->getProducts20();
NB this will only grab the first 20 or so results. To grab all results set $vend->automatic_depage to true
$vend->automatic_depage = true; $products = $vend->getProducts();
Add a Product
$donut = new \VendAPI\VendProduct(null, $vend); $donut->handle = 'donut01'; $donut->sku = '343434343'; $donut->retail_price = 2.99; $donut->name = 'Donut w/ Sprinkles'; $donut->save(); echo 'Donut product id is '.$donut->id;
Add a Sale
$sale = new \VendAPI\VendSale(null, $vend); $sale->register_id = $register_id; $sale->customer_id = $customer_id; $sale->status = 'OPEN'; $products = array(); foreach ($items as $item) { $products[] = array( 'product_id' => $item->product_id, 'quantity' => $item->quantity, 'price' => $item->price ); } $sale->register_sale_products = $products; $sale->save(); echo "Created new order with id: ".$sale->id;
Other cool stuff
$vend->getProducts(array('active' => '1', 'since' => '2012-09-15 20:55:00'));
NB Check the vend api docs for supported search fields. If a search field isn't supported all results will be returned rather than the zero I was expecting
$coffee = $vend->getProduct('42c2ccc4-fbf4-11e1-b195-4040782fde00'); echo $coffee->name; // outputs "Hot Coffee" if ($product->getInventory() == 0) { $coffee->setInventory(10); $coffee->name = 'Iced Coffee'; $coffee->save(); }
Debugging
To debug make a call to the debug() function.
eg:
$vend->debug(true);
统计信息
- 总下载量: 1.53k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-14