Inventory PHP Backend API
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
inventory.core.php
readme.md
sample.php

readme.md

Orkiv Inventory

desc enter image description here

Requirements

  1. PHP 5.2 and Up
  2. An Orkiv Inventory account, with valid API Credentials
  3. We recommend using Twitter Bootstrap for building websites with Inventory.php

Download the PHP file 'inventory.core.php' included in this repo

Initialize the class with the following code. Replace accountid with your actual account ID and apikey with a valid Key generated for your account. You can access all of this information under the settings section of your account.

Navigation

  1. Setup
  2. Initialization
  3. Getting Inventory data
  4. Inventory Group object
  5. Performing a query
  6. Get all categories
  7. Category Object
  8. Get inventory items
  9. Item object
  10. Accessing cart checkout
  11. Orders
  12. Order object
  13. onSubscription event

Setup

Move the php file inventory.php to your website's root. include the file wherever functionality is desired!

Initialization

new InvMaster(mixed $params[ )

The snippet below initializes the class

<?php

include "inventory.core.php";

$manager = new InvManager(array(
  "id" => "accountid",
    "key" => "apikey"
  ));

?>

Get all inventory data.

(caching inventory data)

InvMaster::all()

Used to download all of your inventory data.

Returns

This will return a JSON object with key result, which is an array of inventory group objects.

<?php
$someobject = $manager->all()->result;

Inventory Group object

Properties

Querying

Querying with built in pagination

InvMaster::query(int page,string categoryid, string min_price, string max_price, mixed $additionalquery [ );

When querying you can turn Price min and max constraints off by using the string value OFF.

The first page is always 0. The method below is a DEFAULT call to the api without any search constraints. Since the category field is (empty) "" it will not take the category value of each item into consideration when performing the query.

$manager->query(0,"","OFF","OFF",array());

The additional query field can be used to query for other fields contained with the item. Please see the example below.

$query = array('color' => 'yellow');
$data = $manager->query(0, "","OFF","OFF", $query)->result;

Get all categories

InvMaster::categories()

retrieve all categories.

Returns

This method returns a mixed array with key result, this key is an array of category objects

Example :

<?php
$someobject = $manager->categories()->result;

Category object

Properties

  • name : Name of category.
  • id: ID of category.
  • children: Array of category objects, with the exception being that sampleimage is used as a system generated image for that category.
  • tmp : System generated image for that category.

Get inventory Items

InvMaster::items()

Get all items.

Returns

This method returns a mixed array with key result, this key is an array of item objects

InvMaster::item(string $itemid)

Get a specified item.

Returns

This method returns the desired item object within key result.

Examples :

To simply get all items you can call on the method below, and the method following is used to GET an individual item.

     <?php
    $someobject = $manager->items()->result;
    print_r($someobject);
    $someitem = $manager->item(ITEMID)->result;
    ?>

The script above will output the items retrieved. If you're inventory is of vast amount we recommend using querying instead of this method.

Item Object

Properties

  • ID : ID of item
  • category : Category ID of item.
  • desc : Richtext description of item.
  • name : Name of item.
  • ordprice : Integer value of price.
  • price: String value of price.
  • quantity : Item inventory quantity.
  • media : Array of strings. Each string is a url to an item's image.
  • Buy : Direct buy link of item.

Creating a new Item

InvMaster::add(string name,mixed $properties [);

Creating items via api can be useful for importing previous inventory items by adding them programmatically.

 //add function is used to create a new item
 $myitemname = "Banana";
 $manager->add($myitemname, array("price" => "10000","customfield" => "somevalue"));

Updating an Item

InvMaster::update(string itemid, mixed $set [ )

Updating an item's properties can be useful for updating item data to match actual inventory data. The code below will update an item's price and quantity. Any non-existing key supplied will be added automatically.

//valid item id needed
$ITEMID = "AAAAA";
$manager->update($ITEMID,array("price" => 9000, "quantity" => "20"));

Removing an item

InvMaster::delete(string itemid)

//ITEMID still being "AAAAA"
$manager->delete($ITEMID);

Accessing cart checkout

    https://orkiv.com/i/cart-checkout/?YOURACCOUNTID=SAMPLEITEMID,SAMPLEITEMID2&SAMPLEITEMID=quantity

Cart checkout is accessed via link. You may add as many desired items to include in checkout.

Orders

Opening an Order

InvMaster::order(string $order_id)

$request = $manager->order($order_id);
$order = $request->result;

If the Order exists it will return a json object as the Result if the Order was not found, the result will be 404

Fetching all orders

InvMaster::orders()

This will retrieve all the orders within an account.

$request = $manager->orders();
$orders = $request->result;

Order object

Properties

  • info_email : Customer email
  • info_first : Customer first name
  • info_last : Customer last name
  • phone : Customer phone number (U.S. format)
  • shipset: Customer billing address matches shipping address
  • info_adr1 : Customer billing address line 1
  • info_adr2 : Customer billing address line 2
  • info_cty : Customer billing city
  • info_zip : Customer billing zip
  • state : Customer billing state
  • info_sadr1 : Customer shipping address line 1
  • info_sadr2 : Customer shipping address line 2
  • info_scty : Customer shipping city
  • info_szip : Customer shipping zip
  • sstate : Customer shipping state
  • tax_amount: Float value of tax amount for this order in hundreds. Divide by 100 for USD value
  • shipping_amount: Float value of shipping total in USD. No conversion needed
  • amount_total : Float value of total order in USD.
  • order_id : Unique order ID

Querying orders

InvMaster::orders(mixed $value [)

Returns

Returns an array of order objects matching the supplied criteria.

Example :

<?php
$order = $manager->orders(array("order_id" => "AAA"))->result;
 ?>

Subscription callbacks

An event is a post request that Inventory performs after a successful transaction. This is useful to create any additional login accounts for the services that you are selling.

InvMaster::write(string callbackurl, string serviceid, mixed $value [ )

This function will create an event. 
    
Example :
// Setup Post Data
$postData = array("email" => "foo", "check" => "bar");
//Creating an webhook
$manager->write("url", "serviceID", $postData  );

Using Nano Identifiers

Nano Identifiers are dynamic post variables that can be used in URL callbacks. It allows the personalization of each callback request. You can only assign order data to nano identifiers. In the example below we will create a web hook and use a nano identifier pointing to the customer's email

//sample Nano Identifier
$nano = "@:info_email";

// Setup Post Data
$postData = array("email" => $nano, "check" => "@:order_id");
//Creating an webhook
$manager->write("url", "serviceID", $postData  );

2016 Orkiv Retail Solutions LLC