PHP code example of mdeschermeier / shiphero

1. Go to this page and download the library: Download mdeschermeier/shiphero library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mdeschermeier / shiphero example snippets


Shiphero::setKey('<your API key>');

Shiphero::verifyPeer(true); //Enables Host/Peer Verification

    /*==== or ====*/
    
Shiphero::verifyPeer(false); //Disables Host/Peer Verification

Shiphero::setAdditionalCurlOpt(CURLOPT_VERBOSE, true);

Shiphero::setAdditionalCurlOpt(CURLOPT_VERBOSE, true); // - set a custom cURL option for next API request.

Shiphero::preserveAdditionalCurlOpt(true); // - Will remember cURL option settings until turned off

//send some requests
Shiphero::getOrderById(383484); // - cURL options remembered (CURLOPT_VERBOSE = true)
Shiphero::getProducts();        // - cURL options remembered (CURLOPT_VERBOSE = true)

Shiphero::preserveAdditionalCurlOpt(false); //Turn off cURL option rememberance and clear out stored values.

Shiphero::getVendorList(): // - Request ran with default options (CURLOPT_VERBOSE = false)

$prod = array('sku' => 12345);
$response = Shiphero::getProduct($prod) // - Get one item.

$prod = array('page'=>2, 'count'=>150);
$response = Shiphero::getProduct($prod); // - Of all items, return second page, limit 150 items per page.

$response = Shiphero::getProduct(); // - Get all items, no paging (returns the first 50 products).

$sku = 'abc-123';
$product =  array('title'=>'Sample Item Name', 'available_inventory'=>500, 'value'=>5.00, 'price'=>5000.00,
            'images'=> array(
                   array('url' => 'http://made.up.domain.com/super_rad_product.png',
                   'position' => 1),
                   array('url' => 'http://another.made.up.domain.co.uk/more-rad-product.jpg',
                   'position' => 2)
             ));
             
Shiphero::createProduct($sku, $product); // - Create the simple product.

$product_1 = array('sku'=>'abc-123', 'quantity'=> -2, 'warehouse'=>'Secondary', 'width'=>'2.5');
Shiphero::addProductToUpdateQueue($product_1);

//Product Inventory Update Queue Contains: $product_1

$product_2 = array('sku'=>'def-456', 'new_quantity'=>200);
Shiphero::adddProductToUpdateInventoryQueue($product_2);

//Product Inventory Update Queue Now Contains: $product_1, $product_2

// Define Product Update Information
$product_1 = array('sku'=>'abc-123', 'quantity'=> -2, 'warehouse'=>'Secondary', 'width'=>'2.5');
$product_2 = array('sku'=>'def-456', 'new_quantity'=>200);

//Add Products to Update Queue
Shiphero::addProductToUpdateQueue($product_1);
Shiphero::addProductToUpdateQueue($product_2);

//Update Products in Queue
Shiphero::updateInventory();

$kit = array(
            'parent_sku' => 'kit-sku-123',
            'components' => array(
	    			array(
                                 'sku'=>'product_1-sku-123',
                                 'qty'=> 3
                            	),
                            	array(
                                 'sku'=>'product_2-sku-456',
                                 'qty'=>1
                            	)
			    )
            );
     
Shiphero::addKitToCreationQueue($kit);

//Kit Creation Queue Contains: $kit (3 of 'product_1-sku-123, 1 of 'product_2-sku-456')

$another_kit = array(
            'parent_sku' => 'kit-sku-456',
            'components' => array(
	    			array(
                                 'sku'=>'product_1-sku-123',
                                 'qty'=> 10
                            	),
                            	array(
                                 'sku'=>'product_2-sku-456',
                                 'qty'=>3
                            	)
			   )
            );
     
Shiphero::addKitToCreationQueue($another_kit);

//Kit Creation Queue Contains: $kit (3 of 'product_1-sku-123, 1 of 'product_2-sku-456')
//                             $another_kit (10 of 'product_1-sku-123, 3 of 'product_2-sku-456')

//Kit Creation Queue Contains: $kit (3 of 'product_1-sku-123, 1 of 'product_2-sku-456')
//                             $another_kit (10 of 'product_1-sku-123, 3 of 'product_2-sku-456')
                               
