PHP code example of detrack / detrack-core

1. Go to this page and download the library: Download detrack/detrack-core 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/ */

    

detrack / detrack-core example snippets




Detrack\DetrackCore\Client\DetrackClientStatic::setApiKey($apiKey);

use Detrack\DetrackCore\Resource\Job;

$delivery = new Job([
  "date"=>"2018-12-19",
  "do_number"=>"DO# 12345",
  "address"=>"Null Island",
  "instructions"=>"Tell recipient to come out and retrieve ice cream from van" //not 

use Detrack\DetrackCore\Resource\Job;

$delivery = new Job();
$delivery->date = "2018-12-19";
$delivery->do_number = "DO# 12345";
$delivery->address = "Null Island";
$delivery->instructions = "Tell recipient to come out and retrieve ice cream from van"; //not 

use Detrack\DetrackCore\Resource\Model\Item;

$item = new Item([
  "sku"=>"IC 456",
  "qty"=>"5",
  "desc"=>"Strawberry flavoured ice-cream"
]);

use Detrack\DetrackCore\Model\Item;

$item = new Item();
$item->sku = "IC 456";
$item->qty = "5";
$item->desc = "Strawberry flavoured ice-cream";

$delivery->items->add($item);
$delivery->save() //sends the info to Detrack

// Update instructions
$delivery->instructions = "Change of plan, leave ice cream package in the mailbox instead";
$delivery->save();

// Customer no longer wants ice cream
$delivery->delete();

$delivery = new Job();
$delivery->do_number = "DO# 12345";
$delivery->address = "PHP Island";
$delivery->date = date("Y-m-d");
$delivery->items->add(new Item(["sku"=>"1","qty"=>5,"desc"=>"Chocolate Ice Cream"]));

//will throw exception
$delivery->update();
//ok
$delivery->create();

$delivery->items->pop();
$delivery->items->add(new Item(["sku"=>"2","qty"=>5,"desc"=>"Strawberry Ice Cream"]));
//will throw exception
$delivery->create();
//ok
$delivery->update();

use Detrack\DetrackCore\Resource\Vehicle;

$vehicle = new Vehicle();
$vehicle->detrack_id = "SGVsbG8gV29ybGQ";
$vehicle->name = "Tom's Van";
$vehicle->save();
//or
$vehicle->create();

$tomsVehicle = new Vehicle();
$tomsVehicle->name = "Tom's Van";
$tomsVehicle = $tomsVehicle->hydrate(); //optional, assignTo will do it for you anyway

$delivery->assignTo($tomsVehicle);

echo $delivery->getVehicle()->name;
//prints "Tom's Van"
sh
git clone https://github.com/detrack/detrack-core-php.git .
composer install