Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from mrmonsters/hotfix-tracking-upload-exceptio…
Browse files Browse the repository at this point in the history
…n-20180116

fixed tracking upload exception
  • Loading branch information
mrmonsters committed Jan 26, 2018
2 parents b9efe74 + 9070ed2 commit 5fa9e8e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
22 changes: 17 additions & 5 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use AfterShip\AfterShipException;
use AfterShip\Trackings;
use Magento\Directory\Model\CountryFactory;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Sales\Model\Order;
Expand All @@ -26,6 +27,7 @@ class Data extends AbstractHelper {
protected $_storeManager;
protected $_trackFactory;
protected $_orderFactory;
protected $_countryFactory;
protected $_configHelper;

/**
Expand All @@ -35,14 +37,16 @@ public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
TrackFactory $trackFactory,
OrderFactory $orderFactory,
CountryFactory $countryFactory,
Config $configHelper,
Context $context
)
{
$this->_storeManager = $storeManager;
$this->_trackFactory = $trackFactory;
$this->_orderFactory = $orderFactory;
$this->_configHelper = $configHelper;
$this->_storeManager = $storeManager;
$this->_trackFactory = $trackFactory;
$this->_orderFactory = $orderFactory;
$this->_countryFactory = $countryFactory;
$this->_configHelper = $configHelper;

parent::__construct($context);
}
Expand Down Expand Up @@ -127,11 +131,18 @@ public function sendTrack(\Mrmonsters\Aftership\Model\Track $track)
$shippingAddress = $order->getShippingAddress();
$apiKey = $this->_configHelper->getExtensionApiKey($order->getStore()->getWebsiteId());
$tracking = new Trackings($apiKey);
$countryIso3 = $this->_countryFactory->create()
->loadByCode($shippingAddress->getCountryId());

try {

$this->_eventManager->dispatch('aftership_tracking_upload_before', [
'track' => $track
]);

$response = $tracking->create($track->getTrackingNumber(), [
'destination_country_iso3' => $shippingAddress->getCountryId(),
'slug' => $track->getShipCompCode(),
'destination_country_iso3' => $countryIso3->getData('iso3_code'),
'smses' => $shippingAddress->getTelephone(),
'emails' => $order->getCustomerEmail(),
'title' => $track->getOrderId(),
Expand All @@ -142,6 +153,7 @@ public function sendTrack(\Mrmonsters\Aftership\Model\Track $track)
$track->setPosted(self::POSTED_DONE)->save();
} catch (AfterShipException $e) {

} catch (\Exception $e) {

}
}
Expand Down
5 changes: 5 additions & 0 deletions Observer/AftershipOptionsConfigChangedObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public function execute(\Magento\Framework\Event\Observer $observer)
{
$postData = $_POST;

if (empty($postData)) {

return;
}

if (!isset($postData['groups']['messages']['fields']['api_key']['inherit']) ||
$postData['groups']['messages']['fields']['api_key']['inherit'] != 1
) {
Expand Down

0 comments on commit 5fa9e8e

Please sign in to comment.