Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
ini_set("allow_url_fopen", "1");
require_once(dirname(__FILE__).'/../../config/config.inc.php');
require_once(dirname(__FILE__).'/../../init.php');
// Put your API Key here
$api_key = "";
$state_in_transit = Configuration::get('PS_OS_SHIPPING');
$state_delivered = Configuration::get('PS_OS_DELIVERED');
$sql = Db::getInstance()->executeS('SELECT * FROM '._DB_PREFIX_.'orders WHERE current_state = '.$state_in_transit);
foreach ($sql as $key => $value) {
if(!empty($value['shipping_number'])){
$url = "https://api.aftership.com/v3/trackings/la-poste-colissimo/".str_replace(" ", "", $value['shipping_number']);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'aftership-api-key: '.$api_key
));
curl_setopt($curl, CURLOPT_POST, false);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
$response = json_decode($json_response, true);
if(strtolower($response['data']['tracking']['tag'])=='delivered'){
$id_order = $value['id_order'];
$order = new Order($value['id_order']);
$changeHistory = new OrderHistory();
$changeHistory->id_order = $id_order;
$changeHistory->changeIdOrderState((int)$state_delivered, $order, true);
$changeHistory->addWithemail(true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.