Shiphero::createKits();  // - Kits are now created in Shiphero.

//Kit Creation Queue Contains: Nothing (empty)


// Kit 1 (sku 'abc-123') Components (skus): p-123, p-456, p-789
// Kit 2 (sku 'def-456') Components (skus): p-456, p-111, p-222

// - Queue Removal of Item Skus 'p-456' and 'p-789' from Kit 1
Shiphero::addToRemoveKitComponentQueue('abc-123', array('p-456', 'p-789')); 

// - Queue Removal of Item Sku 'p-111' from Kit 2
Shiphero::addToRemoveKitComponentQueue('def-456', array('p-111'));

// Kit 1 (sku 'abc-123') Components (skus): p-123, p-456, p-789
// Kit 2 (sku 'def-456') Components (skus): p-456, p-111, p-222

//Removal Queue:
//      Kit 1: p-456, p-789
//      Kit 2: p-111

Shiphero::removeKitComponents();

// Kit 1 (sku 'abc-123') Components (skus): p-123
// Kit 2 (sku 'def-456') Components (skus): p-456, p-222

//Removal Queue: 
//      Nothing (empty)

// Kit 1 (sku 'abc-123') Components (skus): p-123, p-456, p-789

Shiphero::clearKit('abc-123');

// Kit 1 (sku 'abc-123') Components (skus): Nothing (empty)

$filter = array('page'=>1, 'from'=>'2016-9-1', 'to'=>'2016-9-28');

//Return all orders matching filter for current store
Shiphero::getOrders($filter)

//return all orders matching filter for ALL stores
Shiphero::getOrders($filter, 1);

//Returns order with ID: 12345
Shiphero::getOrderById('12345');

//Returns order number: 427895-Fri-1
Shiphero::getOrder('427895-Fri-1');

// Define the order
$order = array(
    'email' => '[email protected],
    'line_items' => array(
        array(
            'sku' => 'abc-123',
            'name' => 'Item 1', 
            ...
        ),
        array(
            'sku' => 'def-456',
            'name' => 'Item 2',
            ...
        )
    ),
    'note_attributes' => array(
        ...
    ),
    'shipping_address' => array(
        'address1' => '123 Address Ave',
        'address2' => 'Apt 202',
        'city'     => 'Anytown',
        ...
    ),
    'order_id' => '1234567890',
    ...
);

// Create the Order
Shiphero::createOrder($order);

$order = array(
    'order_number' => '1234-123',
    ...
);

Shiphero::updateOrder($order);

$hist = array(
    'order_id' => 123456,
    'username' => '[email protected]',
    'information' => 'A note on the order history'
);

Shiphero::createOrderHistory($hist);

$vendors = Shiphero::getVendorList();

$vendor = array('vendor_name' => 'Wyld Stallyn Guitars', // - vendor_name is the only fornia'
          );
          
Shiphero::createVendor($vendor);


$product1 = array('sku' => 'abc-123', 'vendor_id' => '1234');
Shiphero::addProductToVendorQueue($product1);

// Products in Vendor Queue:
//          $product1:
//              sku: '1234'
//              vendor_id: '1234'
//

$product2 = array('sku' => '5678', 'vendor_id' => '9012', 'price' => 40.99, 'manufacturer_sku' => 'mSku-494');
Shiphero::addProductToVendorQueue($product2);
// Products in Vendor Queue:
//          $product1:
//              sku: '1234'
//              vendor_id: '1234'
//
//          $product2:
//              sku: '5678'
//              vendor_id: '9012'
//              price: 40.99
//              manufacturer_sku: 'msku-494'
//

// Products in Vendor Queue:
//          $product1:
//              sku: '1234'
//              vendor_id: '1234'
//
//          $product2:
//              sku: '5678'
//              vendor_id: '9012'
//              price: 40.99
//              manufacturer_sku: 'msku-494'
//

Shiphero::addProductsToVendors();

// Products in Vendor Queue:
//          Nothing (empty)
//


//Vendor ID: 123456
//      contains items (skus):
//          'abc-123'
//          'def-456'
//          'ghi-789'
//

