Skip to content

Commit

Permalink
added shipment tracking support
Browse files Browse the repository at this point in the history
added a config file to local environment
* request exception fix
  • Loading branch information
bakkerpeter committed Feb 23, 2016
1 parent 5c4c0fe commit ebd4244
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 11 deletions.
11 changes: 10 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@

require_once(dirname(__FILE__) . '/vendor/autoload.php');


//Include our configs
require_once(dirname(__FILE__) . '/../config.php');


//Make sure this directory is writable
$cacheDirectory = dirname(__FILE__) . '/../cache/';

App::start('', '', '', $cacheDirectory);

App::start($url, $user, $password, $cacheDirectory);


$product = Product::model()
->setName('testProduct')
Expand Down Expand Up @@ -55,3 +62,5 @@
echo $stock->sku . ': ' . $stock->stock . "\n";
}

$shipment = Shipment::model()->findByPk('#123');
print_r($shipment);
4 changes: 2 additions & 2 deletions src/app/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ public function request($path, $data = array(), $method = null) {
}
try {
$this->response = new Response($this->getGuzzleClient()->request($this->getMethod($data, $method), $path, $this->additionalHeaders));
} catch (RequestException $e) {
echo $e->getMessage;
} catch (\Exception $e) {
echo $e->getMessage();
exit();
}
return $this->response;
Expand Down
21 changes: 21 additions & 0 deletions src/app/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,27 @@ public function findAll($attributes = array()) {
}
return $data;
}

/**
* Find by the primary key
* @param string $pk
* @return array
*/
public function findByPk($pk) {
$response = App::getInstance()->client->request($this->_getPath() . '/' . $this->findAction, array($this->primaryKey => $pk), $this->findMethod);
$result = $response->result;
if (count($result) == 1) {
$name = get_called_class();
$object = new $name;
foreach ($result[0] as $key => $value) {
//Fix the fact that for shipment data (only use case) properties
//are camelcase (as expected) but for all the other models aren't
$key = strtoupper(substr($key, 0,1)) . substr($key, 1);
$object->$key = $value;
}
return $object;
}
}

/**
* Return the data from the api
Expand Down
49 changes: 41 additions & 8 deletions src/models/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,52 @@
namespace Afosto\ActiveAnts;

class Shipment extends Model {


/**
* The key used to lookup the model at ActiveAnts
*/
protected $primaryKey = 'externalOrderNumber';

/**
* The id for the shipment
* @var integer
*/
public $Id;


/**
* The external order number (given from your application)
* @var string
*/
public $ExternalOrderNumber;


/**
* The shipping date, the day the package(s) are sent
* @var string
*/
public $ShippingDate;


/**
* Deprecated, not always set
* @var string
*/
public $TrackingNumber;


/**
* The number of packages
* @var integer
*/
public $NumberOfColli;


/**
* The amount of products for this shipment
* @var integer
*/
public $TotalNumberOfProducts;


/**
* The track and trace link (url to follow shipment)
* @var string
*/
public $TrackAndTraceCode;

}

0 comments on commit ebd4244

Please sign in to comment.