2017 © Pedro Peláez
 

library vendapi

Vend API class

image

vendapi/vendapi

Vend API class

  • Thursday, August 24, 2017
  • by brucealdridge
  • Repository
  • 8 Watchers
  • 33 Stars
  • 2,340 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 22 Forks
  • 1 Open issues
  • 4 Versions
  • 3 % Grown

The README.md

Vend API class

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., (*1)

NB: Updated to use oauth for July 2015 deprecation, if you have sample code for handling oauth authorization and token refreshes submit a pull requst, (*2)

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., (*3)

{
    "require": {
        "vendapi/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., (*4)

<?php
require 'path/to/src/VendApi/VendApi.php';

$vend = new VendAPI\VendAPI('https://shopname.vendhq.com','VEND_TOKEN_TYPE','VEND_ACCESS_TOKEN');
$products = $vend->getProducts();

API Usage

Get Products

$vend = new VendAPI\VendAPI('https://shopname.vendhq.com','VEND_TOKEN_TYPE','VEND_ACCESS_TOKEN');
$products = $vend->getProducts();

NB this will only grab the first 20 or so results. To grab all results set $vend->automatic_depage to true, (*5)

$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, (*6)

$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:, (*7)

$vend->debug(true);

The Versions

24/08 2017

dev-master

9999999-dev http://github.com/brucealdridge/vendapi

Vend API class

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Bruce Aldridge
by Arjan Scherpenisse

shop e-commerce shopping

24/08 2017

1.5.2

1.5.2.0 http://github.com/brucealdridge/vendapi

Vend API class

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Bruce Aldridge
by Arjan Scherpenisse

shop e-commerce shopping

04/07 2017

1.5.1

1.5.1.0 http://github.com/brucealdridge/vendapi

Vend API class

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Bruce Aldridge
by Arjan Scherpenisse

shop e-commerce shopping

20/08 2015

v1.5

1.5.0.0 http://github.com/brucealdridge/vendapi

Vend API class

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Bruce Aldridge
by Arjan Scherpenisse

shop e-commerce shopping