Created
August 29, 2014 14:52
-
-
Save williangringo/7b390ce954fd43b25b5e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Change current directory to the directory of current script | |
chdir(dirname(__FILE__)); | |
require '../app/Mage.php'; | |
umask(0); | |
Mage::init("","store"); | |
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); | |
const SHIPPING_SUCCESS_MSG = "Entrega Efetuada"; | |
const STATUS_IN_TRANSPORT = "in_transport"; | |
const STATUS_DELIVERED = "delivery"; | |
$orders = Mage::getModel('sales/order')->getCollection() | |
->addFieldToFilter('status', STATUS_IN_TRANSPORT); | |
$successShipping = 0; | |
foreach ($orders as $order) { | |
try { | |
$trackinList = $order->getTracksCollection(); | |
if (count($trackinList)>0) { | |
foreach ($trackinList as $tracking) { | |
$correiosMethod = new PedroTeixeira_Correios_Model_Carrier_CorreiosMethod(); | |
$r = $correiosMethod->getTracking($tracking['track_number'])->getAllTrackings(); | |
if (count($r[0])>0) { | |
$status = $r[0]['status']; | |
if ($status == SHIPPING_SUCCESS_MSG) { | |
// - Alterar o status para 'entregue' | |
$msgSuccess = "ATUALIZADO CORREIOS [ " . $r[0]['status'] . " - " . $r[0]['deliverydate'] . " - " . $r[0]['deliverytime']; | |
$order->addStatusToHistory( | |
STATUS_DELIVERED, | |
$msgSuccess, | |
false | |
)->save(); | |
$successShipping++; | |
} | |
} else { | |
throw new Exception("Not found info by tracking", 1); | |
} | |
} | |
} | |
} catch (Exception $e) { | |
echo "error in order [" . $order->getData("increment_id") . "] - " . $e->getMessage(); | |
} | |
} | |
echo "{$successShipping} entregas atualizadas\n"; | |
exit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment