PHP code example of block-ops / directscale-sdk-php

1. Go to this page and download the library: Download block-ops/directscale-sdk-php 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/ */

    

block-ops / directscale-sdk-php example snippets


# Create define
define('DIRECTSCALE_APIKEY', 'your123prod456key543here210');
# Create instance
$DirectScale = new \DirectScale\User(54321);
# Get distributor details
print_r($DirectScale->getDistInfo());

use \DirectScale\ {
	User,
	User\Subscription,
	Orders,
	Products,
	Stores
};

try {
	$User = new User('15F92');
	$Subscription =	new Subscription($User);
	$Orders = new Orders($User);
	$Products = new Products();
	$Stores = new Stores($Products);

	print_r([
		# Notice here that the autoship is appended to the user data
		# when creating instance of Subscription
		$User->getData(),
		# This will just fetch the autoship by itself
		$Subscription->getOrder(),
		# Fetches a list of all products
		$Products->get(),
		# Fetches a specific sku
		$Products->getBySku('EXAMPLESKU123'),
		# Fetches the store regions
		$Stores->getRegions(),
		# Fetches the store cateories
		$Stores->getCategories()
	]);
}
catch(\DirectScale\Exception $e) {
	# It is worth noting that getting a single product by sku 

use \DirectScale\ {
    Model as Connection,
    User
};
# You will need a "dev" version of the API key
define('DIRECTSCALE_DEVAPIKEY', 'your123dev456key654here321');
# You can also save your regular key
define('DIRECTSCALE_APIKEY', 'your123prod456key543here210');
# Set the dev mode here
Connection::setMode('dev'); # <--- Comment out this line to make live
# Alternately, you can set the API key using the Model
# If using this method to set the API key, uncomment this line below, comment out the defines
# Connection::setApiKey('your123dev456key654here321');
# Start a user class
$User = new User(12345);
# Fetch the data
$info = $User->getDistInfo();
# Write out the api url
echo $User->getConnection()->getUrl();