1. Go to this page and download the library: Download kattatzu/ship-it 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/ */
kattatzu / ship-it example snippets
use Kattatzu/ShipIt/ShipIt;
$shipIt = new ShipIt('EMAIL', 'TOKEN', 'development');
// o
$shipIt = new ShipIt;
$shipIt->email('EMAIL');
$shipIt->token('TOKEN');
$shipIt->environment(ShipIt::ENV_PRODUCTION);
var_export($shipIt->getCommunes());
$regions = $shipIt->getRegions();
echo $regions[0]->name;
// "Arica y Parinacota"
$request = new QuotationRequest([
'commune_id' => 317, // id de la Comuna en ShipIt
'height' => 10, // altura en centimetros
'length' => 10, // largo en centimetros
'width' => 10, // ancho en centimetros
'weight' => 1 // peso en kilogramos
]);
$quotationItems = $shipIt->getQuotation($request)->getItems();
foreach($quotationItems as $item){
echo $item->courier . "<br>";
}
$request = new QuotationRequest(...);
$quotationItems = $shipIt->getQuotation($request)->toArray();
foreach($quotationItems as $item){
echo $item['total'] . "<br>";
}
$request = new QuotationRequest([
'commune_id' => 317, // id de la Comuna en ShipIt
'height' => 10, // altura en centimetros
'length' => 10, // largo en centimetros
'width' => 10, // ancho en centimetros
'weight' => 1 // peso en kilogramos
]);
$quotationItem = $shipIt->getEconomicQuotation($request);
echo $quotationItem->total;
// o como array
$quotationItem = $shipIt->getEconomicQuotation($request)->toArray();
echo $quotationItem['total'];
$request = new QuotationRequest([
'commune_id' => 317, // id de la Comuna en ShipIt
'height' => 10, // altura en centimetros
'length' => 10, // largo en centimetros
'width' => 10, // ancho en centimetros
'weight' => 1 // peso en kilogramos
]);
$quotationItem = $shipIt->getBestQuotation($request);
echo $quotationItem->total;
// o como array
$quotationItem = $shipIt->getBestQuotation($request)->toArray();
echo $quotationItem['total'];
$request = new ShippingRequest(...);
$response = $shipIt->requestShipping($request)->toArray();
echo $response['id'];
$history = $shipIt->getAllShippings('2017-04-06');
// ó
$history = $shipIt->getAllShippings(Carbon::yesterday());
// ó
$history = $shipIt->getAllShippings(); // Por defecto será la fecha actual
foreach($history->getShippings() as $shipping){
echo $shipping->id . "<br>";
}