Shiphero::removeProductFromVendor(123456, 'def-456');

//Vendor ID: 123456
//      contains items (skus):
//          'abc-123'
//          'ghi-789'
//

Shiphero::createFulfillmentStatus('My Custom Status');

Shiphero::deleteFulfillmentStatus('My Custom Status');

	$line_item1 = array('id'=>3456789012, 'sku'=>'abc-123', 'name'=>'Test1',
						'price'=>'25.00', 'quantity'=>30, 'sell_ahead'=>0);

    //PO Line Item Queue Contains: $line_item1

	$line_item2 = array('id'=>2345678901, 'sku'=>'def-456', 'name'=>'Test2',
						'price'=>'0.00', 'quantity'=>40, 'sell_ahead'=>0);
    
    //PO Line Item Queue Contains: $line_item1, $line_item2
    
    $line_item3 = array('id'=>1234567890, 'sku'=>'ghi-789', 'name'=>'Item 3',
						'price'=>'25.00', 'quantity'=>20, 'sell_ahead'=>0);
                        
    //PO Line Item Queue Contains: $line_item1, $line_item2, $line_item3
    

    ...
    Shiphero::addProductToPoQueue($line_item1);
	Shiphero::addProductToPoQueue($line_item2);
	Shiphero::addProductToPoQueue($line_item3);
    
    //PO Line Item Queue Contains: $line_item1, $line_item2, $line_item3
    
    $po = array('email'=>'[email protected]', 'vendor_name'=>'A. Vendor, Inc', 'created_at'=>'2016-10-03 10:42:25');
    
    Shiphero::createPO($po);
    
    //PO Line Item Queue Contains: Nothing (empty)

    
    $po_1 = Shiphero::getPO(1);     // - Return information from PO ID: 1
    $po_2 = Shiphero::getPO(2);     // - Return information from PO ID: 2
    $po_3 = Shiphero::getPO(456789); // - Return information from PO ID: 456789
    

    
    //Get page 1 of all shipments from Sept. 28, 2016
    $filter = array('page'=>1, 'from'=>'2016-09-28', 'to'=>'2016-09-28');
    $collection1 = Shiphero::getShipments($filter);
    
    //Get page 6 of all shipments from Sept. 28, 2016 to Oct. 2, 2016
    $filter = array('page'=>6, 'from'=>'2016-09-28', 'to'=>'2016-10-2');
    $collection2 = Shiphero::getShipments($filter);
    


    $shipment = array('warehouse'=>'Primary', 
                      'profile'=>'default',
                      'shipment'=>array(
                            'shipment_id'=>'123456',
                            'order_id'=>'78901',
                            'carrier'=>'UPS',
                            'shipping_method'=>'UPS GROUND',
                            'tracking_number'=>'abcde1234567890',
                            'cost'=>10.76,
                            'dimensions'=>array(
                                'weight'=>20,
                                'length'=>5,
                                'width'=>8,
                                'height'=>4
                            ),
                            'address'=>array(
                                'name'=>'John Doe',
                                'address1'=>'123 Anywhere St.',
                                'address2'=>'Apt 2',
                                'city'=>'Anytown',
                                'state'=>'CA',
                                'postal_code'=>'12345',
                                'country'=>'US'
                            ),
                            'label'=>array(
                                'pdf'=>'http://example.url.to/pdf/file.pdf',
                                'png'=>array(
                                    'http://example.url.to/png/page1.png',
                                    'http://example.url.to/png/page2.png'
                                )
                            ),
                            'customs_info'=>array(
                                'http://example.url.to/customs/info/page1.png',
                                'http://example.url.to/customs/info/page2.png'
                            )
                        )
                    );
                    
    Shiphero::createShipment($shipment);
    

    //register a webhook to post to URL 'http://my.owned.url.for/webhooks/' every time inventory is updated on my bigcommerce store.
    $hook_info = array('name'=>'Inventory Update', 'url'=>'http://my.owned.url.for/webhooks/', 'source'=>'bigcommerce');
    Shiphero::registerWebhook($hook_info);

    
    $webhook_list = Shiphero::getWebhooks();