Version Notes
First release which has been in production for several months on multiple sites.
Download this release
Release Info
| Developer | George Plummer |
| Extension | Rvtech_Starshipit |
| Version | 1.0.0.0 |
| Comparing to | |
| See all releases | |
Version 1.0.0.0
- app/code/community/Rvtech/Starshipit/Block/Adminhtml/System/Config/Form/Button.php +51 -0
- app/code/community/Rvtech/Starshipit/Block/Adminhtml/System/Config/Form/Syncbutton.php +50 -0
- app/code/community/Rvtech/Starshipit/Helper/Data.php +4 -0
- app/code/community/Rvtech/Starshipit/Helper/Starship.php +163 -0
- app/code/community/Rvtech/Starshipit/Helper/Starship.php_ORG +137 -0
- app/code/community/Rvtech/Starshipit/Model/Observer.php +110 -0
- app/code/community/Rvtech/Starshipit/Model/Orders.php +468 -0
- app/code/community/Rvtech/Starshipit/Model/Orders.php_ORG +437 -0
- app/code/community/Rvtech/Starshipit/controllers/Adminhtml/StarshipitController.php +124 -0
- app/code/community/Rvtech/Starshipit/controllers/Adminhtml/StarshipitController.php_ORG +101 -0
- app/code/community/Rvtech/Starshipit/controllers/IndexController.php +7 -0
- app/code/community/Rvtech/Starshipit/etc/adminhtml.xml +21 -0
- app/code/community/Rvtech/Starshipit/etc/config.xml +74 -0
- app/code/community/Rvtech/Starshipit/etc/system.xml +96 -0
- app/code/community/Rvtech/Starshipquote/Block/Dhlform.php +17 -0
- app/code/community/Rvtech/Starshipquote/Helper/Data.php +10 -0
- app/code/community/Rvtech/Starshipquote/Helper/Dhl.php +41 -0
- app/code/community/Rvtech/Starshipquote/controllers/DhlquoteController.php +17 -0
- app/code/community/Rvtech/Starshipquote/etc/adminhtml.xml +0 -0
- app/code/community/Rvtech/Starshipquote/etc/config.xml +59 -0
- app/code/community/Rvtech/Starshipquote/etc/system.xml +54 -0
- app/design/adminhtml/default/default/template/starshipit/system/config/button.phtml +23 -0
- app/design/adminhtml/default/default/template/starshipit/system/config/syncbutton.phtml +22 -0
- app/etc/modules/Rvtech_Startshipit.xml +9 -0
- package.xml +22 -0
app/code/community/Rvtech/Starshipit/Block/Adminhtml/System/Config/Form/Button.php
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Rvtech_Starshipit_Block_Adminhtml_System_Config_Form_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
|
| 3 |
+
{
|
| 4 |
+
/*
|
| 5 |
+
* Set template
|
| 6 |
+
*/
|
| 7 |
+
protected function _construct()
|
| 8 |
+
{
|
| 9 |
+
parent::_construct();
|
| 10 |
+
$this->setTemplate('starshipit/system/config/button.phtml');
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* Return element html
|
| 15 |
+
*
|
| 16 |
+
* @param Varien_Data_Form_Element_Abstract $element
|
| 17 |
+
* @return string
|
| 18 |
+
*/
|
| 19 |
+
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
|
| 20 |
+
{
|
| 21 |
+
return $this->_toHtml();
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
/**
|
| 25 |
+
* Return ajax url for button
|
| 26 |
+
*
|
| 27 |
+
* @return string
|
| 28 |
+
*/
|
| 29 |
+
public function getAjaxCheckUrl()
|
| 30 |
+
{
|
| 31 |
+
return Mage::helper('adminhtml')->getUrl('adminhtml/adminhtml_starshipit/test');
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
/**
|
| 35 |
+
* Generate button html
|
| 36 |
+
*
|
| 37 |
+
* @return string
|
| 38 |
+
*/
|
| 39 |
+
public function getButtonHtml()
|
| 40 |
+
{
|
| 41 |
+
$button = $this->getLayout()->createBlock('adminhtml/widget_button')
|
| 42 |
+
->setData(array(
|
| 43 |
+
'id' => 'starshipit_test_button',
|
| 44 |
+
'label' => $this->helper('adminhtml')->__('Test'),
|
| 45 |
+
'onclick' => 'javascript:test(); return false;'
|
| 46 |
+
));
|
| 47 |
+
|
| 48 |
+
return $button->toHtml();
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
}
|
app/code/community/Rvtech/Starshipit/Block/Adminhtml/System/Config/Form/Syncbutton.php
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Rvtech_Starshipit_Block_Adminhtml_System_Config_Form_Syncbutton extends Mage_Adminhtml_Block_System_Config_Form_Field
|
| 3 |
+
{
|
| 4 |
+
/*
|
| 5 |
+
* Set template
|
| 6 |
+
*/
|
| 7 |
+
protected function _construct()
|
| 8 |
+
{
|
| 9 |
+
parent::_construct();
|
| 10 |
+
$this->setTemplate('starshipit/system/config/syncbutton.phtml');
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* Return element html
|
| 15 |
+
*
|
| 16 |
+
* @param Varien_Data_Form_Element_Abstract $element
|
| 17 |
+
* @return string
|
| 18 |
+
*/
|
| 19 |
+
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
|
| 20 |
+
{
|
| 21 |
+
return $this->_toHtml();
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
/**
|
| 25 |
+
* Return ajax url for button
|
| 26 |
+
*
|
| 27 |
+
* @return string
|
| 28 |
+
*/
|
| 29 |
+
public function getAjaxCheckUrl()
|
| 30 |
+
{
|
| 31 |
+
return Mage::helper('adminhtml')->getUrl('adminhtml/adminhtml_starshipit/syncOrder');
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
/**
|
| 35 |
+
* Generate button html
|
| 36 |
+
*
|
| 37 |
+
* @return string
|
| 38 |
+
*/
|
| 39 |
+
public function getButtonHtml()
|
| 40 |
+
{
|
| 41 |
+
$button = $this->getLayout()->createBlock('adminhtml/widget_button')
|
| 42 |
+
->setData(array(
|
| 43 |
+
'id' => 'starshipit_test_button',
|
| 44 |
+
'label' => $this->helper('adminhtml')->__('Sync Orders'),
|
| 45 |
+
'onclick' => 'javascript:syncOrder(); return false;'
|
| 46 |
+
));
|
| 47 |
+
|
| 48 |
+
return $button->toHtml();
|
| 49 |
+
}
|
| 50 |
+
}
|
app/code/community/Rvtech/Starshipit/Helper/Data.php
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Rvtech_Starshipit_Helper_Data extends Mage_Core_Helper_Abstract
|
| 3 |
+
{
|
| 4 |
+
}
|
app/code/community/Rvtech/Starshipit/Helper/Starship.php
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Rvtech_Starshipit_Helper_Starship extends Mage_Core_Helper_Abstract
|
| 3 |
+
{
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
public $_wsdl = 'http://dhl.starshipit.com/OrdersService.svc?singleWsdl';
|
| 7 |
+
|
| 8 |
+
public $_syncMsg = '';
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
*
|
| 12 |
+
* @return php soap client object
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
protected function _soapClient() {
|
| 16 |
+
|
| 17 |
+
$wsdl = $this->_wsdl;
|
| 18 |
+
return new SoapClient($wsdl, array('trace' => 1));
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
protected function _getAuthDetails(){
|
| 23 |
+
|
| 24 |
+
return Mage::getModel('starshipit/orders')->getAuthDetails();
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* Call to Validate method of Soap
|
| 29 |
+
* @return string
|
| 30 |
+
*/
|
| 31 |
+
|
| 32 |
+
public function validateUser($authTo = array()) {
|
| 33 |
+
|
| 34 |
+
$soap = $this->_soapClient();
|
| 35 |
+
if(!empty($authTo)) {
|
| 36 |
+
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
|
| 37 |
+
Mage::getModel('core/config')
|
| 38 |
+
->saveConfig('starshipit_options/group1/username', $authTo['userName']);
|
| 39 |
+
Mage::getModel('core/config')
|
| 40 |
+
->saveConfig('starshipit_options/group1/api_key', $authTo['apiKey']);
|
| 41 |
+
}else {
|
| 42 |
+
$authTo = $this->_getAuthDetails();
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
$validate = $soap->__soapCall('Validate',array(
|
| 47 |
+
'Validate' => $authTo,
|
| 48 |
+
));
|
| 49 |
+
|
| 50 |
+
$result = $validate->ValidateResult;
|
| 51 |
+
|
| 52 |
+
return $result;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* Format the Post Data.
|
| 57 |
+
*
|
| 58 |
+
* @return array
|
| 59 |
+
*/
|
| 60 |
+
|
| 61 |
+
public function arrangePostData($params = array()){
|
| 62 |
+
$postData = array();
|
| 63 |
+
$postData['username'] = $params['groups']['group1']['fields']['username']['value'];
|
| 64 |
+
$postData['api_key'] = $params['groups']['group1']['fields']['api_key']['value'];
|
| 65 |
+
$postData['update_orders'] = $params['groups']['group1']['fields']['update_orders']['value'];
|
| 66 |
+
$postData['sync_orders_yesno'] = $params['groups']['group1']['fields']['sync_orders_yesno']['value'];
|
| 67 |
+
$postData['sync_orders'] = $params['groups']['group1']['fields']['sync_orders']['value'];
|
| 68 |
+
return $postData;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* Prepare an array in Magento acceptable form
|
| 73 |
+
* from the existing orders returned via Starship
|
| 74 |
+
* @return array
|
| 75 |
+
*/
|
| 76 |
+
|
| 77 |
+
public function finalOrderArrOverStarShip($orders) {
|
| 78 |
+
|
| 79 |
+
$finOrderArr = array();
|
| 80 |
+
$ordersArr = (array) $orders;
|
| 81 |
+
if(isset($ordersArr[0])){
|
| 82 |
+
foreach ($ordersArr as $order) {
|
| 83 |
+
$finOrderArr[$order->Id] = date("Y-m-d H:i:s", strtotime($order->LastUpdate));
|
| 84 |
+
}
|
| 85 |
+
}
|
| 86 |
+
else{
|
| 87 |
+
$finOrderArr[$ordersArr['Id']] = date("Y-m-d H:i:s", strtotime($ordersArr['LastUpdate']));
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
return $finOrderArr;
|
| 91 |
+
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
/**
|
| 95 |
+
* Call to GetExisting method of soap-server.
|
| 96 |
+
* Check the existing orders at Starship
|
| 97 |
+
* @return object
|
| 98 |
+
*/
|
| 99 |
+
public function getExistingOrders($order = array()) {
|
| 100 |
+
|
| 101 |
+
$soap = $this->_soapClient();
|
| 102 |
+
$orders = $soap->__soapCall('GetExisting',array(
|
| 103 |
+
'GetExisting' => array('existing' => $order),
|
| 104 |
+
));
|
| 105 |
+
|
| 106 |
+
return $orders;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/**
|
| 110 |
+
* Call to soap method AddShipment.
|
| 111 |
+
* For adding/sync oredrs to the StarShip
|
| 112 |
+
* @return string
|
| 113 |
+
*/
|
| 114 |
+
|
| 115 |
+
public function addShipment($order = array()){
|
| 116 |
+
|
| 117 |
+
$soap = $this->_soapClient();
|
| 118 |
+
$orders = $soap->__soapCall('AddShipment',array(
|
| 119 |
+
'AddShipment' => array('orders' => $order),
|
| 120 |
+
));
|
| 121 |
+
|
| 122 |
+
return $orders;
|
| 123 |
+
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
/**
|
| 127 |
+
* Check condition for Writing Tracking info and
|
| 128 |
+
* creating shippment in Magento
|
| 129 |
+
* @return boolean
|
| 130 |
+
*/
|
| 131 |
+
|
| 132 |
+
public function checkCondForMagentoWritebacks($response) {
|
| 133 |
+
|
| 134 |
+
$success = $response->AddShipmentResult;
|
| 135 |
+
$update = Mage::getModel('starshipit/orders')->needToUpdateOredrsInMage();
|
| 136 |
+
|
| 137 |
+
if($success === 'Success' && ($update)) {
|
| 138 |
+
return true;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
return false;
|
| 142 |
+
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
/**
|
| 146 |
+
* Call to GetMagentoWritebacks method of Soap service
|
| 147 |
+
* call only if "Update orders to complete once shipped" is set to Yes
|
| 148 |
+
* Return the Tracking info ONLY ONECE
|
| 149 |
+
* @return object
|
| 150 |
+
*/
|
| 151 |
+
|
| 152 |
+
public function getMagentoWritebacks(){
|
| 153 |
+
$soap = $this->_soapClient();
|
| 154 |
+
$authTo = $this->_getAuthDetails();
|
| 155 |
+
$orders = $soap->__soapCall('GetMagentoWritebacks',array(
|
| 156 |
+
'GetMagentoWritebacks' => $authTo
|
| 157 |
+
));
|
| 158 |
+
|
| 159 |
+
return $orders;
|
| 160 |
+
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
}
|
app/code/community/Rvtech/Starshipit/Helper/Starship.php_ORG
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Rvtech_Starshipit_Helper_Starship extends Mage_Core_Helper_Abstract
|
| 3 |
+
{
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
public $_wsdl = 'http://dhl.starshipit.com/OrdersService.svc?singleWsdl';
|
| 7 |
+
|
| 8 |
+
public $_syncMsg = '';
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
*
|
| 12 |
+
* @return php soap client object
|
| 13 |
+
*/
|
| 14 |
+
|
| 15 |
+
protected function _soapClient() {
|
| 16 |
+
|
| 17 |
+
$wsdl = $this->_wsdl;
|
| 18 |
+
return new SoapClient($wsdl, array('trace' => 1));
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
protected function _getAuthDetails(){
|
| 23 |
+
|
| 24 |
+
return Mage::getModel('starshipit/orders')->getAuthDetails();
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* Call to Validate method of Soap
|
| 29 |
+
* @return string
|
| 30 |
+
*/
|
| 31 |
+
|
| 32 |
+
public function validateUser() {
|
| 33 |
+
|
| 34 |
+
$soap = $this->_soapClient();
|
| 35 |
+
$authTo = $this->_getAuthDetails();
|
| 36 |
+
$validate = $soap->__soapCall('Validate',array(
|
| 37 |
+
'Validate' => $authTo,
|
| 38 |
+
));
|
| 39 |
+
|
| 40 |
+
$result = $validate->ValidateResult;
|
| 41 |
+
|
| 42 |
+
return $result;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
/**
|
| 46 |
+
* Prepare an array in Magento acceptable form
|
| 47 |
+
* from the existing orders returned via Starship
|
| 48 |
+
* @return array
|
| 49 |
+
*/
|
| 50 |
+
|
| 51 |
+
public function finalOrderArrOverStarShip($orders) {
|
| 52 |
+
|
| 53 |
+
$finOrderArr = array();
|
| 54 |
+
$ordersArr = (array) $orders;
|
| 55 |
+
if(isset($ordersArr[0])){
|
| 56 |
+
foreach ($ordersArr as $order) {
|
| 57 |
+
$finOrderArr[$order->Id] = date("Y-m-d H:i:s", strtotime($order->LastUpdate));
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
else{
|
| 61 |
+
$finOrderArr[$ordersArr['Id']] = date("Y-m-d H:i:s", strtotime($ordersArr['LastUpdate']));
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
return $finOrderArr;
|
| 65 |
+
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
/**
|
| 69 |
+
* Call to GetExisting method of soap-server.
|
| 70 |
+
* Check the existing orders at Starship
|
| 71 |
+
* @return object
|
| 72 |
+
*/
|
| 73 |
+
public function getExistingOrders($order = array()) {
|
| 74 |
+
|
| 75 |
+
$soap = $this->_soapClient();
|
| 76 |
+
$orders = $soap->__soapCall('GetExisting',array(
|
| 77 |
+
'GetExisting' => array('existing' => $order),
|
| 78 |
+
));
|
| 79 |
+
|
| 80 |
+
return $orders;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
/**
|
| 84 |
+
* Call to soap method AddShipment.
|
| 85 |
+
* For adding/sync oredrs to the StarShip
|
| 86 |
+
* @return string
|
| 87 |
+
*/
|
| 88 |
+
|
| 89 |
+
public function addShipment($order = array()){
|
| 90 |
+
|
| 91 |
+
$soap = $this->_soapClient();
|
| 92 |
+
$orders = $soap->__soapCall('AddShipment',array(
|
| 93 |
+
'AddShipment' => array('orders' => $order),
|
| 94 |
+
));
|
| 95 |
+
|
| 96 |
+
return $orders;
|
| 97 |
+
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/**
|
| 101 |
+
* Check condition for Writing Tracking info and
|
| 102 |
+
* creating shippment in Magento
|
| 103 |
+
* @return boolean
|
| 104 |
+
*/
|
| 105 |
+
|
| 106 |
+
public function checkCondForMagentoWritebacks($response) {
|
| 107 |
+
|
| 108 |
+
$success = $response->AddShipmentResult;
|
| 109 |
+
$update = Mage::getModel('starshipit/orders')->needToUpdateOredrsInMage();
|
| 110 |
+
|
| 111 |
+
if($success === 'Success' && ($update)) {
|
| 112 |
+
return true;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
return false;
|
| 116 |
+
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
/**
|
| 120 |
+
* Call to GetMagentoWritebacks method of Soap service
|
| 121 |
+
* call only if "Update orders to complete once shipped" is set to Yes
|
| 122 |
+
* Return the Tracking info ONLY ONECE
|
| 123 |
+
* @return object
|
| 124 |
+
*/
|
| 125 |
+
|
| 126 |
+
public function getMagentoWritebacks(){
|
| 127 |
+
$soap = $this->_soapClient();
|
| 128 |
+
$authTo = $this->_getAuthDetails();
|
| 129 |
+
$orders = $soap->__soapCall('GetMagentoWritebacks',array(
|
| 130 |
+
'GetMagentoWritebacks' => $authTo
|
| 131 |
+
));
|
| 132 |
+
|
| 133 |
+
return $orders;
|
| 134 |
+
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
}
|
app/code/community/Rvtech/Starshipit/Model/Observer.php
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Rvtech_Starshipit_Model_Observer {
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
protected $_noticeTitle = 'Starship Automatic Synchronization';
|
| 7 |
+
|
| 8 |
+
protected $_noticeStatus;
|
| 9 |
+
|
| 10 |
+
public function syncOrdersNow() {
|
| 11 |
+
|
| 12 |
+
$noticeMsg = '';
|
| 13 |
+
$helper = Mage::helper('starshipit/starship');
|
| 14 |
+
|
| 15 |
+
$orderObj = Mage::getModel('starshipit/orders');
|
| 16 |
+
|
| 17 |
+
//get the configuration array (username, apikey etc.)
|
| 18 |
+
$para = $orderObj->getDataForExistingOredrs();
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
//get existing orders from Starship
|
| 22 |
+
$existingOrderRes = $helper->getExistingOrders($para);
|
| 23 |
+
|
| 24 |
+
if(empty($existingOrderRes->GetExistingResult->ErrorMessage)){
|
| 25 |
+
$resOrders = $existingOrderRes
|
| 26 |
+
->GetExistingResult
|
| 27 |
+
->Orders;
|
| 28 |
+
$odersArr = array();
|
| 29 |
+
try{
|
| 30 |
+
if(isset($resOrders->ExistingOrder)){
|
| 31 |
+
$resExistingOrder = $resOrders->ExistingOrder;
|
| 32 |
+
$odersArr = $helper->finalOrderArrOverStarShip($resExistingOrder);
|
| 33 |
+
}
|
| 34 |
+
}catch(Exception $e){
|
| 35 |
+
|
| 36 |
+
$this->_noticeStatus = 3;
|
| 37 |
+
$noticeMsg .= $e->getMessage();
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
if(!empty($odersArr)) {
|
| 41 |
+
//get Orders array to sync with StarShip
|
| 42 |
+
$ordersToPass = $orderObj->prepareOrderToPass($odersArr);
|
| 43 |
+
|
| 44 |
+
if(empty($ordersToPass['Orders'])) {
|
| 45 |
+
$noticeMsg .= 'No order found for sync to Starship';
|
| 46 |
+
$this->_noticeStatus = 0;
|
| 47 |
+
}else{
|
| 48 |
+
|
| 49 |
+
$noticeMsg .= 'Orders sync to Starship';
|
| 50 |
+
$this->_noticeStatus = 1;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
//Sync orders and store resonpse
|
| 54 |
+
$resShipSync = $helper->addShipment($ordersToPass);
|
| 55 |
+
|
| 56 |
+
//Change Order State and add Track Info
|
| 57 |
+
if($helper->checkCondForMagentoWritebacks($resShipSync)) {
|
| 58 |
+
$resWriteBack = $helper->getMagentoWritebacks();
|
| 59 |
+
//$this->getResponse()->setBody(print_r($resWriteBack));
|
| 60 |
+
if(isset($resWriteBack->GetMagentoWritebacksResult->WritebackStruct)){
|
| 61 |
+
$isTackadded = $orderObj->addTrackingInfo($resWriteBack);
|
| 62 |
+
if($isTackadded) {
|
| 63 |
+
|
| 64 |
+
$noticeMsg .= 'Tracking Info SAVED';
|
| 65 |
+
$this->_noticeStatus += 1;
|
| 66 |
+
}
|
| 67 |
+
}else{
|
| 68 |
+
|
| 69 |
+
$noticeMsg .= 'No tracking info found on Starship';
|
| 70 |
+
$this->_noticeStatus += 0;
|
| 71 |
+
}
|
| 72 |
+
}else{
|
| 73 |
+
if($this->_noticeStatus){
|
| 74 |
+
$this->_noticeStatus += 1;
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
}else{
|
| 79 |
+
|
| 80 |
+
$this->_noticeStatus = 3;
|
| 81 |
+
$noticeMsg .= $existingOrderRes->GetExistingResult->ErrorMessage;
|
| 82 |
+
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
$this->_addNotice($noticeMsg);
|
| 86 |
+
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
protected function _addNotice($msg)
|
| 90 |
+
{
|
| 91 |
+
$notice = Mage::getModel('adminNotification/inbox');
|
| 92 |
+
|
| 93 |
+
switch ($this->_noticeStatus) {
|
| 94 |
+
case 0:
|
| 95 |
+
$notice->add(2,$this->_noticeTitle,$msg);
|
| 96 |
+
break;
|
| 97 |
+
case 1:
|
| 98 |
+
$notice->add(3,$this->_noticeTitle,$msg);
|
| 99 |
+
break;
|
| 100 |
+
case 3:
|
| 101 |
+
$notice->add(1,$this->_noticeTitle,$msg);
|
| 102 |
+
break;
|
| 103 |
+
|
| 104 |
+
default:
|
| 105 |
+
$notice->add(4,$this->_noticeTitle,$msg);
|
| 106 |
+
break;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
}
|
| 110 |
+
}
|
app/code/community/Rvtech/Starshipit/Model/Orders.php
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Rvtech_Starshipit_Model_Orders extends Mage_Sales_Model_Order {
|
| 4 |
+
|
| 5 |
+
protected $_User;
|
| 6 |
+
|
| 7 |
+
protected $_APIKey;
|
| 8 |
+
|
| 9 |
+
protected $_auth = array();
|
| 10 |
+
|
| 11 |
+
protected $_orderInMage = array();
|
| 12 |
+
|
| 13 |
+
protected $_orderInStarShip = array();
|
| 14 |
+
|
| 15 |
+
protected $_dataForExistingOredrs = array();
|
| 16 |
+
|
| 17 |
+
public function _getUserName() {
|
| 18 |
+
|
| 19 |
+
return Mage::getStoreConfig('starshipit_options/group1/username');
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
public function _getAPIKey() {
|
| 23 |
+
|
| 24 |
+
return Mage::getStoreConfig('starshipit_options/group1/api_key');
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
protected function _getUpdateOrderConfig() {
|
| 28 |
+
|
| 29 |
+
return Mage::getStoreConfig('starshipit_options/group1/update_orders');
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
protected function _getSyncOrderConfig() {
|
| 33 |
+
|
| 34 |
+
return Mage::getStoreConfig('starshipit_options/group1/sync_orders');
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
protected function _getSyncOrderAutoConfig() {
|
| 38 |
+
|
| 39 |
+
return Mage::getStoreConfig('starshipit_options/group1/sync_orders_yesno');
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
protected function _getFormattedTelephone($order){
|
| 43 |
+
|
| 44 |
+
return str_replace('-', '', $order->getShippingAddress()->getData('telephone'));
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
protected function _saveStoreConfig($postData) {
|
| 48 |
+
|
| 49 |
+
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
|
| 50 |
+
Mage::getModel('core/config')
|
| 51 |
+
->saveConfig('starshipit_options/group1/username', $postData['username']);
|
| 52 |
+
Mage::getModel('core/config')
|
| 53 |
+
->saveConfig('starshipit_options/group1/api_key', $postData['api_key']);
|
| 54 |
+
Mage::getModel('core/config')
|
| 55 |
+
->saveConfig('starshipit_options/group1/update_orders', $postData['update_orders']);
|
| 56 |
+
Mage::getModel('core/config')
|
| 57 |
+
->saveConfig('starshipit_options/group1/sync_orders', $postData['sync_orders']);
|
| 58 |
+
Mage::getModel('core/config')
|
| 59 |
+
->saveConfig('starshipit_options/group1/sync_orders_yesno', $postData['sync_orders_yesno']);
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
public function getAuthDetails() {
|
| 64 |
+
|
| 65 |
+
$this->_auth = array(
|
| 66 |
+
|
| 67 |
+
'userName' => $this->_getUserName(),
|
| 68 |
+
'apiKey' => $this->_getAPIKey()
|
| 69 |
+
);
|
| 70 |
+
return $this->_auth;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
public function getDataForExistingOredrs($postData = array()) {
|
| 75 |
+
|
| 76 |
+
if(empty($postData))
|
| 77 |
+
{
|
| 78 |
+
return $this->_dataForExistingOredrs = array(
|
| 79 |
+
|
| 80 |
+
'User' => $this->_getUserName(),
|
| 81 |
+
'APIKey' => $this->_getAPIKey(),
|
| 82 |
+
'Days' => $this->_getSyncOrderConfig(),
|
| 83 |
+
'Orders' => $this->_getUpdateOrderConfig(),
|
| 84 |
+
|
| 85 |
+
);
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
$this->_saveStoreConfig($postData);
|
| 89 |
+
|
| 90 |
+
$this->_dataForExistingOredrs = array(
|
| 91 |
+
|
| 92 |
+
'User' => $postData['username'],
|
| 93 |
+
'APIKey' => $postData['api_key'],
|
| 94 |
+
'Days' => $postData['sync_orders'],
|
| 95 |
+
'Orders' => $postData['update_orders'],
|
| 96 |
+
|
| 97 |
+
);
|
| 98 |
+
|
| 99 |
+
return $this->_dataForExistingOredrs;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
/**
|
| 103 |
+
* Convert date array to UTC
|
| 104 |
+
* for comaprison purpose
|
| 105 |
+
* @return array
|
| 106 |
+
*/
|
| 107 |
+
|
| 108 |
+
protected function _formatDateUtc($dateArr = array()){
|
| 109 |
+
|
| 110 |
+
$dateUtcArr = array();
|
| 111 |
+
foreach ($dateArr as $id => $date) {
|
| 112 |
+
$dateUtcArr[$id] = strtotime($date);
|
| 113 |
+
}
|
| 114 |
+
return $dateUtcArr;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
/**
|
| 118 |
+
* Convert date in Starship Accpetable Format
|
| 119 |
+
*
|
| 120 |
+
* @return string
|
| 121 |
+
*/
|
| 122 |
+
|
| 123 |
+
protected function _formatDateStarShip($date){
|
| 124 |
+
|
| 125 |
+
return date('d/m/Y h:i:s A',strtotime($date));
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
/**
|
| 129 |
+
* Check all oredrs in Magento with status Processing
|
| 130 |
+
* and set their Ids as key and Update_at as value in Protected array _orderInMage
|
| 131 |
+
* @return none
|
| 132 |
+
*/
|
| 133 |
+
|
| 134 |
+
protected function _checkOrdersInMage() {
|
| 135 |
+
|
| 136 |
+
foreach ($this->getCollection() as $order) {
|
| 137 |
+
if(strtolower($order->getStatusLabel()) === self::STATE_PROCESSING) {
|
| 138 |
+
$this->_orderInMage[$order->getData('entity_id')] = $order->getData('updated_at');
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
/**
|
| 145 |
+
* Prepare a final array of Oredrs via comparing Orders in Mage and Oredrs in Starship
|
| 146 |
+
*
|
| 147 |
+
* @return array
|
| 148 |
+
*/
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
protected function _checkOrderToProcess($orders = array()) {
|
| 152 |
+
|
| 153 |
+
$ordersToProcess = array();
|
| 154 |
+
$this->_checkOrdersInMage();
|
| 155 |
+
$orderInStarShipUtc = $this->_formatDateUtc($this->_orderInStarShip);
|
| 156 |
+
$orderInMageUtc = $this->_formatDateUtc($this->_orderInMage);
|
| 157 |
+
|
| 158 |
+
foreach ($orderInMageUtc as $key => $value) {
|
| 159 |
+
if (array_key_exists($key,$orderInStarShipUtc)) {
|
| 160 |
+
if($value >= $orderInStarShipUtc[$key]){
|
| 161 |
+
$ordersToProcess[] = $key;
|
| 162 |
+
}
|
| 163 |
+
}else{
|
| 164 |
+
$ordersToProcess[] = $key;
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
return $ordersToProcess;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
/**
|
| 173 |
+
* Prepare Orders details to send over Starship
|
| 174 |
+
*
|
| 175 |
+
* @return array
|
| 176 |
+
*/
|
| 177 |
+
|
| 178 |
+
protected function _orderShippedArr($ordersToProcess = array()){
|
| 179 |
+
|
| 180 |
+
$orderList = array();
|
| 181 |
+
foreach ($this->getCollection() as $order) {
|
| 182 |
+
|
| 183 |
+
if(in_array($order->getData('entity_id'),$ordersToProcess)) {
|
| 184 |
+
|
| 185 |
+
$orderData['Id'] = $order->getData('entity_id');
|
| 186 |
+
$orderData['SequenceNumber'] = $order->getData('entity_id');
|
| 187 |
+
$orderData['SequenceGuid'] = null;
|
| 188 |
+
$orderData['OrginalSeqNumber'] = 0;
|
| 189 |
+
$orderData['AccountingAppId'] = 3;
|
| 190 |
+
$orderData['ShippedDate'] = $this->_getOrderShipmentCreatedDate($order);
|
| 191 |
+
$orderData['Date'] = $this->_formatDateStarShip($order->getData('created_at'));
|
| 192 |
+
$orderData['To'] = $this->_getOrderTo($order);
|
| 193 |
+
$orderData['OurRef'] = (string) $order->getData('increment_id');
|
| 194 |
+
$orderData['TheirRef'] = (string) $order->getData('entity_id');
|
| 195 |
+
$orderData['ConsigneeCode'] = '';
|
| 196 |
+
$orderData['Email'] = (string) $order->getData('customer_email');
|
| 197 |
+
$orderData['Telephone'] = (string) $this->_getFormattedTelephone($order);
|
| 198 |
+
$orderData['AddressString'] = (string) $this->_getOrderShippingAddress($order,true);
|
| 199 |
+
$orderData['ItemsString'] = (string) $this->_getOrderItemsStr($order);
|
| 200 |
+
$orderData['TrackingNumber'] = '';
|
| 201 |
+
$orderData['CarrierCode'] = 0;
|
| 202 |
+
$orderData['ProductName'] = 'P';
|
| 203 |
+
$orderData['ErrorMessage'] = '';
|
| 204 |
+
$orderData['Status'] = 0;
|
| 205 |
+
$orderData['TrackingCode'] = '';
|
| 206 |
+
$orderData['Invoiced'] = '';
|
| 207 |
+
$orderData['OrderValue'] = (float) $order->getData('total_qty_ordered');
|
| 208 |
+
$orderData['OrderCurrency'] = (string) $order->getData('global_currency_code');
|
| 209 |
+
$orderData['AddressChecked'] = true;
|
| 210 |
+
$orderData['AddressValidated'] = true;
|
| 211 |
+
$orderData['ShipmentDescription'] = "ShipmentDescription";
|
| 212 |
+
$orderData['Items'] = $this->_getOrderItemsArr($order);
|
| 213 |
+
$orderData['AddressDetails'] = $this->_getOrderShippingAddress($order);
|
| 214 |
+
$orderData['BillingAddress'] = (string) $this->_getOrderBillingAddress($order);
|
| 215 |
+
$orderData['LastUpdatedatSource'] = (string) $this->_formatDateStarShip($order->getData('updated_at'));
|
| 216 |
+
$orderList[] = $orderData;
|
| 217 |
+
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
return $orderList;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
/**
|
| 226 |
+
* Get shipment created date
|
| 227 |
+
*
|
| 228 |
+
* @return string
|
| 229 |
+
*/
|
| 230 |
+
|
| 231 |
+
protected function _getOrderShipmentCreatedDate($order){
|
| 232 |
+
|
| 233 |
+
$date = '';
|
| 234 |
+
if(!$order->canShip()){
|
| 235 |
+
$shipData = $order->getShipmentsCollection()->getData();
|
| 236 |
+
$date = $this->_formatDateStarShip($shipData[0]['created_at']);
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
return $date;
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
/**
|
| 243 |
+
* Get person name
|
| 244 |
+
*
|
| 245 |
+
* @return string
|
| 246 |
+
*/
|
| 247 |
+
|
| 248 |
+
protected function _getOrderTo($order){
|
| 249 |
+
|
| 250 |
+
$firstName = $order->getShippingAddress()->getData('firstname');
|
| 251 |
+
$lastName = $order->getShippingAddress()->getData('lastname');
|
| 252 |
+
$name = $firstName." ".$lastName;
|
| 253 |
+
return $name;
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
/**
|
| 257 |
+
* Get country full name
|
| 258 |
+
*
|
| 259 |
+
* @return string
|
| 260 |
+
*/
|
| 261 |
+
|
| 262 |
+
protected function _getCountryNameByCode($country_code){
|
| 263 |
+
|
| 264 |
+
return Mage::app()->getLocale()->getCountryTranslation($country_code);
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
/**
|
| 268 |
+
* Get shippment address
|
| 269 |
+
*
|
| 270 |
+
* @return string/array
|
| 271 |
+
*/
|
| 272 |
+
|
| 273 |
+
protected function _getOrderShippingAddress($order, $string = false ) {
|
| 274 |
+
|
| 275 |
+
$addArr = array();
|
| 276 |
+
$AddressDTO = array();
|
| 277 |
+
if($string){
|
| 278 |
+
$streetAdd = $order->getShippingAddress()->getData('street');
|
| 279 |
+
$street = trim(preg_replace('/\s+/', ' ', $streetAdd));
|
| 280 |
+
$city = $order->getShippingAddress()->getData('city');
|
| 281 |
+
$postcode = $order->getShippingAddress()->getData('postcode');
|
| 282 |
+
$countryCode = $order->getShippingAddress()->getData('country_id');
|
| 283 |
+
$country = $this->_getCountryNameByCode($countryCode);
|
| 284 |
+
$addString = $street."k ".$city." ".$postcode." ".$country;
|
| 285 |
+
return $addString;
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
$addArr['City'] = $order->getShippingAddress()->getData('city');
|
| 289 |
+
$addArr['Company'] = $order->getShippingAddress()->getData('company');
|
| 290 |
+
$addArr['Country'] = $this->_getCountryNameByCode($order->getShippingAddress()->getData('country_id'));
|
| 291 |
+
$addArr['CountryId'] = $order->getShippingAddress()->getData('country_id');
|
| 292 |
+
$addArr['Instructions'] = '';
|
| 293 |
+
$addArr['PostCode'] = $order->getShippingAddress()->getData('postcode');
|
| 294 |
+
$addArr['Region'] = $order->getShippingAddress()->getData('region');
|
| 295 |
+
$addArr['State'] = '';
|
| 296 |
+
$addArr['Street'] = $order->getShippingAddress()->getData('street');
|
| 297 |
+
$addArr['Suburb'] = '';
|
| 298 |
+
$AddressDTO['AddressDTO'] = $addArr;
|
| 299 |
+
return $addArr;
|
| 300 |
+
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
/**
|
| 304 |
+
* Get billing addresss
|
| 305 |
+
*
|
| 306 |
+
* @return string
|
| 307 |
+
*/
|
| 308 |
+
|
| 309 |
+
protected function _getOrderBillingAddress($order) {
|
| 310 |
+
|
| 311 |
+
$streetAdd = $order->getBillingAddress()->getData('street');
|
| 312 |
+
$street = trim(preg_replace('/\s+/', ' ', $streetAdd));
|
| 313 |
+
$city = $order->getBillingAddress()->getData('city');
|
| 314 |
+
$postcode = $order->getBillingAddress()->getData('postcode');
|
| 315 |
+
$country = $order->getBillingAddress()->getData('country_id');
|
| 316 |
+
$add = $street." ".$city." ".$postcode." ".$country;
|
| 317 |
+
|
| 318 |
+
return $add;
|
| 319 |
+
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
/**
|
| 323 |
+
* Get Oredrs Items as string
|
| 324 |
+
*
|
| 325 |
+
* @return string
|
| 326 |
+
*/
|
| 327 |
+
protected function _getOrderItemsStr($order) {
|
| 328 |
+
|
| 329 |
+
$allItemsArr = $order->getAllVisibleItems();
|
| 330 |
+
$itemsStr = '';
|
| 331 |
+
$lastItemArr = end($allItemsArr);
|
| 332 |
+
$count = count($allItemsArr);
|
| 333 |
+
foreach ($allItemsArr as $item) {
|
| 334 |
+
$itemsStr .= $item->getName();
|
| 335 |
+
if( $count > 1 && $item->getId() != $lastItemArr->getId())
|
| 336 |
+
$itemsStr .= ', ';
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
return $itemsStr;
|
| 340 |
+
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
/**
|
| 344 |
+
* Get Order's items
|
| 345 |
+
*
|
| 346 |
+
* @return array
|
| 347 |
+
*/
|
| 348 |
+
|
| 349 |
+
protected function _getOrderItemsArr($order, $string = false) {
|
| 350 |
+
|
| 351 |
+
$ItemsArr = array();
|
| 352 |
+
$shipmentitems = array();
|
| 353 |
+
foreach ($order->getAllVisibleItems() as $item) {
|
| 354 |
+
$ItemsArr['Description'] = (string)$item->getName();
|
| 355 |
+
$ItemsArr['Country'] = (string)$order->getShippingAddress()->getData('country_id');;
|
| 356 |
+
$ItemsArr['Price'] = (float)$item->getPrice();
|
| 357 |
+
$ItemsArr['Quantity'] = (int)round($item->getQtyOrdered());
|
| 358 |
+
$shipmentitems['ShipmentItem'][] = $ItemsArr;
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
return $shipmentitems;
|
| 362 |
+
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
/**
|
| 366 |
+
* Prepare final Orders Array with auth details to pass
|
| 367 |
+
* over the star ship
|
| 368 |
+
* @return array
|
| 369 |
+
*/
|
| 370 |
+
|
| 371 |
+
public function prepareOrderToPass($orders = array()) {
|
| 372 |
+
|
| 373 |
+
$this->_orderInStarShip = $orders;
|
| 374 |
+
$ordersToProcess = $this->_checkOrderToProcess($orders);
|
| 375 |
+
$arrOrdersToPass['UserName'] = $this->_getUserName();
|
| 376 |
+
$arrOrdersToPass['Password'] = $this->_getAPIKey();
|
| 377 |
+
$arrOrdersToPass['Orders'] = $this->_orderShippedArr($ordersToProcess);
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
return $arrOrdersToPass;
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
public function needToUpdateOredrsInMage(){
|
| 386 |
+
|
| 387 |
+
return $this->_getUpdateOrderConfig();
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
/**
|
| 393 |
+
* Create shippment and set the tracking info to ot
|
| 394 |
+
*
|
| 395 |
+
* @return
|
| 396 |
+
*/
|
| 397 |
+
|
| 398 |
+
protected function _setAndSaveTrackingInfo($orderId,$orderCarrier,$orderTrackingNumber){
|
| 399 |
+
|
| 400 |
+
foreach ($this->getCollection() as $order) {
|
| 401 |
+
if($order->getData('entity_id') == $orderId && $order->canShip()){
|
| 402 |
+
|
| 403 |
+
try {
|
| 404 |
+
|
| 405 |
+
$shipment = $order->prepareShipment();
|
| 406 |
+
$shipment->register();
|
| 407 |
+
$order->setIsInProcess(true);
|
| 408 |
+
$order->addStatusHistoryComment('Automatically SHIPPED by Starship.', false);
|
| 409 |
+
$transactionSave = Mage::getModel('core/resource_transaction')
|
| 410 |
+
->addObject($shipment)
|
| 411 |
+
->addObject($shipment->getOrder())
|
| 412 |
+
->save();
|
| 413 |
+
|
| 414 |
+
if($shipment->getId() != '') {
|
| 415 |
+
try{
|
| 416 |
+
$track = Mage::getModel('sales/order_shipment_track')
|
| 417 |
+
->setShipment($shipment)
|
| 418 |
+
->setData('number', $orderTrackingNumber)
|
| 419 |
+
->setData('carrier_code', strtolower($orderCarrier))
|
| 420 |
+
->setData('order_id', $shipment->getData('order_id'))
|
| 421 |
+
->save();
|
| 422 |
+
return true;
|
| 423 |
+
}catch(Exception $e){
|
| 424 |
+
|
| 425 |
+
Mage::getSingleton('core/session')
|
| 426 |
+
->addError($this->__('Shipment added But Error while adding Tracking details Error is: ').$e->getMessage());
|
| 427 |
+
}
|
| 428 |
+
}
|
| 429 |
+
}catch(Exception $e){
|
| 430 |
+
$order->addStatusHistoryComment('Starship_Invoicer: Exception occurred during action. Exception message: '.$e->getMessage(), false);
|
| 431 |
+
$order->save();
|
| 432 |
+
Mage::getSingleton('core/session')->addError($this->__('Exception Occured: ').$e->getMessage());
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
}
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
public function addTrackingInfo($trackingInfo) {
|
| 441 |
+
|
| 442 |
+
$WritebackStruct = $trackingInfo->GetMagentoWritebacksResult->WritebackStruct;
|
| 443 |
+
|
| 444 |
+
if(is_array($WritebackStruct)){
|
| 445 |
+
|
| 446 |
+
foreach ($WritebackStruct as $orderTrackInfo) {
|
| 447 |
+
$orderId = $orderTrackInfo->Sequence;
|
| 448 |
+
$orderCarrier = $orderTrackInfo->Carrier;
|
| 449 |
+
$orderTrackingNumber = $orderTrackInfo->TrackingNumber;
|
| 450 |
+
$this->_setAndSaveTrackingInfo($orderId,$orderCarrier,$orderTrackingNumber);
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
return true;
|
| 454 |
+
|
| 455 |
+
}else{
|
| 456 |
+
$orderId = $WritebackStruct->Sequence;
|
| 457 |
+
$orderCarrier = $WritebackStruct->Carrier;
|
| 458 |
+
$orderTrackingNumber = $WritebackStruct->TrackingNumber;
|
| 459 |
+
$this->_setAndSaveTrackingInfo($orderId,$orderCarrier,$orderTrackingNumber);
|
| 460 |
+
|
| 461 |
+
return true;
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
return false;
|
| 465 |
+
|
| 466 |
+
|
| 467 |
+
}
|
| 468 |
+
}
|
app/code/community/Rvtech/Starshipit/Model/Orders.php_ORG
ADDED
|
@@ -0,0 +1,437 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
class Rvtech_Starshipit_Model_Orders extends Mage_Sales_Model_Order {
|
| 4 |
+
|
| 5 |
+
protected $_User;
|
| 6 |
+
|
| 7 |
+
protected $_APIKey;
|
| 8 |
+
|
| 9 |
+
protected $_auth = array();
|
| 10 |
+
|
| 11 |
+
protected $_orderInMage = array();
|
| 12 |
+
|
| 13 |
+
protected $_orderInStarShip = array();
|
| 14 |
+
|
| 15 |
+
protected $_dataForExistingOredrs = array();
|
| 16 |
+
|
| 17 |
+
public function _getUserName() {
|
| 18 |
+
|
| 19 |
+
return Mage::getStoreConfig('starshipit_options/group1/username');
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
public function _getAPIKey() {
|
| 23 |
+
|
| 24 |
+
return Mage::getStoreConfig('starshipit_options/group1/api_key');
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
protected function _getUpdateOrderConfig() {
|
| 28 |
+
|
| 29 |
+
return Mage::getStoreConfig('starshipit_options/group1/update_orders');
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
protected function _getSyncOrderConfig() {
|
| 33 |
+
|
| 34 |
+
return Mage::getStoreConfig('starshipit_options/group1/sync_orders');
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
protected function _getSyncOrderAutoConfig() {
|
| 38 |
+
|
| 39 |
+
return Mage::getStoreConfig('starshipit_options/group1/sync_orders_yesno');
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
protected function _getFormattedTelephone($order){
|
| 43 |
+
|
| 44 |
+
return str_replace('-', '', $order->getShippingAddress()->getData('telephone'));
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
public function getAuthDetails() {
|
| 48 |
+
|
| 49 |
+
$this->_auth = array(
|
| 50 |
+
|
| 51 |
+
'userName' => $this->_getUserName(),
|
| 52 |
+
'apiKey' => $this->_getAPIKey()
|
| 53 |
+
);
|
| 54 |
+
return $this->_auth;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
public function getDataForExistingOredrs() {
|
| 58 |
+
|
| 59 |
+
$this->_dataForExistingOredrs = array(
|
| 60 |
+
|
| 61 |
+
'User' => $this->_getUserName(),
|
| 62 |
+
'APIKey' => $this->_getAPIKey(),
|
| 63 |
+
'Days' => $this->_getSyncOrderConfig(),
|
| 64 |
+
'Orders' => $this->_getUpdateOrderConfig(),
|
| 65 |
+
|
| 66 |
+
);
|
| 67 |
+
|
| 68 |
+
return $this->_dataForExistingOredrs;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* Convert date array to UTC
|
| 73 |
+
* for comaprison purpose
|
| 74 |
+
* @return array
|
| 75 |
+
*/
|
| 76 |
+
|
| 77 |
+
protected function _formatDateUtc($dateArr = array()){
|
| 78 |
+
|
| 79 |
+
$dateUtcArr = array();
|
| 80 |
+
foreach ($dateArr as $id => $date) {
|
| 81 |
+
$dateUtcArr[$id] = strtotime($date);
|
| 82 |
+
}
|
| 83 |
+
return $dateUtcArr;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
/**
|
| 87 |
+
* Convert date in Starship Accpetable Format
|
| 88 |
+
*
|
| 89 |
+
* @return string
|
| 90 |
+
*/
|
| 91 |
+
|
| 92 |
+
protected function _formatDateStarShip($date){
|
| 93 |
+
|
| 94 |
+
return date('d/m/Y h:i:s A',strtotime($date));
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
/**
|
| 98 |
+
* Check all oredrs in Magento with status Processing
|
| 99 |
+
* and set their Ids as key and Update_at as value in Protected array _orderInMage
|
| 100 |
+
* @return none
|
| 101 |
+
*/
|
| 102 |
+
|
| 103 |
+
protected function _checkOrdersInMage() {
|
| 104 |
+
|
| 105 |
+
foreach ($this->getCollection() as $order) {
|
| 106 |
+
if(strtolower($order->getStatusLabel()) === self::STATE_PROCESSING) {
|
| 107 |
+
$this->_orderInMage[$order->getData('entity_id')] = $order->getData('updated_at');
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/**
|
| 114 |
+
* Prepare a final array of Oredrs via comparing Orders in Mage and Oredrs in Starship
|
| 115 |
+
*
|
| 116 |
+
* @return array
|
| 117 |
+
*/
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
protected function _checkOrderToProcess($orders = array()) {
|
| 121 |
+
|
| 122 |
+
$ordersToProcess = array();
|
| 123 |
+
$this->_checkOrdersInMage();
|
| 124 |
+
$orderInStarShipUtc = $this->_formatDateUtc($this->_orderInStarShip);
|
| 125 |
+
$orderInMageUtc = $this->_formatDateUtc($this->_orderInMage);
|
| 126 |
+
|
| 127 |
+
foreach ($orderInMageUtc as $key => $value) {
|
| 128 |
+
if (array_key_exists($key,$orderInStarShipUtc)) {
|
| 129 |
+
if($value >= $orderInStarShipUtc[$key]){
|
| 130 |
+
$ordersToProcess[] = $key;
|
| 131 |
+
}
|
| 132 |
+
}else{
|
| 133 |
+
$ordersToProcess[] = $key;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
return $ordersToProcess;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
/**
|
| 142 |
+
* Prepare Orders details to send over Starship
|
| 143 |
+
*
|
| 144 |
+
* @return array
|
| 145 |
+
*/
|
| 146 |
+
|
| 147 |
+
protected function _orderShippedArr($ordersToProcess = array()){
|
| 148 |
+
|
| 149 |
+
$orderList = array();
|
| 150 |
+
foreach ($this->getCollection() as $order) {
|
| 151 |
+
|
| 152 |
+
if(in_array($order->getData('entity_id'),$ordersToProcess)) {
|
| 153 |
+
|
| 154 |
+
$orderData['Id'] = $order->getData('entity_id');
|
| 155 |
+
$orderData['SequenceNumber'] = $order->getData('entity_id');
|
| 156 |
+
$orderData['SequenceGuid'] = null;
|
| 157 |
+
$orderData['OrginalSeqNumber'] = 0;
|
| 158 |
+
$orderData['AccountingAppId'] = 3;
|
| 159 |
+
$orderData['ShippedDate'] = $this->_getOrderShipmentCreatedDate($order);
|
| 160 |
+
$orderData['Date'] = $this->_formatDateStarShip($order->getData('created_at'));
|
| 161 |
+
$orderData['To'] = $this->_getOrderTo($order);
|
| 162 |
+
$orderData['OurRef'] = (string) $order->getData('increment_id');
|
| 163 |
+
$orderData['TheirRef'] = (string) $order->getData('entity_id');
|
| 164 |
+
$orderData['ConsigneeCode'] = '';
|
| 165 |
+
$orderData['Email'] = (string) $order->getData('customer_email');
|
| 166 |
+
$orderData['Telephone'] = (string) $this->_getFormattedTelephone($order);
|
| 167 |
+
$orderData['AddressString'] = (string) $this->_getOrderShippingAddress($order,true);
|
| 168 |
+
$orderData['ItemsString'] = (string) $this->_getOrderItemsStr($order);
|
| 169 |
+
$orderData['TrackingNumber'] = '';
|
| 170 |
+
$orderData['CarrierCode'] = 0;
|
| 171 |
+
$orderData['ProductName'] = 'P';
|
| 172 |
+
$orderData['ErrorMessage'] = '';
|
| 173 |
+
$orderData['Status'] = 0;
|
| 174 |
+
$orderData['TrackingCode'] = '';
|
| 175 |
+
$orderData['Invoiced'] = '';
|
| 176 |
+
$orderData['OrderValue'] = (float) $order->getData('total_qty_ordered');
|
| 177 |
+
$orderData['OrderCurrency'] = (string) $order->getData('global_currency_code');
|
| 178 |
+
$orderData['AddressChecked'] = true;
|
| 179 |
+
$orderData['AddressValidated'] = true;
|
| 180 |
+
$orderData['ShipmentDescription'] = "ShipmentDescription";
|
| 181 |
+
$orderData['Items'] = $this->_getOrderItemsArr($order);
|
| 182 |
+
$orderData['AddressDetails'] = $this->_getOrderShippingAddress($order);
|
| 183 |
+
$orderData['BillingAddress'] = (string) $this->_getOrderBillingAddress($order);
|
| 184 |
+
$orderData['LastUpdatedatSource'] = (string) $this->_formatDateStarShip($order->getData('updated_at'));
|
| 185 |
+
$orderList[] = $orderData;
|
| 186 |
+
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
return $orderList;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
/**
|
| 195 |
+
* Get shipment created date
|
| 196 |
+
*
|
| 197 |
+
* @return string
|
| 198 |
+
*/
|
| 199 |
+
|
| 200 |
+
protected function _getOrderShipmentCreatedDate($order){
|
| 201 |
+
|
| 202 |
+
$date = '';
|
| 203 |
+
if(!$order->canShip()){
|
| 204 |
+
$shipData = $order->getShipmentsCollection()->getData();
|
| 205 |
+
$date = $this->_formatDateStarShip($shipData[0]['created_at']);
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
return $date;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
/**
|
| 212 |
+
* Get person name
|
| 213 |
+
*
|
| 214 |
+
* @return string
|
| 215 |
+
*/
|
| 216 |
+
|
| 217 |
+
protected function _getOrderTo($order){
|
| 218 |
+
|
| 219 |
+
$firstName = $order->getShippingAddress()->getData('firstname');
|
| 220 |
+
$lastName = $order->getShippingAddress()->getData('lastname');
|
| 221 |
+
$name = $firstName." ".$lastName;
|
| 222 |
+
return $name;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
/**
|
| 226 |
+
* Get country full name
|
| 227 |
+
*
|
| 228 |
+
* @return string
|
| 229 |
+
*/
|
| 230 |
+
|
| 231 |
+
protected function _getCountryNameByCode($country_code){
|
| 232 |
+
|
| 233 |
+
return Mage::app()->getLocale()->getCountryTranslation($country_code);
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
/**
|
| 237 |
+
* Get shippment address
|
| 238 |
+
*
|
| 239 |
+
* @return string/array
|
| 240 |
+
*/
|
| 241 |
+
|
| 242 |
+
protected function _getOrderShippingAddress($order, $string = false ) {
|
| 243 |
+
|
| 244 |
+
$addArr = array();
|
| 245 |
+
$AddressDTO = array();
|
| 246 |
+
if($string){
|
| 247 |
+
$streetAdd = $order->getShippingAddress()->getData('street');
|
| 248 |
+
$street = trim(preg_replace('/\s+/', ' ', $streetAdd));
|
| 249 |
+
$city = $order->getShippingAddress()->getData('city');
|
| 250 |
+
$postcode = $order->getShippingAddress()->getData('postcode');
|
| 251 |
+
$countryCode = $order->getShippingAddress()->getData('country_id');
|
| 252 |
+
$country = $this->_getCountryNameByCode($countryCode);
|
| 253 |
+
$addString = $street."k ".$city." ".$postcode." ".$country;
|
| 254 |
+
return $addString;
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
$addArr['City'] = $order->getShippingAddress()->getData('city');
|
| 258 |
+
$addArr['Company'] = $order->getShippingAddress()->getData('company');
|
| 259 |
+
$addArr['Country'] = $this->_getCountryNameByCode($order->getShippingAddress()->getData('country_id'));
|
| 260 |
+
$addArr['CountryId'] = $order->getShippingAddress()->getData('country_id');
|
| 261 |
+
$addArr['Instructions'] = '';
|
| 262 |
+
$addArr['PostCode'] = $order->getShippingAddress()->getData('postcode');
|
| 263 |
+
$addArr['Region'] = $order->getShippingAddress()->getData('region');
|
| 264 |
+
$addArr['State'] = '';
|
| 265 |
+
$addArr['Street'] = $order->getShippingAddress()->getData('street');
|
| 266 |
+
$addArr['Suburb'] = '';
|
| 267 |
+
$AddressDTO['AddressDTO'] = $addArr;
|
| 268 |
+
return $addArr;
|
| 269 |
+
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
/**
|
| 273 |
+
* Get billing addresss
|
| 274 |
+
*
|
| 275 |
+
* @return string
|
| 276 |
+
*/
|
| 277 |
+
|
| 278 |
+
protected function _getOrderBillingAddress($order) {
|
| 279 |
+
|
| 280 |
+
$streetAdd = $order->getBillingAddress()->getData('street');
|
| 281 |
+
$street = trim(preg_replace('/\s+/', ' ', $streetAdd));
|
| 282 |
+
$city = $order->getBillingAddress()->getData('city');
|
| 283 |
+
$postcode = $order->getBillingAddress()->getData('postcode');
|
| 284 |
+
$country = $order->getBillingAddress()->getData('country_id');
|
| 285 |
+
$add = $street." ".$city." ".$postcode." ".$country;
|
| 286 |
+
|
| 287 |
+
return $add;
|
| 288 |
+
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
/**
|
| 292 |
+
* Get Oredrs Items as string
|
| 293 |
+
*
|
| 294 |
+
* @return string
|
| 295 |
+
*/
|
| 296 |
+
protected function _getOrderItemsStr($order) {
|
| 297 |
+
|
| 298 |
+
$allItemsArr = $order->getAllVisibleItems();
|
| 299 |
+
$itemsStr = '';
|
| 300 |
+
$lastItemArr = end($allItemsArr);
|
| 301 |
+
$count = count($allItemsArr);
|
| 302 |
+
foreach ($allItemsArr as $item) {
|
| 303 |
+
$itemsStr .= $item->getName();
|
| 304 |
+
if( $count > 1 && $item->getId() != $lastItemArr->getId())
|
| 305 |
+
$itemsStr .= ', ';
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
return $itemsStr;
|
| 309 |
+
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
/**
|
| 313 |
+
* Get Order's items
|
| 314 |
+
*
|
| 315 |
+
* @return array
|
| 316 |
+
*/
|
| 317 |
+
|
| 318 |
+
protected function _getOrderItemsArr($order, $string = false) {
|
| 319 |
+
|
| 320 |
+
$ItemsArr = array();
|
| 321 |
+
$shipmentitems = array();
|
| 322 |
+
foreach ($order->getAllVisibleItems() as $item) {
|
| 323 |
+
$ItemsArr['Description'] = (string)$item->getName();
|
| 324 |
+
$ItemsArr['Country'] = (string)$order->getShippingAddress()->getData('country_id');;
|
| 325 |
+
$ItemsArr['Price'] = (float)$item->getPrice();
|
| 326 |
+
$ItemsArr['Quantity'] = (int)round($item->getQtyOrdered());
|
| 327 |
+
$shipmentitems['ShipmentItem'][] = $ItemsArr;
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
return $shipmentitems;
|
| 331 |
+
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
/**
|
| 335 |
+
* Prepare final Orders Array with auth details to pass
|
| 336 |
+
* over the star ship
|
| 337 |
+
* @return array
|
| 338 |
+
*/
|
| 339 |
+
|
| 340 |
+
public function prepareOrderToPass($orders = array()) {
|
| 341 |
+
|
| 342 |
+
$this->_orderInStarShip = $orders;
|
| 343 |
+
$ordersToProcess = $this->_checkOrderToProcess($orders);
|
| 344 |
+
$arrOrdersToPass['UserName'] = $this->_getUserName();
|
| 345 |
+
$arrOrdersToPass['Password'] = $this->_getAPIKey();
|
| 346 |
+
$arrOrdersToPass['Orders'] = $this->_orderShippedArr($ordersToProcess);
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
return $arrOrdersToPass;
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
public function needToUpdateOredrsInMage(){
|
| 355 |
+
|
| 356 |
+
return $this->_getUpdateOrderConfig();
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
/**
|
| 362 |
+
* Create shippment and set the tracking info to ot
|
| 363 |
+
*
|
| 364 |
+
* @return
|
| 365 |
+
*/
|
| 366 |
+
|
| 367 |
+
protected function _setAndSaveTrackingInfo($orderId,$orderCarrier,$orderTrackingNumber){
|
| 368 |
+
|
| 369 |
+
foreach ($this->getCollection() as $order) {
|
| 370 |
+
if($order->getData('entity_id') == $orderId && $order->canShip()){
|
| 371 |
+
|
| 372 |
+
try {
|
| 373 |
+
|
| 374 |
+
$shipment = $order->prepareShipment();
|
| 375 |
+
$shipment->register();
|
| 376 |
+
$order->setIsInProcess(true);
|
| 377 |
+
$order->addStatusHistoryComment('Automatically SHIPPED by Starship.', false);
|
| 378 |
+
$transactionSave = Mage::getModel('core/resource_transaction')
|
| 379 |
+
->addObject($shipment)
|
| 380 |
+
->addObject($shipment->getOrder())
|
| 381 |
+
->save();
|
| 382 |
+
|
| 383 |
+
if($shipment->getId() != '') {
|
| 384 |
+
try{
|
| 385 |
+
$track = Mage::getModel('sales/order_shipment_track')
|
| 386 |
+
->setShipment($shipment)
|
| 387 |
+
->setData('number', $orderTrackingNumber)
|
| 388 |
+
->setData('carrier_code', strtolower($orderCarrier))
|
| 389 |
+
->setData('order_id', $shipment->getData('order_id'))
|
| 390 |
+
->save();
|
| 391 |
+
return true;
|
| 392 |
+
}catch(Exception $e){
|
| 393 |
+
|
| 394 |
+
Mage::getSingleton('core/session')
|
| 395 |
+
->addError($this->__('Shipment added But Error while adding Tracking details Error is: ').$e->getMessage());
|
| 396 |
+
}
|
| 397 |
+
}
|
| 398 |
+
}catch(Exception $e){
|
| 399 |
+
$order->addStatusHistoryComment('Starship_Invoicer: Exception occurred during action. Exception message: '.$e->getMessage(), false);
|
| 400 |
+
$order->save();
|
| 401 |
+
Mage::getSingleton('core/session')->addError($this->__('Exception Occured: ').$e->getMessage());
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
}
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
public function addTrackingInfo($trackingInfo) {
|
| 410 |
+
|
| 411 |
+
$WritebackStruct = $trackingInfo->GetMagentoWritebacksResult->WritebackStruct;
|
| 412 |
+
|
| 413 |
+
if(is_array($WritebackStruct)){
|
| 414 |
+
|
| 415 |
+
foreach ($WritebackStruct as $orderTrackInfo) {
|
| 416 |
+
$orderId = $orderTrackInfo->Sequence;
|
| 417 |
+
$orderCarrier = $orderTrackInfo->Carrier;
|
| 418 |
+
$orderTrackingNumber = $orderTrackInfo->TrackingNumber;
|
| 419 |
+
$this->_setAndSaveTrackingInfo($orderId,$orderCarrier,$orderTrackingNumber);
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
return true;
|
| 423 |
+
|
| 424 |
+
}else{
|
| 425 |
+
$orderId = $WritebackStruct->Sequence;
|
| 426 |
+
$orderCarrier = $WritebackStruct->Carrier;
|
| 427 |
+
$orderTrackingNumber = $WritebackStruct->TrackingNumber;
|
| 428 |
+
$this->_setAndSaveTrackingInfo($orderId,$orderCarrier,$orderTrackingNumber);
|
| 429 |
+
|
| 430 |
+
return true;
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
return false;
|
| 434 |
+
|
| 435 |
+
|
| 436 |
+
}
|
| 437 |
+
}
|
app/code/community/Rvtech/Starshipit/controllers/Adminhtml/StarshipitController.php
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Rvtech_Starshipit_Adminhtml_StarshipitController extends Mage_Adminhtml_Controller_Action
|
| 3 |
+
{
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* Return some checking result
|
| 8 |
+
*
|
| 9 |
+
* @return void
|
| 10 |
+
*/
|
| 11 |
+
public function testAction()
|
| 12 |
+
{
|
| 13 |
+
$params = array();
|
| 14 |
+
$params = $this->getRequest()->getParams();
|
| 15 |
+
// $this->getResponse()->setBody(print_r($params));
|
| 16 |
+
//break;
|
| 17 |
+
$autoTo = array(
|
| 18 |
+
'userName' => $params['groups']['group1']['fields']['username']['value'],
|
| 19 |
+
'apiKey' => $params['groups']['group1']['fields']['api_key']['value']
|
| 20 |
+
);
|
| 21 |
+
// $this->getResponse()->setBody(print_r($autoTo));
|
| 22 |
+
|
| 23 |
+
$helper = Mage::helper('starshipit/starship');
|
| 24 |
+
$resStarShip = $helper->validateUser($autoTo);
|
| 25 |
+
if($resStarShip === 'Success'){
|
| 26 |
+
Mage::getSingleton('core/session')->addSuccess('Valid UserName And APIKey');
|
| 27 |
+
}
|
| 28 |
+
else{
|
| 29 |
+
Mage::getSingleton('core/session')->addError($resStarShip);
|
| 30 |
+
//$this->getResponse()->setBody(print_r($resStarShip));
|
| 31 |
+
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
Mage::app()->getResponse()->setBody(
|
| 35 |
+
$this->getLayout()->getMessagesBlock()->getGroupedHtml()
|
| 36 |
+
);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* will sync orders
|
| 41 |
+
*
|
| 42 |
+
* @return void
|
| 43 |
+
*/
|
| 44 |
+
|
| 45 |
+
public function syncOrderAction(){
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
$params = array();
|
| 49 |
+
$params = $this->getRequest()->getParams();
|
| 50 |
+
//$this->getResponse()->setBody($params);
|
| 51 |
+
|
| 52 |
+
// $user = $params['user'];
|
| 53 |
+
// $apikey = $params['apikey'];
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
$helper = Mage::helper('starshipit/starship');
|
| 58 |
+
$postData = $helper->arrangePostData($params);
|
| 59 |
+
//$this->getResponse()->setBody(print_r($postData));
|
| 60 |
+
$orderObj = Mage::getModel('starshipit/orders');
|
| 61 |
+
|
| 62 |
+
//get the configuration array (username, apikey etc.)
|
| 63 |
+
$para = $orderObj->getDataForExistingOredrs($postData);
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
//get existing orders from Starship
|
| 67 |
+
$existingOrderRes = $helper->getExistingOrders($para);
|
| 68 |
+
|
| 69 |
+
if(empty($existingOrderRes->GetExistingResult->ErrorMessage)){
|
| 70 |
+
$resOrders = $existingOrderRes
|
| 71 |
+
->GetExistingResult
|
| 72 |
+
->Orders;
|
| 73 |
+
$odersArr = array();
|
| 74 |
+
try{
|
| 75 |
+
if(isset($resOrders->ExistingOrder)){
|
| 76 |
+
$resExistingOrder = $resOrders->ExistingOrder;
|
| 77 |
+
$odersArr = $helper->finalOrderArrOverStarShip($resExistingOrder);
|
| 78 |
+
}
|
| 79 |
+
}catch(Exception $e){
|
| 80 |
+
|
| 81 |
+
Mage::getSingleton('core/session')->addError($e->getMessage());
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
//get Orders array to sync with StarShip
|
| 86 |
+
$ordersToPass = $orderObj->prepareOrderToPass($odersArr);
|
| 87 |
+
|
| 88 |
+
if(empty($ordersToPass['Orders'])) {
|
| 89 |
+
Mage::getSingleton('core/session')->addNotice('No order found for sync to Starship');
|
| 90 |
+
}else{
|
| 91 |
+
Mage::getSingleton('core/session')->addSuccess('Orders sync to Starship ');
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
//Sync orders and store resonpse
|
| 95 |
+
$resShipSync = $helper->addShipment($ordersToPass);
|
| 96 |
+
|
| 97 |
+
//Change Order State and add Track Info
|
| 98 |
+
if($helper->checkCondForMagentoWritebacks($resShipSync)) {
|
| 99 |
+
$resWriteBack = $helper->getMagentoWritebacks();
|
| 100 |
+
//$this->getResponse()->setBody(print_r($resWriteBack));
|
| 101 |
+
if(isset($resWriteBack->GetMagentoWritebacksResult->WritebackStruct)){
|
| 102 |
+
$isTackadded = $orderObj->addTrackingInfo($resWriteBack);
|
| 103 |
+
if($isTackadded) {
|
| 104 |
+
Mage::getSingleton('core/session')->addSuccess('Tracking Info SAVED');
|
| 105 |
+
}
|
| 106 |
+
}else{
|
| 107 |
+
Mage::getSingleton('core/session')->addNotice('No tracking info found on Starship');
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
}else{
|
| 112 |
+
|
| 113 |
+
Mage::getSingleton('core/session')->addError(
|
| 114 |
+
$existingOrderRes->GetExistingResult->ErrorMessage
|
| 115 |
+
);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
Mage::app()->getResponse()->setBody(
|
| 119 |
+
$this->getLayout()->getMessagesBlock()->getGroupedHtml()
|
| 120 |
+
);
|
| 121 |
+
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
}
|
app/code/community/Rvtech/Starshipit/controllers/Adminhtml/StarshipitController.php_ORG
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Rvtech_Starshipit_Adminhtml_StarshipitController extends Mage_Adminhtml_Controller_Action
|
| 3 |
+
{
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* Return some checking result
|
| 8 |
+
*
|
| 9 |
+
* @return void
|
| 10 |
+
*/
|
| 11 |
+
public function testAction()
|
| 12 |
+
{
|
| 13 |
+
|
| 14 |
+
$helper = Mage::helper('starshipit/starship');
|
| 15 |
+
$resStarShip = $helper->validateUser();
|
| 16 |
+
if($resStarShip === 'Success'){
|
| 17 |
+
Mage::getSingleton('core/session')->addSuccess('Valid UserName And APIKey');
|
| 18 |
+
}
|
| 19 |
+
else{
|
| 20 |
+
Mage::getSingleton('core/session')->addError($resStarShip);
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
Mage::app()->getResponse()->setBody(
|
| 24 |
+
$this->getLayout()->getMessagesBlock()->getGroupedHtml()
|
| 25 |
+
);
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* will sync orders
|
| 30 |
+
*
|
| 31 |
+
* @return void
|
| 32 |
+
*/
|
| 33 |
+
|
| 34 |
+
public function syncOrderAction(){
|
| 35 |
+
|
| 36 |
+
$helper = Mage::helper('starshipit/starship');
|
| 37 |
+
|
| 38 |
+
$orderObj = Mage::getModel('starshipit/orders');
|
| 39 |
+
|
| 40 |
+
//get the configuration array (username, apikey etc.)
|
| 41 |
+
$para = $orderObj->getDataForExistingOredrs();
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
//get existing orders from Starship
|
| 45 |
+
$existingOrderRes = $helper->getExistingOrders($para);
|
| 46 |
+
|
| 47 |
+
if(empty($existingOrderRes->GetExistingResult->ErrorMessage)){
|
| 48 |
+
$resOrders = $existingOrderRes
|
| 49 |
+
->GetExistingResult
|
| 50 |
+
->Orders;
|
| 51 |
+
$odersArr = array();
|
| 52 |
+
try{
|
| 53 |
+
if(isset($resOrders->ExistingOrder)){
|
| 54 |
+
$resExistingOrder = $resOrders->ExistingOrder;
|
| 55 |
+
$odersArr = $helper->finalOrderArrOverStarShip($resExistingOrder);
|
| 56 |
+
}
|
| 57 |
+
}catch(Exception $e){
|
| 58 |
+
|
| 59 |
+
Mage::getSingleton('core/session')->addError($e->getMessage());
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
//get Orders array to sync with StarShip
|
| 64 |
+
$ordersToPass = $orderObj->prepareOrderToPass($odersArr);
|
| 65 |
+
|
| 66 |
+
if(empty($ordersToPass['Orders'])) {
|
| 67 |
+
Mage::getSingleton('core/session')->addNotice('No order found for sync to Starship');
|
| 68 |
+
}else{
|
| 69 |
+
Mage::getSingleton('core/session')->addSuccess('Orders sync to Starship ');
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
//Sync orders and store resonpse
|
| 73 |
+
$resShipSync = $helper->addShipment($ordersToPass);
|
| 74 |
+
|
| 75 |
+
//Change Order State and add Track Info
|
| 76 |
+
if($helper->checkCondForMagentoWritebacks($resShipSync)) {
|
| 77 |
+
$resWriteBack = $helper->getMagentoWritebacks();
|
| 78 |
+
if(isset($resWriteBack->GetMagentoWritebacksResult->WritebackStruct)){
|
| 79 |
+
$isTackadded = $orderObj->addTrackingInfo($resWriteBack);
|
| 80 |
+
if($isTackadded) {
|
| 81 |
+
Mage::getSingleton('core/session')->addSuccess('Tracking Info SAVED');
|
| 82 |
+
}
|
| 83 |
+
}else{
|
| 84 |
+
Mage::getSingleton('core/session')->addNotice('No tracking info found on Starship');
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
}else{
|
| 89 |
+
|
| 90 |
+
Mage::getSingleton('core/session')->addError(
|
| 91 |
+
$existingOrderRes->GetExistingResult->ErrorMessage
|
| 92 |
+
);
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
Mage::app()->getResponse()->setBody(
|
| 96 |
+
$this->getLayout()->getMessagesBlock()->getGroupedHtml()
|
| 97 |
+
);
|
| 98 |
+
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
}
|
app/code/community/Rvtech/Starshipit/controllers/IndexController.php
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Rvtech_Starshipit_IndexController extends Mage_Adminhtml_Controller_Action
|
| 3 |
+
{
|
| 4 |
+
public function indexAction() {
|
| 5 |
+
echo "hey there";
|
| 6 |
+
}
|
| 7 |
+
}
|
app/code/community/Rvtech/Starshipit/etc/adminhtml.xml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<menu>
|
| 4 |
+
<starshipit translate="title" module="starshipit">
|
| 5 |
+
<title>Starshipit</title>
|
| 6 |
+
<sort_order>9999</sort_order>
|
| 7 |
+
<children>
|
| 8 |
+
<configuration translate="title" module="starshipit">
|
| 9 |
+
<title>Configuration</title>
|
| 10 |
+
<sort_order>1</sort_order>
|
| 11 |
+
<action>adminhtml/system_config/edit/section/starshipit_options</action>
|
| 12 |
+
</configuration>
|
| 13 |
+
<notification translate="title" module="starshipit">
|
| 14 |
+
<title>Automatic Sync Notifications</title>
|
| 15 |
+
<sort_order>2</sort_order>
|
| 16 |
+
<action>adminhtml/notification</action>
|
| 17 |
+
</notification>
|
| 18 |
+
</children>
|
| 19 |
+
</starshipit>
|
| 20 |
+
</menu>
|
| 21 |
+
</config>
|
app/code/community/Rvtech/Starshipit/etc/config.xml
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<config>
|
| 2 |
+
<modules>
|
| 3 |
+
<Rvtech_Starshipit>
|
| 4 |
+
<version>1.0.0.0</version>
|
| 5 |
+
</Rvtech_Starshipit>
|
| 6 |
+
</modules>
|
| 7 |
+
<admin>
|
| 8 |
+
<routers>
|
| 9 |
+
<adminhtml>
|
| 10 |
+
<args>
|
| 11 |
+
<modules>
|
| 12 |
+
<starshipit after="Mage_Adminhtml">Rvtech_Starshipit</starshipit>
|
| 13 |
+
</modules>
|
| 14 |
+
</args>
|
| 15 |
+
</adminhtml>
|
| 16 |
+
</routers>
|
| 17 |
+
</admin>
|
| 18 |
+
<adminhtml>
|
| 19 |
+
<acl>
|
| 20 |
+
<resources>
|
| 21 |
+
<admin>
|
| 22 |
+
<children>
|
| 23 |
+
<system>
|
| 24 |
+
<children>
|
| 25 |
+
<config>
|
| 26 |
+
<children>
|
| 27 |
+
<starshipit_options>
|
| 28 |
+
<title>Starshipit Module Section</title>
|
| 29 |
+
</starshipit_options>
|
| 30 |
+
</children>
|
| 31 |
+
</config>
|
| 32 |
+
</children>
|
| 33 |
+
</system>
|
| 34 |
+
</children>
|
| 35 |
+
</admin>
|
| 36 |
+
</resources>
|
| 37 |
+
</acl>
|
| 38 |
+
</adminhtml>
|
| 39 |
+
<global>
|
| 40 |
+
<blocks>
|
| 41 |
+
<starshipit>
|
| 42 |
+
<class>Rvtech_Starshipit_Block</class>
|
| 43 |
+
</starshipit>
|
| 44 |
+
</blocks>
|
| 45 |
+
<models>
|
| 46 |
+
<starshipit>
|
| 47 |
+
<class>Rvtech_Starshipit_Model</class>
|
| 48 |
+
</starshipit>
|
| 49 |
+
</models>
|
| 50 |
+
<helpers>
|
| 51 |
+
<starshipit>
|
| 52 |
+
<class>Rvtech_Starshipit_Helper</class>
|
| 53 |
+
</starshipit>
|
| 54 |
+
</helpers>
|
| 55 |
+
<events>
|
| 56 |
+
<checkout_type_onepage_save_order_after>
|
| 57 |
+
<observers>
|
| 58 |
+
<rvtech_starshipit_order_placed_sync_now>
|
| 59 |
+
<type>singleton</type>
|
| 60 |
+
<class>Rvtech_Starshipit_Model_Observer</class>
|
| 61 |
+
<method>syncOrdersNow</method>
|
| 62 |
+
</rvtech_starshipit_order_placed_sync_now>
|
| 63 |
+
</observers>
|
| 64 |
+
</checkout_type_onepage_save_order_after>
|
| 65 |
+
</events>
|
| 66 |
+
</global>
|
| 67 |
+
<default>
|
| 68 |
+
<starshipit_options>
|
| 69 |
+
<group1>
|
| 70 |
+
<sync_orders>5</sync_orders>
|
| 71 |
+
</group1>
|
| 72 |
+
</starshipit_options>
|
| 73 |
+
</default>
|
| 74 |
+
</config>
|
app/code/community/Rvtech/Starshipit/etc/system.xml
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<config>
|
| 2 |
+
<tabs>
|
| 3 |
+
<starshipitconfig translate="label" module="starshipit">
|
| 4 |
+
<label>Starshipit Configuration</label>
|
| 5 |
+
<sort_order>200</sort_order>
|
| 6 |
+
</starshipitconfig>
|
| 7 |
+
</tabs>
|
| 8 |
+
<sections>
|
| 9 |
+
<starshipit_options translate="label" module="starshipit">
|
| 10 |
+
<label>Starshipit Config Options</label>
|
| 11 |
+
<tab>starshipitconfig</tab>
|
| 12 |
+
<frontend_type>text</frontend_type>
|
| 13 |
+
<sort_order>100</sort_order>
|
| 14 |
+
<show_in_default>1</show_in_default>
|
| 15 |
+
<show_in_website>1</show_in_website>
|
| 16 |
+
<show_in_store>1</show_in_store>
|
| 17 |
+
<groups>
|
| 18 |
+
<group1 translate="label">
|
| 19 |
+
<label>Configuration</label>
|
| 20 |
+
<frontend_type>text</frontend_type>
|
| 21 |
+
<sort_order>1</sort_order>
|
| 22 |
+
<show_in_default>1</show_in_default>
|
| 23 |
+
<show_in_website>1</show_in_website>
|
| 24 |
+
<show_in_store>1</show_in_store>
|
| 25 |
+
<fields>
|
| 26 |
+
<username>
|
| 27 |
+
<label>Username</label>
|
| 28 |
+
<frontend_type>text</frontend_type>
|
| 29 |
+
<comment><![CDATA[<i>UserName for the Starship</i>]]></comment>
|
| 30 |
+
<sort_order>0</sort_order>
|
| 31 |
+
<show_in_default>1</show_in_default>
|
| 32 |
+
<show_in_website>1</show_in_website>
|
| 33 |
+
<show_in_store>1</show_in_store>
|
| 34 |
+
</username>
|
| 35 |
+
<api_key>
|
| 36 |
+
<label>API Key</label>
|
| 37 |
+
<frontend_type>password</frontend_type>
|
| 38 |
+
<comment><![CDATA[<i>APIKey for the Starship</i>]]></comment>
|
| 39 |
+
<sort_order>1</sort_order>
|
| 40 |
+
<show_in_default>1</show_in_default>
|
| 41 |
+
<show_in_website>1</show_in_website>
|
| 42 |
+
<show_in_store>1</show_in_store>
|
| 43 |
+
</api_key>
|
| 44 |
+
<test>
|
| 45 |
+
<frontend_type>button</frontend_type>
|
| 46 |
+
<frontend_model>starshipit/adminhtml_system_config_form_button</frontend_model>
|
| 47 |
+
<comment><![CDATA[<i>Click here to test that above UserName and APIKey are valid or not</i>]]></comment>
|
| 48 |
+
<sort_order>3</sort_order>
|
| 49 |
+
<show_in_default>1</show_in_default>
|
| 50 |
+
<show_in_website>1</show_in_website>
|
| 51 |
+
<show_in_store>1</show_in_store>
|
| 52 |
+
</test>
|
| 53 |
+
<syncbutton>
|
| 54 |
+
<frontend_type>button</frontend_type>
|
| 55 |
+
<frontend_model>starshipit/adminhtml_system_config_form_syncbutton</frontend_model>
|
| 56 |
+
<sort_order>6</sort_order>
|
| 57 |
+
<show_in_default>1</show_in_default>
|
| 58 |
+
<show_in_website>1</show_in_website>
|
| 59 |
+
<show_in_store>1</show_in_store>
|
| 60 |
+
</syncbutton>
|
| 61 |
+
<update_orders>
|
| 62 |
+
<label>Update orders to complete once shipped</label>
|
| 63 |
+
<frontend_type>select</frontend_type>
|
| 64 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 65 |
+
<sort_order>4</sort_order>
|
| 66 |
+
<tooltip><![CDATA[<i>If set to YES, it will automatically create shipment and and update track info received from StartShip</i>]]></tooltip>
|
| 67 |
+
<show_in_default>1</show_in_default>
|
| 68 |
+
<show_in_website>1</show_in_website>
|
| 69 |
+
<show_in_store>1</show_in_store>
|
| 70 |
+
</update_orders>
|
| 71 |
+
<sync_orders_yesno>
|
| 72 |
+
<label>Sync orders automatically</label>
|
| 73 |
+
<frontend_type>select</frontend_type>
|
| 74 |
+
<tooltip><![CDATA[<i>If set to YES, it will automatically sync order after every 'x' minute (mentioned below)</i>]]></tooltip>
|
| 75 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 76 |
+
<sort_order>5</sort_order>
|
| 77 |
+
<show_in_default>1</show_in_default>
|
| 78 |
+
<show_in_website>1</show_in_website>
|
| 79 |
+
<show_in_store>1</show_in_store>
|
| 80 |
+
</sync_orders_yesno>
|
| 81 |
+
<sync_orders>
|
| 82 |
+
<label>Time period to sync orders</label>
|
| 83 |
+
<frontend_type>text</frontend_type>
|
| 84 |
+
<comment><![CDATA[<i><b>Note:</b>Time Period is in Minutes</i>]]></comment>
|
| 85 |
+
<default>5</default>
|
| 86 |
+
<sort_order>6</sort_order>
|
| 87 |
+
<show_in_default>1</show_in_default>
|
| 88 |
+
<show_in_website>1</show_in_website>
|
| 89 |
+
<show_in_store>1</show_in_store>
|
| 90 |
+
</sync_orders>
|
| 91 |
+
</fields>
|
| 92 |
+
</group1>
|
| 93 |
+
</groups>
|
| 94 |
+
</starshipit_options>
|
| 95 |
+
</sections>
|
| 96 |
+
</config>
|
app/code/community/Rvtech/Starshipquote/Block/Dhlform.php
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
*
|
| 4 |
+
*/
|
| 5 |
+
class Rvtech_Starshipquote_Block_Dhlform extends Mage_Core_Block_Template
|
| 6 |
+
{
|
| 7 |
+
|
| 8 |
+
public function getFormSubmitUrl() {
|
| 9 |
+
|
| 10 |
+
return Mage::getUrl('starshipquote/dhlquote/quote');
|
| 11 |
+
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
?>
|
app/code/community/Rvtech/Starshipquote/Helper/Data.php
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
*
|
| 4 |
+
*/
|
| 5 |
+
class Rvtech_Starshipquote_Helper_Data extends Mage_Core_Helper_Abstract
|
| 6 |
+
{
|
| 7 |
+
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
?>
|
app/code/community/Rvtech/Starshipquote/Helper/Dhl.php
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Rvtech_Starshipquote_Helper_Dhl extends Mage_Core_Helper_Abstract
|
| 3 |
+
{
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
public $_wsdl = 'http://dhl.starshipit.com/OrdersService.svc?singleWsdl';
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
*
|
| 10 |
+
* @return php soap client object
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
protected function _soapClient() {
|
| 14 |
+
|
| 15 |
+
$wsdl = $this->_wsdl;
|
| 16 |
+
return new SoapClient($wsdl, array('trace' => 1));
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
protected function _getQuote($info = array()){
|
| 20 |
+
$soap = $this->_soapClient();
|
| 21 |
+
$result = $soap->__call('GetDHLQuote',array(
|
| 22 |
+
'GetDHLQuote' => array(
|
| 23 |
+
|
| 24 |
+
'accountId' => 403,
|
| 25 |
+
'info' => $info
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
));
|
| 29 |
+
|
| 30 |
+
return $result;
|
| 31 |
+
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
public function getQuoteFromDhl($params = array()) {
|
| 35 |
+
|
| 36 |
+
return $this->_getQuote($params);
|
| 37 |
+
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
}
|
app/code/community/Rvtech/Starshipquote/controllers/DhlquoteController.php
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
*
|
| 4 |
+
*/
|
| 5 |
+
class Rvtech_Starshipquote_DhlquoteController extends Mage_Core_Controller_Front_Action
|
| 6 |
+
{
|
| 7 |
+
|
| 8 |
+
public function quoteAction(){
|
| 9 |
+
|
| 10 |
+
$params = $this->getRequest()->getParams();
|
| 11 |
+
$result = Mage::helper('starshipquote/dhl')->getQuoteFromDhl($params);
|
| 12 |
+
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
|
| 13 |
+
return;
|
| 14 |
+
}
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
?>
|
app/code/community/Rvtech/Starshipquote/etc/adminhtml.xml
ADDED
|
File without changes
|
app/code/community/Rvtech/Starshipquote/etc/config.xml
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Rvtech_Starshipquote>
|
| 5 |
+
<version>1.0.0.0</version>
|
| 6 |
+
</Rvtech_Starshipquote>
|
| 7 |
+
</modules>
|
| 8 |
+
<global>
|
| 9 |
+
<helpers>
|
| 10 |
+
<starshipquote>
|
| 11 |
+
<class>Rvtech_Starshipquote_Helper</class>
|
| 12 |
+
</starshipquote>
|
| 13 |
+
</helpers>
|
| 14 |
+
<blocks>
|
| 15 |
+
<starshipquote>
|
| 16 |
+
<class>Rvtech_Starshipquote_Block</class>
|
| 17 |
+
</starshipquote>
|
| 18 |
+
</blocks>
|
| 19 |
+
</global>
|
| 20 |
+
<frontend>
|
| 21 |
+
<routers>
|
| 22 |
+
<starshipquote>
|
| 23 |
+
<use>standard</use>
|
| 24 |
+
<args>
|
| 25 |
+
<module>Rvtech_Starshipquote</module>
|
| 26 |
+
<frontName>starshipquote</frontName>
|
| 27 |
+
</args>
|
| 28 |
+
</starshipquote>
|
| 29 |
+
</routers>
|
| 30 |
+
<layout>
|
| 31 |
+
<updates>
|
| 32 |
+
<starshipquote>
|
| 33 |
+
<file>starshipquote.xml</file>
|
| 34 |
+
</starshipquote>
|
| 35 |
+
</updates>
|
| 36 |
+
</layout>
|
| 37 |
+
</frontend>
|
| 38 |
+
<adminhtml>
|
| 39 |
+
<acl>
|
| 40 |
+
<resources>
|
| 41 |
+
<admin>
|
| 42 |
+
<children>
|
| 43 |
+
<system>
|
| 44 |
+
<children>
|
| 45 |
+
<config>
|
| 46 |
+
<children>
|
| 47 |
+
<dhl_settings>
|
| 48 |
+
<title>DHL Quote</title>
|
| 49 |
+
</dhl_settings>
|
| 50 |
+
</children>
|
| 51 |
+
</config>
|
| 52 |
+
</children>
|
| 53 |
+
</system>
|
| 54 |
+
</children>
|
| 55 |
+
</admin>
|
| 56 |
+
</resources>
|
| 57 |
+
</acl>
|
| 58 |
+
</adminhtml>
|
| 59 |
+
</config>
|
app/code/community/Rvtech/Starshipquote/etc/system.xml
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<config>
|
| 3 |
+
<tabs>
|
| 4 |
+
<dhl translate="label" module="starshipquote">
|
| 5 |
+
<label>DHL Quote</label>
|
| 6 |
+
<sort_order>25</sort_order>
|
| 7 |
+
</dhl>
|
| 8 |
+
</tabs>
|
| 9 |
+
<sections>
|
| 10 |
+
<dhl_settings translate="label" module="starshipquote">
|
| 11 |
+
<label>Account Settings</label>
|
| 12 |
+
<tab>dhl</tab>
|
| 13 |
+
<class>seprator-top</class>
|
| 14 |
+
<sort_order>200</sort_order>
|
| 15 |
+
<show_in_default>1</show_in_default>
|
| 16 |
+
<show_in_store>1</show_in_store>
|
| 17 |
+
<show_in_website>1</show_in_website>
|
| 18 |
+
<groups>
|
| 19 |
+
<dhl_account translate="label">
|
| 20 |
+
<label>Account Configuration</label>
|
| 21 |
+
<expanded>1</expanded>
|
| 22 |
+
<sort_order>1</sort_order>
|
| 23 |
+
<show_in_default>1</show_in_default>
|
| 24 |
+
<show_in_store>1</show_in_store>
|
| 25 |
+
<show_in_website>1</show_in_website>
|
| 26 |
+
<fields>
|
| 27 |
+
<user_name translate="label">
|
| 28 |
+
<label>Enabled</label>
|
| 29 |
+
<validate>required-entry</validate>
|
| 30 |
+
<frontend_type>select</frontend_type>
|
| 31 |
+
<source_model>adminhtml/system_config_source_yesno</source_model>
|
| 32 |
+
<sort_order>1</sort_order>
|
| 33 |
+
<show_in_store>1</show_in_store>
|
| 34 |
+
<show_in_website>1</show_in_website>
|
| 35 |
+
<show_in_default>1</show_in_default>
|
| 36 |
+
</user_name>
|
| 37 |
+
<user_key translate="label">
|
| 38 |
+
<label>Account ID</label>
|
| 39 |
+
<frontend_type>text</frontend_type>
|
| 40 |
+
<comment><![CDATA[<i>if empty default(403) will be used </i>]]></comment>
|
| 41 |
+
<sort_order>3</sort_order>
|
| 42 |
+
<show_in_store>1</show_in_store>
|
| 43 |
+
<show_in_website>1</show_in_website>
|
| 44 |
+
<show_in_default>1</show_in_default>
|
| 45 |
+
<depends>
|
| 46 |
+
<user_name>1</user_name>
|
| 47 |
+
</depends>
|
| 48 |
+
</user_key>
|
| 49 |
+
</fields>
|
| 50 |
+
</dhl_account>
|
| 51 |
+
</groups>
|
| 52 |
+
</dhl_settings>
|
| 53 |
+
</sections>
|
| 54 |
+
</config>
|
app/design/adminhtml/default/default/template/starshipit/system/config/button.phtml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script type="text/javascript">
|
| 2 |
+
//<![CDATA[
|
| 3 |
+
function test() {
|
| 4 |
+
var formData = $('config_edit_form').serialize();
|
| 5 |
+
new Ajax.Request('<?php echo $this->getAjaxCheckUrl() ?>', {
|
| 6 |
+
method: 'post',
|
| 7 |
+
postBody: formData,
|
| 8 |
+
onSuccess: function(transport){
|
| 9 |
+
|
| 10 |
+
if (transport.responseText){
|
| 11 |
+
//alert(transport.responseText);
|
| 12 |
+
if($('messages')){
|
| 13 |
+
$('messages').innerHTML = transport.responseText;
|
| 14 |
+
//alert(transport.responseText);
|
| 15 |
+
}
|
| 16 |
+
}
|
| 17 |
+
}
|
| 18 |
+
});
|
| 19 |
+
}
|
| 20 |
+
//]]>
|
| 21 |
+
</script>
|
| 22 |
+
|
| 23 |
+
<?php echo $this->getButtonHtml() ?>
|
app/design/adminhtml/default/default/template/starshipit/system/config/syncbutton.phtml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script type="text/javascript">
|
| 2 |
+
//<![CDATA[
|
| 3 |
+
function syncOrder() {
|
| 4 |
+
var formData = $('config_edit_form').serialize();
|
| 5 |
+
new Ajax.Request('<?php echo $this->getAjaxCheckUrl() ?>', {
|
| 6 |
+
method: 'post',
|
| 7 |
+
postBody: formData,
|
| 8 |
+
onSuccess: function(transport){
|
| 9 |
+
|
| 10 |
+
if (transport.responseText){
|
| 11 |
+
if($('messages')){
|
| 12 |
+
$('messages').innerHTML = transport.responseText;
|
| 13 |
+
//alert(transport.responseText);
|
| 14 |
+
}
|
| 15 |
+
}
|
| 16 |
+
}
|
| 17 |
+
});
|
| 18 |
+
}
|
| 19 |
+
//]]>
|
| 20 |
+
</script>
|
| 21 |
+
|
| 22 |
+
<?php echo $this->getButtonHtml() ?>
|
app/etc/modules/Rvtech_Startshipit.xml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
| 2 |
+
<config>
|
| 3 |
+
<modules>
|
| 4 |
+
<Rvtech_Starshipit>
|
| 5 |
+
<active>true</active>
|
| 6 |
+
<codePool>community</codePool>
|
| 7 |
+
</Rvtech_Starshipit>
|
| 8 |
+
</modules>
|
| 9 |
+
</config>
|
package.xml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<package>
|
| 3 |
+
<name>Rvtech_Starshipit</name>
|
| 4 |
+
<version>1.0.0.0</version>
|
| 5 |
+
<stability>stable</stability>
|
| 6 |
+
<license>Open Software License (OSL)</license>
|
| 7 |
+
<channel>community</channel>
|
| 8 |
+
<extends/>
|
| 9 |
+
<summary>Syncs Orders between Magento and StarShipIT DHL ClickToDoor to enable quotes, printing of shipping labels and track and trace.</summary>
|
| 10 |
+
<description>The StarShipIT Magento Extension enables orders to be imported into StarShipIT DHL ClickToDoor and writes back tracking information and updates order status in Magento.
|
| 11 |
+

|
| 12 |
+
From DHL ShipToDoor shipping labels can be produced, tracking of orders is supported, quotes can be obtained and all custom and DHL documentation can be produced.
|
| 13 |
+

|
| 14 |
+
DHL Express Worldwide is supported.</description>
|
| 15 |
+
<notes>First release which has been in production for several months on multiple sites.</notes>
|
| 16 |
+
<authors><author><name>George Plummer</name><user>GeorgeSPlummer</user><email>george@starshipit.com</email></author></authors>
|
| 17 |
+
<date>2013-09-06</date>
|
| 18 |
+
<time>01:40:00</time>
|
| 19 |
+
<contents><target name="magecommunity"><dir name="Rvtech"><dir name="Starshipit"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Form"><file name="Button.php" hash="2b3b0143262abe0d3ba50c38fe10d932"/><file name="Syncbutton.php" hash="b53f7f430495c1e9466789b116ce6349"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="0313223fc94e9ed45f4401119bd6f528"/><file name="Starship.php" hash="f4c538bcb80335b213602528b749ce3c"/><file name="Starship.php_ORG" hash="d92f50594c70158dd94453ef7f147de9"/></dir><dir name="Model"><file name="Observer.php" hash="68edec460ac627ff4aec5fece6d688b6"/><file name="Orders.php" hash="d5e6fa78702b1a0bd60e8cb4b3f57521"/><file name="Orders.php_ORG" hash="cbadeab0c67303b653bed3549a9b73de"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="StarshipitController.php" hash="926e0e618d5732fa7fffc0b1b5028259"/><file name="StarshipitController.php_ORG" hash="b7c694e8252892da817eae072f6f8ad6"/></dir><file name="IndexController.php" hash="3ac934011e0b4bffd25fbbe927bad092"/></dir><dir name="etc"><file name="adminhtml.xml" hash="d1b2db6c781f6fcacfe4ef75ad490cd0"/><file name="config.xml" hash="8c3ed77f01ca97b8db4cb55a8b7b27d8"/><file name="system.xml" hash="02f6bb9bd097efe52939c8c638cdb4af"/></dir></dir><dir name="Starshipquote"><dir name="Block"><file name="Dhlform.php" hash="2ace0bd01d2a9339aae870eca7accb51"/></dir><dir name="Helper"><file name="Data.php" hash="6634c0b478fffffd5b1f1545b504a205"/><file name="Dhl.php" hash="7e400792ff42275417246210d132508a"/></dir><dir name="controllers"><file name="DhlquoteController.php" hash="f4727027567fd6ea2750da05ab9b9091"/></dir><dir name="etc"><file name="adminhtml.xml" hash="d41d8cd98f00b204e9800998ecf8427e"/><file name="config.xml" hash="905ac050fe21f37bd0798abfc74d5c6a"/><file name="system.xml" hash="03fd335a3f24072d938ca74b68a80c6a"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="starshipit"><dir name="system"><dir name="config"><file name="button.phtml" hash="064f053f67fc7b749d1aec40cd352ce1"/><file name="syncbutton.phtml" hash="3e67731254d4d0298891cd2598471dc9"/></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Rvtech_Startshipit.xml" hash="741fde1331d6a9b27ef2faa2bd8a843f"/></dir></target></contents>
|
| 20 |
+
<compatible/>
|
| 21 |
+
<dependencies><required><php><min>5.1.0</min><max>5.5.2</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.6.0.0</min><max>1.7</max></package></required></dependencies>
|
| 22 |
+
</package>
|
