Shiptheory_Dpd - Version 0.0.1

Version Notes

First public release

Download this release

Release Info

Developer Shiptheory
Extension Shiptheory_Dpd
Version 0.0.1
Comparing to
See all releases


Version 0.0.1

Files changed (37) hide show
  1. app/code/local/Shiptheory/Dpd/Block/Adminhtml/System/Config/Fieldset/Hint.php +41 -0
  2. app/code/local/Shiptheory/Dpd/Helper/Data.php +8 -0
  3. app/code/local/Shiptheory/Dpd/etc/config.xml +65 -0
  4. app/code/local/Shiptheory/Dpd/etc/system.xml +24 -0
  5. app/code/local/Shiptheory/Shippinglabels/Block/Adminhtml/Shippinglabels.php +32 -0
  6. app/code/local/Shiptheory/Shippinglabels/Block/Adminhtml/Shippinglabels/Grid.php +126 -0
  7. app/code/local/Shiptheory/Shippinglabels/Block/Adminhtml/System/Config/Fieldset/Hint.php +25 -0
  8. app/code/local/Shiptheory/Shippinglabels/Block/Adminhtml/Version.php +16 -0
  9. app/code/local/Shiptheory/Shippinglabels/Block/Button/New.php +24 -0
  10. app/code/local/Shiptheory/Shippinglabels/Helper/Data.php +59 -0
  11. app/code/local/Shiptheory/Shippinglabels/Model/Config.php +139 -0
  12. app/code/local/Shiptheory/Shippinglabels/Model/Config/Api.php +15 -0
  13. app/code/local/Shiptheory/Shippinglabels/Model/Config/Observer.php +104 -0
  14. app/code/local/Shiptheory/Shippinglabels/Model/History.php +95 -0
  15. app/code/local/Shiptheory/Shippinglabels/Model/History/Observer.php +117 -0
  16. app/code/local/Shiptheory/Shippinglabels/Model/Mysql4/History.php +14 -0
  17. app/code/local/Shiptheory/Shippinglabels/Model/Mysql4/History/Collection.php +13 -0
  18. app/code/local/Shiptheory/Shippinglabels/Model/Observer.php +20 -0
  19. app/code/local/Shiptheory/Shippinglabels/Model/Order.php +44 -0
  20. app/code/local/Shiptheory/Shippinglabels/Model/Order/Observer.php +109 -0
  21. app/code/local/Shiptheory/Shippinglabels/Model/Version.php +13 -0
  22. app/code/local/Shiptheory/Shippinglabels/Model/Webservice.php +156 -0
  23. app/code/local/Shiptheory/Shippinglabels/Triggers.php +15 -0
  24. app/code/local/Shiptheory/Shippinglabels/controllers/Adminhtml/ShippinglabelsController.php +252 -0
  25. app/code/local/Shiptheory/Shippinglabels/etc/api.xml +28 -0
  26. app/code/local/Shiptheory/Shippinglabels/etc/config.xml +164 -0
  27. app/code/local/Shiptheory/Shippinglabels/etc/system.xml +107 -0
  28. app/code/local/Shiptheory/Shippinglabels/sql/shippinglabels_setup/mysql4-install-0.0.1.php +25 -0
  29. app/design/adminhtml/base/default/layout/shiptheory.xml +11 -0
  30. app/design/adminhtml/base/default/template/shiptheory/system/config/fieldset/dpd.phtml +36 -0
  31. app/design/adminhtml/base/default/template/shiptheory/system/config/fieldset/hint.phtml +11 -0
  32. app/etc/modules/Shiptheory_Dpd.xml +8 -0
  33. app/etc/modules/Shiptheory_Shippinglabels.xml +8 -0
  34. package.xml +18 -0
  35. skin/adminhtml/default/default/shiptheory/css/shiptheory.css +1 -0
  36. skin/adminhtml/default/default/shiptheory/images/shiptheory-section.png +0 -0
  37. skin/adminhtml/default/default/shiptheory/images/shiptheory.png +0 -0
app/code/local/Shiptheory/Dpd/Block/Adminhtml/System/Config/Fieldset/Hint.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Dpd
5
+ */
6
+ class Shiptheory_Dpd_Block_Adminhtml_System_Config_Fieldset_Hint extends Mage_Adminhtml_Block_Abstract implements Varien_Data_Form_Element_Renderer_Interface
7
+ {
8
+
9
+ /**
10
+ * hint template file
11
+ */
12
+
13
+ protected $_template = 'shiptheory/system/config/fieldset/dpd.phtml';
14
+
15
+ /**
16
+ * Render hint
17
+ */
18
+
19
+ public function render(Varien_Data_Form_Element_Abstract $element) {
20
+
21
+ return $this->toHtml();
22
+
23
+ }
24
+
25
+ /**
26
+ * Check if extension has been setup
27
+ */
28
+
29
+ public function isSetup() {
30
+
31
+ $status = false;
32
+
33
+ if(Mage::getStoreConfig('shippinglabels/misc/apikey') && Mage::getStoreConfig('shippinglabels/misc/enabled')){
34
+ $status = true;
35
+ }
36
+
37
+ return $status;
38
+
39
+ }
40
+
41
+ }
app/code/local/Shiptheory/Dpd/Helper/Data.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Dpd
5
+ */
6
+ class Shiptheory_Dpd_Helper_Data extends Mage_Core_Helper_Abstract
7
+ {
8
+ }
app/code/local/Shiptheory/Dpd/etc/config.xml ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Shiptheory_Dpd>
5
+ <version>0.0.1</version>
6
+ </Shiptheory_Dpd>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <dpd>
11
+ <class>Shiptheory_Dpd_Model</class>
12
+ </dpd>
13
+ </models>
14
+ <helpers>
15
+ <dpd>
16
+ <class>Shiptheory_Dpd_Helper</class>
17
+ </dpd>
18
+ </helpers>
19
+ <blocks>
20
+ <dpd>
21
+ <class>Shiptheory_Dpd_Block</class>
22
+ </dpd>
23
+ </blocks>
24
+ </global>
25
+ <admin>
26
+ <routers>
27
+ <dpd>
28
+ <use>admin</use>
29
+ <args>
30
+ <module>Shiptheory_Dpd</module>
31
+ <frontName>dpd</frontName>
32
+ </args>
33
+ </dpd>
34
+ </routers>
35
+ </admin>
36
+ <adminhtml>
37
+ <layout>
38
+ <updates>
39
+ <shiptheory>
40
+ <file>shiptheory.xml</file>
41
+ </shiptheory>
42
+ </updates>
43
+ </layout>
44
+ <acl>
45
+ <resources>
46
+ <admin>
47
+ <children>
48
+ <system>
49
+ <children>
50
+ <config>
51
+ <children>
52
+ <dpd translate="title" module="dpd">
53
+ <title>Dpd Setup</title>
54
+ <sort_order>20</sort_order>
55
+ </dpd>
56
+ </children>
57
+ </config>
58
+ </children>
59
+ </system>
60
+ </children>
61
+ </admin>
62
+ </resources>
63
+ </acl>
64
+ </adminhtml>
65
+ </config>
app/code/local/Shiptheory/Dpd/etc/system.xml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <dpd translate="label" module="dpd">
5
+ <label>DPD</label>
6
+ <tab>shiptheory</tab>
7
+ <class>dpd-section</class>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>1</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <groups>
14
+ <hint>
15
+ <frontend_model>dpd/adminhtml_system_config_fieldset_hint</frontend_model>
16
+ <sort_order>0</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <show_in_store>1</show_in_store>
20
+ </hint>
21
+ </groups>
22
+ </dpd>
23
+ </sections>
24
+ </config>
app/code/local/Shiptheory/Shippinglabels/Block/Adminhtml/Shippinglabels.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ class Shiptheory_Shippinglabels_Block_Adminhtml_Shippinglabels extends Mage_Adminhtml_Block_Widget_Grid_Container
7
+ {
8
+
9
+ public function __construct()
10
+ {
11
+
12
+ $this->_blockGroup = 'shippinglabels';
13
+ $this->_controller = 'adminhtml_shippinglabels';
14
+ $this->_headerText = $this->__('Shiptheory History');
15
+
16
+ //$this->_addButton('retry', array(
17
+ // 'label' => Mage::helper('shippinglabels')->__('Retry All'),
18
+ // 'onclick' => "setLocation('".$this->getUrl('*/*/retry')."')",
19
+ //));
20
+
21
+ //$this->_addButton('refresh', array(
22
+ // 'label' => Mage::helper('shippinglabels')->__('Refresh Config'),
23
+ // 'onclick' => "setLocation('".$this->getUrl('*/*/refresh')."')",
24
+ //));
25
+
26
+
27
+ parent::__construct();
28
+
29
+ $this->removeButton('add');
30
+
31
+ }
32
+ }
app/code/local/Shiptheory/Shippinglabels/Block/Adminhtml/Shippinglabels/Grid.php ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ class Shiptheory_Shippinglabels_Block_Adminhtml_Shippinglabels_Grid extends Mage_Adminhtml_Block_Widget_Grid
7
+ {
8
+
9
+ public function __construct()
10
+ {
11
+ parent::__construct();
12
+ $this->setId('shippinglabels_queue_grid');
13
+ $this->setDefaultSort('created');
14
+ $this->setDefaultDir('DESC');
15
+ $this->setSaveParametersInSession(true);
16
+ }
17
+
18
+ protected function _prepareCollection()
19
+ {
20
+
21
+ $this->setDefaultFilter(array('status' => array("1","0")));
22
+ $collection = Mage::getModel('shippinglabels/history')->getCollection();
23
+ $collection->addFieldToFilter('status', array('in' => array(1,2,0)));
24
+ $this->setCollection($collection);
25
+ return parent::_prepareCollection();
26
+
27
+ }
28
+
29
+ protected function _prepareColumns()
30
+ {
31
+
32
+ $this->addColumn('reference', array(
33
+
34
+ 'header' => Mage::helper('shippinglabels')->__('Id'),
35
+ 'align' =>'right',
36
+ 'width' => '100px',
37
+ 'index' => 'reference'
38
+ ));
39
+
40
+ $this->addColumn('status', array(
41
+
42
+ 'header' => Mage::helper('shippinglabels')->__('Status'),
43
+ 'align' => 'left',
44
+ 'width' => '150px',
45
+ 'index' => 'status',
46
+ 'type' => 'options',
47
+ 'options' => array(
48
+ 'failed' => 'Failed',
49
+ 'success' => 'Complete',
50
+ 'pending' => 'Pending'
51
+ ),
52
+ 'filter_condition_callback' => array($this, '_filterStatusCondition')
53
+ ));
54
+
55
+ $this->addColumn('attempts', array(
56
+
57
+ 'header' => Mage::helper('shippinglabels')->__('# Retries'),
58
+ 'align' =>'right',
59
+ 'width' => '10px',
60
+ 'index' => 'attempts'
61
+ ));
62
+
63
+ $this->addColumn('message', array(
64
+
65
+ 'header' => Mage::helper('shippinglabels')->__('Message'),
66
+ 'align' =>'right',
67
+ 'width' => '300px',
68
+ 'index' => 'message',
69
+ ));
70
+
71
+ $this->addColumn('created', array(
72
+ 'header' => Mage::helper('shippinglabels')->__('Created'),
73
+ 'align' => 'left',
74
+ 'width' => '120px',
75
+ 'type' => 'datetime',
76
+ 'default' => '--',
77
+ 'index' => 'created',
78
+ ));
79
+
80
+ $this->addColumn('action',
81
+ array(
82
+ 'header' => Mage::helper('shippinglabels')->__('Action'),
83
+ 'width' => '100',
84
+ 'type' => 'action',
85
+ 'getter' => 'getId',
86
+ 'actions' => array(
87
+ array(
88
+
89
+ )
90
+ ),
91
+ 'filter' => false,
92
+ 'sortable' => false,
93
+ 'index' => 'shippinglabels',
94
+ 'is_system' => true,
95
+ ));
96
+
97
+
98
+
99
+ return parent::_prepareColumns();
100
+ }
101
+
102
+ public function getRowUrl($row)
103
+ {
104
+
105
+ }
106
+
107
+ protected function _filterStatusCondition($collection, $column)
108
+ {
109
+
110
+ if(!$status = $column->getFilter()->getValue()){
111
+ return;
112
+ }
113
+
114
+ if(is_array($status)){
115
+
116
+ $this->getCollection()->addFieldToFilter('status', array('in' => $status));
117
+
118
+ } else {
119
+
120
+ $this->getCollection()->addFieldToFilter('status', $status);
121
+
122
+ }
123
+ }
124
+
125
+
126
+ }
app/code/local/Shiptheory/Shippinglabels/Block/Adminhtml/System/Config/Fieldset/Hint.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ class Shiptheory_Shippinglabels_Block_Adminhtml_System_Config_Fieldset_Hint extends Mage_Adminhtml_Block_Abstract implements Varien_Data_Form_Element_Renderer_Interface
7
+ {
8
+
9
+ /**
10
+ * hint template file
11
+ */
12
+
13
+ protected $_template = 'shiptheory/system/config/fieldset/hint.phtml';
14
+
15
+ /**
16
+ * Render hint
17
+ */
18
+
19
+ public function render(Varien_Data_Form_Element_Abstract $element) {
20
+
21
+ return $this->toHtml();
22
+
23
+ }
24
+
25
+ }
app/code/local/Shiptheory/Shippinglabels/Block/Adminhtml/Version.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ class Shiptheory_Shippinglabels_Block_Adminhtml_Version extends Mage_Adminhtml_Block_System_Config_Form_Field
7
+ {
8
+
9
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
10
+ {
11
+
12
+ return (string) Mage::helper('shippinglabels')->getExtensionVersion();
13
+
14
+ }
15
+
16
+ }
app/code/local/Shiptheory/Shippinglabels/Block/Button/New.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ class Shiptheory_Shippinglabels_Block_Button_New extends Mage_Adminhtml_Block_System_Config_Form_Field
7
+ {
8
+
9
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
10
+ {
11
+
12
+ $this->setElement($element);
13
+
14
+ $html = $this->getLayout()->createBlock('adminhtml/widget_button')
15
+ ->setType('button')
16
+ ->setClass('scalable')
17
+ ->setLabel('Register Free')
18
+ ->setOnClick("setLocation('https://shiptheory.com/integrate/magento/dpd')")
19
+ ->toHtml();
20
+
21
+ return $html;
22
+
23
+ }
24
+ }
app/code/local/Shiptheory/Shippinglabels/Helper/Data.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ class Shiptheory_Shippinglabels_Helper_Data extends Mage_Core_Helper_Abstract
7
+ {
8
+
9
+ /**
10
+ * Current extension version
11
+ *
12
+ * @return string
13
+ **/
14
+
15
+ public function getExtensionVersion()
16
+ {
17
+ return (string) Mage::getConfig()->getNode()->modules->Shiptheory_Shippinglabels->version;
18
+ }
19
+
20
+ /**
21
+ * Logger
22
+ *
23
+ * @param string
24
+ **/
25
+
26
+ public function log($message)
27
+ {
28
+
29
+ if(Mage::getStoreConfig('shippinglabels/advanced/log')){
30
+
31
+ Mage::log($message, null, 'Shiptheory.log');
32
+
33
+ }
34
+
35
+ }
36
+
37
+ /**
38
+ * Changes extension status
39
+ *
40
+ * @param string new status
41
+ * @return string current status
42
+ **/
43
+
44
+ public function status($status = null)
45
+ {
46
+ $current_status = Mage::getStoreConfig('shippinglabels/default/status');
47
+
48
+ //return current status
49
+ if(is_null($status)){
50
+ return $current_status;
51
+ }
52
+
53
+ //update status
54
+ $config = new Mage_Core_Model_Config();
55
+ $config->saveConfig('shippinglabels/default/status', $status, 'default', 0);
56
+
57
+ }
58
+
59
+ }
app/code/local/Shiptheory/Shippinglabels/Model/Config.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ class Shiptheory_Shippinglabels_Model_Config extends Mage_Core_Model_Abstract
7
+ {
8
+
9
+ protected function _construct()
10
+ {
11
+ $this->_init('shippinglabels/config');
12
+ }
13
+
14
+ /**
15
+ * Load config data
16
+ *
17
+ * @return array
18
+ * @param string
19
+ */
20
+
21
+ public function load($api_key, $field = null)
22
+ {
23
+
24
+ $data = array();
25
+ $data['websites'] = $this->getWebsiteData();
26
+ $data['status'] = $this->getStatusData();
27
+ $data['shipping'] = $this->getShippingMethodData();
28
+ $data['shiptheory_url'] = $this->getUrl();
29
+ $data['shiptheory_user'] = $this->getApiUser();
30
+ $data['shiptheory_pass'] = $api_key;
31
+ return $data;
32
+
33
+ }
34
+
35
+ /**
36
+ * Create a Shiptheory Config Update
37
+ *
38
+ * @param array config_data
39
+ **/
40
+
41
+ public function create($config_data)
42
+ {
43
+
44
+ try{
45
+
46
+ $post = Mage::getModel("shippinglabels/webservice")->config($config_data);
47
+
48
+ }catch (Exception $e) {
49
+ Mage::helper('shippinglabels')->log("Failed communicating with Shiptheory: ".$e);
50
+ }
51
+
52
+ if(!$post){
53
+ Mage::helper('shippinglabels')->log("Failed to communicate with Shippinglabels");
54
+ return false;
55
+ }
56
+
57
+ return true;
58
+
59
+ }
60
+
61
+ /**
62
+ * Get website setup
63
+ *
64
+ * @return array
65
+ */
66
+
67
+ protected function getWebsiteData()
68
+ {
69
+
70
+ $stores = Mage::getModel('core/store')->getCollection()->getData();
71
+ return array(Mage::getModel('core/website')->getCollection()->getData(), $stores);
72
+
73
+ }
74
+
75
+ /**
76
+ * Get core shipping method data
77
+ *
78
+ * @return array
79
+ */
80
+
81
+ public function getShippingMethodData()
82
+ {
83
+
84
+ $carriers = Mage::getSingleton('shipping/config')->getActiveCarriers();
85
+ $shipping_methods = array();
86
+
87
+ foreach ($carriers as $shipping_code => $shipping_model)
88
+ {
89
+
90
+ $shipping_title = Mage::getStoreConfig('carriers/'.$shipping_code.'/title');
91
+ $shipping_methods[] = array(
92
+ 'code' => $shipping_code,
93
+ 'title' => $shipping_title,
94
+ );
95
+
96
+ }
97
+
98
+ return $shipping_methods;
99
+
100
+ }
101
+
102
+ /**
103
+ * Get statuses
104
+ *
105
+ * @return array
106
+ */
107
+
108
+ protected function getStatusData()
109
+ {
110
+
111
+ return Mage::getModel('sales/order_status')->getCollection()->getData();
112
+
113
+ }
114
+
115
+ /**
116
+ * Get Shippinglabels API User information
117
+ *
118
+ * @return array
119
+ */
120
+
121
+ protected function getApiUser()
122
+ {
123
+
124
+ return Mage::getStoreConfig('shippinglabels/default/apiusername');
125
+
126
+ }
127
+
128
+ /**
129
+ * Get URL
130
+ *
131
+ * @return string
132
+ */
133
+
134
+ protected function getUrl()
135
+ {
136
+ return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
137
+ }
138
+
139
+ }
app/code/local/Shiptheory/Shippinglabels/Model/Config/Api.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ class Shiptheory_Shippinglabels_Model_Config_Api extends Mage_Api_Model_Resource_Abstract {
7
+
8
+
9
+ public function getShippingMethods() {
10
+
11
+ return Mage::getModel('shippinglabels/config')->getShippingMethodData();
12
+
13
+ }
14
+
15
+ }
app/code/local/Shiptheory/Shippinglabels/Model/Config/Observer.php ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ class Shiptheory_Shippinglabels_Model_Config_Observer
7
+ {
8
+
9
+ public function configure($observer)
10
+ {
11
+
12
+ if(Mage::registry('shippinglabels_config_save_after_executed')){
13
+ return;
14
+ }
15
+
16
+ Mage::register('shippinglabels_config_save_after_executed', true);
17
+
18
+ if(!Mage::getStoreConfig('shippinglabels/misc/apikey')){
19
+ return Mage::getSingleton('core/session')->addError('You must provide a Shiptheory API Key. <a href="#" target="_blank">How do I get an API Key</a>');
20
+ }
21
+
22
+ //check/create api user and role
23
+ $id = Mage::getStoreConfig('shippinglabels/default/apiuserid');
24
+ $api_user = Mage::getModel('api/user')->load($id);
25
+
26
+ if(!$api_user->getData()){
27
+
28
+ //utilise customer Model to generate a random api key
29
+ $api_key = Mage::getModel('customer/customer')->generatePassword();
30
+
31
+ $api_user = Mage::getModel('api/user')
32
+ ->setData(array(
33
+ 'username' => Mage::getStoreConfig('shippinglabels/default/apiusername'),
34
+ 'firstname' => Mage::getStoreConfig('shippinglabels/default/apiname'),
35
+ 'lastname' => Mage::getStoreConfig('shippinglabels/default/apiname'),
36
+ 'email' => Mage::getStoreConfig('shippinglabels/default/apiemail'),
37
+ 'api_key' => $api_key,
38
+ 'api_key_confirmation' => $api_key,
39
+ 'is_active' => 1,
40
+ ));
41
+
42
+ //create role
43
+ $role = Mage::getModel('api/roles')
44
+ ->setName('Shiptheory')
45
+ ->setPid(false)
46
+ ->setRoleType('G')
47
+ ->save();
48
+
49
+ //assign resource
50
+ Mage::getModel("api/rules")
51
+ ->setRoleId($role->getId())
52
+ ->setResources(array('all'))
53
+ ->saveRel();
54
+
55
+ try{
56
+
57
+ $api_user->save();
58
+ $api_user->setRoleIds(array($role->getId()))
59
+ ->setRoleUserId($api_user->getUserId())
60
+ ->saveRelations();
61
+
62
+ }catch (Exception $e) {
63
+ Mage::helper('shippinglabels')->log($e);
64
+ }
65
+
66
+ //load core config data
67
+ $config_data = Mage::getModel('shippinglabels/config')->load($api_key);
68
+
69
+ try{
70
+
71
+ $config_post = Mage::getModel("shippinglabels/config")->create($config_data);
72
+
73
+ }catch (Exception $e) {
74
+ Mage::helper('shippinglabels')->log("Failed transmit setup data: ".$e);
75
+ }
76
+
77
+ if($config_post && $api_user->getId()){
78
+
79
+ $auth_test = true;
80
+ //Update extension config to store the Shiptheory api user id
81
+ $config = new Mage_Core_Model_Config();
82
+ $config->saveConfig('shippinglabels/default/apiuserid', $api_user->getId(), 'default', 0);
83
+
84
+ }else{
85
+
86
+ //display failed message and delete API user
87
+ Mage::getSingleton('core/session')->addError("Unable to communicate with Shiptheory. Please try again.<br />If the problem persists, please <a href=\"http://support.shiptheory.com/\" target=\"_blank\">contact support</a>");
88
+ $api_user->delete();
89
+
90
+ }
91
+
92
+ }
93
+
94
+ if(isset($auth_test) && Mage::getStoreConfig('shippinglabels/default/status')!='approved'){
95
+
96
+ //update extension status
97
+ Mage::helper('shippinglabels')->status('pending');
98
+
99
+ Mage::getSingleton('core/session')->getMessages(true);
100
+ Mage::getSingleton('core/session')->addSuccess("Success, everything is now connected. Check out your Shiptheory account to <a href=\"https://shiptheory.com/magento/edit\" target=\"_blank\">setup some shipping rules</a>.");
101
+ }
102
+
103
+ }
104
+ }
app/code/local/Shiptheory/Shippinglabels/Model/History.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ class Shiptheory_Shippinglabels_Model_History extends Mage_Core_Model_Abstract
7
+ {
8
+
9
+ protected function _construct()
10
+ {
11
+ $this->_init('shippinglabels/history');
12
+ }
13
+
14
+ /**
15
+ * Retries POST request from queue to Shippinglabels
16
+ *
17
+ * @param int $type
18
+ * @param int $id
19
+ * @param mixed $response
20
+ **/
21
+
22
+ public function reprocess($type, $id = null){
23
+
24
+ $response = false;
25
+
26
+ //TODO store type ids in the config or as constants
27
+ if($type == Mage::getStoreConfig('shippinglabels/constants/queue_type/order')){
28
+
29
+ //get Order
30
+ $_shippinglabelsModel = 'order';
31
+ $post_data = Mage::getModel("sales/order")->load($id);
32
+
33
+ if(!$post_data->getId()){
34
+ Mage::helper('shippinglabels')->log('Unable to load order '.$id);
35
+ }
36
+
37
+ }elseif($type == Mage::getStoreConfig('shippinglabels/constants/queue_type/product')){
38
+
39
+ //get Product
40
+ $_shippinglabelsModel = 'product';
41
+ $product = Mage::getModel("catalog/product")->load($id);
42
+
43
+ if(!$product->getId()){
44
+ Mage::helper('shippinglabels')->log('Unable to load product '.$id);
45
+ }
46
+
47
+ $post_data = array(
48
+ 'sku' => $product->getSKU(),
49
+ /*'oldsku' => $this->_previousSku,*/
50
+ 'website_ids' => $product->getWebsiteIds()
51
+ );
52
+
53
+ }elseif($type == Mage::getStoreConfig('shippinglabels/constants/queue_type/config')){
54
+
55
+ //get Configuration
56
+ $_shippinglabelsModel = 'config';
57
+ $post_data = Mage::getModel('shippinglabels/config')->load();
58
+
59
+ }else{
60
+ Mage::helper('shippinglabels')->log("Unknown Message Queue type.");
61
+ }
62
+
63
+ //we have the payload, rePOST it to Shippinglabels
64
+ try{
65
+
66
+ $response = Mage::getModel("shippinglabels/{$_shippinglabelsModel}")->create($post_data);
67
+
68
+ }catch (Exception $e){
69
+ Mage::helper('shippinglabels')->log('Failed to repost payload to Shippinglabels'.$e);
70
+ }
71
+
72
+ return $response;
73
+
74
+ }
75
+
76
+
77
+ /**
78
+ * Checks for local queue data
79
+ *
80
+ **/
81
+
82
+ public function loadArchive($id = null){
83
+
84
+ $archive = Mage::getModel('shippinglabels/history');
85
+ $archive->load($id, 'internal_id');
86
+
87
+ if(!$archive->getId()){
88
+ return false;
89
+ }
90
+
91
+ return $archive->getId();
92
+
93
+ }
94
+
95
+ }
app/code/local/Shiptheory/Shippinglabels/Model/History/Observer.php ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ class Shiptheory_Shippinglabels_Model_Queue_Observer
7
+ {
8
+
9
+ /**
10
+ * Retries pending and failed queued items
11
+ *
12
+ **/
13
+
14
+ public function reprocess()
15
+ {
16
+
17
+ Mage::helper('shippinglabels')->log("Reprocessing queue running");
18
+
19
+ // find all pending and failed queued jobs where retry count < limit
20
+ $queue = Mage::getModel("shippinglabels/queue")->getCollection();
21
+ $queue->addFieldToFilter('status', array('in' => array(1,0)));
22
+ $queue->addFieldToFilter('attempts', array('lteq' => Mage::getStoreConfig('shippinglabels/default/retrylimit')));
23
+
24
+ foreach($queue as $job)
25
+ {
26
+
27
+ Mage::helper('shippinglabels')->log("Reprocessing Job id: ".$job->getID());
28
+ $shippinglabels_post = Mage::getModel('shippinglabels/queue')->reprocess($job->getTypeId(), $job->getInternalId());
29
+ Mage::helper('shippinglabels')->log("Result: ".$shippinglabels_post);
30
+
31
+ $queued_job = Mage::getModel("shippinglabels/queue")->load($id);
32
+ $queued_job->setAttempts(($queued_job->getAttempts()+1))->save();
33
+ $queued_job->setStatus(Mage::getStoreConfig('shippinglabels/constants/queue_status/complete'))->save();
34
+
35
+ }
36
+
37
+
38
+
39
+ }
40
+
41
+ /**
42
+ * Sends daily product digest to Shippinglabels
43
+ *
44
+ **/
45
+
46
+ public function digest()
47
+ {
48
+
49
+ $product_data = array();
50
+
51
+ $products = Mage::getModel('catalog/product')->getCollection()
52
+ ->addAttributeToSelect('*');
53
+
54
+ foreach($products as $product) {
55
+
56
+ $core_product_data = array();
57
+ $tier_product_data = array();
58
+ $group_product_data = array();
59
+
60
+ $product_detail = Mage::getModel('catalog/product')->load($product->getId());
61
+
62
+
63
+ //set core product attributes
64
+ $core_product_data = array(
65
+ 'product_id' => $product->getId(),
66
+ 'sku' => $product->getSku(),
67
+ 'website_ids' => $product->getWebsiteIds(),
68
+ 'qty' => $product_detail->getStockItem()->getQty(),
69
+ 'price' => $product->getPrice(),
70
+ 'special_price' => $product->getSpecialPrice()
71
+
72
+ );
73
+
74
+ //get tier prices
75
+ if($product_detail->getTierPrice()){
76
+
77
+ foreach($product_detail->getTierPrice() as $tier){
78
+
79
+ $tier_product_data[] = array(
80
+ 'customer_group_id' => $tier['cust_group'],
81
+ 'qty' => $tier['price_qty'],
82
+ 'price' => $tier['price']
83
+ );
84
+
85
+ }
86
+
87
+ }
88
+
89
+ //get group prices
90
+ if(is_array($product_detail->getGroupPrice())){
91
+
92
+ foreach($product_detail->getGroupPrice() as $group){
93
+
94
+ $group_product_data[] = array(
95
+ 'customer_group_id' => $group['cust_group'],
96
+ 'price' => $group['price']
97
+ );
98
+
99
+ }
100
+
101
+ }
102
+
103
+ $product_data[] = $core_product_data + array('tier_price' => $tier_product_data) + array('group_price' => $group_product_data);
104
+
105
+ }
106
+
107
+ try{
108
+
109
+ $queue = Mage::getModel("shippinglabels/webservice")->digest(json_decode($product_data));
110
+
111
+ }catch (Exception $e) {
112
+ Mage::helper('shippinglabels')->log("Failed to call Webservice: ".$e);
113
+ }
114
+
115
+ }
116
+
117
+ }
app/code/local/Shiptheory/Shippinglabels/Model/Mysql4/History.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ class Shiptheory_Shippinglabels_Model_Mysql4_History extends Mage_Core_Model_Mysql4_Abstract
7
+ {
8
+
9
+ protected function _construct()
10
+ {
11
+ $this->_init('shippinglabels/history', 'id');
12
+ }
13
+
14
+ }
app/code/local/Shiptheory/Shippinglabels/Model/Mysql4/History/Collection.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ class Shiptheory_Shippinglabels_Model_Mysql4_History_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
7
+ {
8
+
9
+ protected function _construct()
10
+ {
11
+ $this->_init('shippinglabels/history');
12
+ }
13
+ }
app/code/local/Shiptheory/Shippinglabels/Model/Observer.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ class Shiptheory_Shippinglabels_Model_Observer
7
+ {
8
+ public function addShippingAction($observer)
9
+ {
10
+ $block = $observer->getEvent()->getBlock();
11
+ if(get_class($block) =='Mage_Adminhtml_Block_Widget_Grid_Massaction'
12
+ && $block->getRequest()->getControllerName() == 'sales_order')
13
+ {
14
+ $block->addItem('shippinglabels', array(
15
+ 'label' => 'Ship Orders',
16
+ 'url' => Mage::app()->getStore()->getUrl('shippinglabels/adminhtml_shippinglabels/ship')
17
+ ));
18
+ }
19
+ }
20
+ }
app/code/local/Shiptheory/Shippinglabels/Model/Order.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ class Shiptheory_Shippinglabels_Model_Order extends Mage_Core_Model_Abstract
7
+ {
8
+
9
+ protected function _construct()
10
+ {
11
+ $this->_init('shippinglabels/order');
12
+ }
13
+
14
+ /**
15
+ * Create a POST request
16
+ *
17
+ * @param object $order
18
+ **/
19
+
20
+ public function create($order){
21
+
22
+ try{
23
+
24
+ $response = Mage::getModel("shippinglabels/webservice")->order($order);
25
+
26
+ }catch (Exception $e) {
27
+ Mage::helper('shippinglabels')->log("Failed calling Webservice: ".$e);
28
+ }
29
+
30
+ if($response){
31
+ if(!($response->getStatus() >= 200 && $response->getStatus() <= 204)){
32
+ Mage::helper('shippinglabels')->log("Failed to communicate with Shiptheory.com. ".$response->getMessage());
33
+ return false;
34
+ }
35
+ }else{
36
+ Mage::helper('shippinglabels')->log("Failed to communicate with Shiptheory.com. ");
37
+ return false;
38
+ }
39
+
40
+ return true;
41
+
42
+ }
43
+
44
+ }
app/code/local/Shiptheory/Shippinglabels/Model/Order/Observer.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ class Shiptheory_Shippinglabels_Model_Order_Observer
7
+ {
8
+
9
+ protected $_orderId = null;
10
+ protected $_failMsg = 'Failed to send to Shiptheory';
11
+ protected $_successMsg = 'Sent to Shiptheory successfully';
12
+ protected $_failStatus = 'failed';
13
+ protected $_successStatus = 'success';
14
+
15
+ /**
16
+ * Listens to order save event
17
+ *
18
+ * @param object $observer
19
+ **/
20
+
21
+ public function order($observer)
22
+ {
23
+ $order = $observer->getEvent()->getOrder();
24
+ $data = [
25
+ 'order_id' => $order->getId()
26
+ ];
27
+
28
+ return $this->queue($order, $data);
29
+ }
30
+
31
+ /**
32
+ * Listens to shipment save event
33
+ *
34
+ * @param object $observer
35
+ **/
36
+
37
+ public function shipment($observer)
38
+ {
39
+ $order = Mage::getModel('sales/order')->load($observer->getEvent()->getShipment()->getOrderId());
40
+ $data = [
41
+ 'order_id' => $observer->getEvent()->getShipment()->getOrderId(),
42
+ 'shipment_id' => $observer->getEvent()->getShipment()->getIncrementId()
43
+ ];
44
+
45
+ return $this->queue($order, $data);
46
+ }
47
+
48
+ /**
49
+ * Queues and POSTS Shippinglabels order
50
+ *
51
+ * @param object $order
52
+ * @param array $data
53
+ **/
54
+
55
+ protected function queue($order, $data)
56
+ {
57
+
58
+ if(Mage::registry('sales_order_save_commit_after_executed')){
59
+ return;
60
+ }
61
+
62
+ Mage::register('sales_order_save_commit_after_executed', true);
63
+ $order_id = $order->getId();
64
+ $this->_orderId = Mage::getModel('shippinglabels/history')->loadArchive($order_id);
65
+
66
+ //save the new order to the local Shiptheory queue
67
+ $pending_order = Mage::getModel('shippinglabels/history');
68
+ if($this->_orderId){
69
+ $pending_order->setId($this->_orderId);
70
+ }
71
+
72
+ try{
73
+
74
+ $pending_order
75
+ ->setInternalId($order_id)
76
+ ->setReference($order->getIncrementId())
77
+ ->save();
78
+
79
+ }catch (Exception $e) {
80
+ Mage::helper('shippinglabels')->log($e);
81
+ }
82
+
83
+ try{
84
+
85
+ $shippinglabels_order = Mage::getModel("shippinglabels/order")->create($data);
86
+
87
+ }catch (Exception $e) {
88
+ Mage::helper('shippinglabels')->log("Failed to create queued order: ".$e);
89
+ }
90
+
91
+ if(isset($shippinglabels_order)){
92
+
93
+ //update the local Shiptheory order queue status to complete
94
+ $pending_order
95
+ ->setStatus($this->_successStatus)
96
+ ->setMessage($this->_successMsg)
97
+ ->save();
98
+
99
+ }else{
100
+
101
+ //update the local Shiptheory order queue status to failed
102
+ $pending_order
103
+ ->setStatus($this->_failStatus)
104
+ ->setMessage($this->_failMsg)
105
+ ->save();
106
+ }
107
+
108
+ }
109
+ }
app/code/local/Shiptheory/Shippinglabels/Model/Version.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ class Shiptheory_Shippinglabels_Model_Version extends Mage_Core_Model_Abstract
7
+ {
8
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
9
+ {
10
+ return (string) Mage::helper('shippinglabels')->getExtensionVersion();
11
+ }
12
+
13
+ }
app/code/local/Shiptheory/Shippinglabels/Model/Webservice.php ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ class Shiptheory_Shippinglabels_Model_Webservice extends Mage_Core_Model_Abstract
7
+ {
8
+
9
+ protected function _construct()
10
+ {
11
+
12
+ $this->_init('shippinglabels/token');
13
+ }
14
+
15
+ /**
16
+ * Prepares Order POST
17
+ *
18
+ * @param array
19
+ **/
20
+
21
+ public function order($data)
22
+ {
23
+
24
+ $order_endpoint = Mage::getStoreConfig('shippinglabels/endpoint/order');
25
+ return $this->get($data, $order_endpoint);
26
+
27
+ }
28
+
29
+ /**
30
+ * Prepares Configuration POST
31
+ *
32
+ * @return array
33
+ **/
34
+
35
+ public function config($data)
36
+ {
37
+
38
+ $config_endpoint = Mage::getStoreConfig('shippinglabels/endpoint/configuration');
39
+ return $this->post($data, $config_endpoint);
40
+
41
+ }
42
+
43
+ /**
44
+ * GET Shiptheory
45
+ *
46
+ * @param array
47
+ * @param string endpoint
48
+ **/
49
+
50
+ protected function get($data, $endpoint)
51
+ {
52
+
53
+ $extension_version = (string)Mage::helper('shippinglabels')->getExtensionVersion();
54
+ $endpoint = Mage::getStoreConfig('shippinglabels/endpoint/order');
55
+
56
+ try{
57
+ $client = new Zend_Http_Client($endpoint);
58
+
59
+ }catch(Zend_Http_Client_Exception $e){
60
+ Mage::helper('shippinglabels')->log("Unable to create Zend_Http_Client: ".$e);
61
+ return false;
62
+ }
63
+
64
+ $ident = Mage::getStoreConfig('shippinglabels/misc/apikey');
65
+ $client->setHeaders(array(
66
+ 'Shiptheory-ident' => $ident,
67
+ 'X-Powered-By' => 'Shiptheory Magento Extension v'.$extension_version
68
+ )
69
+ );
70
+
71
+ $client->setParameterGet(array(
72
+ 'channel' => substr($ident, 0, -4)."/Magento/".$this->formatUrl()."/".$data['shipment_id']."/order/event"
73
+ ));
74
+
75
+ $data['timestamp'] = $this->getTimestamp();
76
+ $json = $this->formatJson($data);
77
+
78
+ $client->setRawData($json, 'application/json');
79
+ Mage::helper('shippinglabels')->log("Sending Json ".$json);
80
+ $response = $client->request(Zend_Http_Client::GET);
81
+
82
+ return $response;
83
+
84
+ }
85
+
86
+ /**
87
+ * POST Shiptheory
88
+ *
89
+ * @param array
90
+ * @param string endpoint
91
+ **/
92
+
93
+ protected function post($data, $endpoint)
94
+ {
95
+
96
+ $extension_version = (string)Mage::helper('shippinglabels')->getExtensionVersion();
97
+ $endpoint = Mage::getStoreConfig('shippinglabels/endpoint/setup');
98
+
99
+ try{
100
+ $client = new Zend_Http_Client($endpoint);
101
+
102
+ }catch(Zend_Http_Client_Exception $e){
103
+ Mage::helper('shippinglabels')->log("Unable to create Zend_Http_Client: ".$e);
104
+ return false;
105
+ }
106
+
107
+ $client->setHeaders(array(
108
+ 'Shiptheory-ident' => Mage::getStoreConfig('shippinglabels/misc/apikey'),
109
+ 'X-Powered-By' => 'Shiptheory Magento Extension v'.$extension_version
110
+ )
111
+ );
112
+
113
+ $data['timestamp'] = $this->getTimestamp();
114
+ $json = $this->formatJson($data);
115
+ $client->setParameterPost('magento_data', $json);
116
+ $response = $client->request(Zend_Http_Client::POST);
117
+ return true;
118
+ }
119
+
120
+ /**
121
+ * Formats JSON for POST
122
+ *
123
+ * @param array
124
+ * @return string json
125
+ **/
126
+
127
+ protected function formatJson($data)
128
+ {
129
+ return str_replace("\u0000*\u0000_", "", Mage::helper('core')->jsonEncode((array) $data ));
130
+ }
131
+
132
+ /**
133
+ * Returned formatted base url
134
+ *
135
+ **/
136
+
137
+ protected function formatUrl()
138
+ {
139
+ $url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
140
+ $url = str_replace("http://", "", $url);
141
+ $parts = explode("/", $url);
142
+ return $parts[0];
143
+ }
144
+
145
+ /**
146
+ * Timestamp
147
+ *
148
+ **/
149
+
150
+ protected function getTimestamp()
151
+ {
152
+ $timezone = new DateTime('now', new DateTimeZone(Mage::getStoreConfig('general/locale/timezone')));
153
+ return $currentDate = date('Y-m-d\\TH:i:s', Mage::getModel('core/date')->timestamp(time())).$timezone->format('P');
154
+ }
155
+
156
+ }
app/code/local/Shiptheory/Shippinglabels/Triggers.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ class Shiptheory_Shippinglabels_Triggers
7
+ {
8
+ public function toOptionArray()
9
+ {
10
+ return array(
11
+ array('value' => 'order', 'label'=>Mage::helper('adminhtml')->__('when orders are created')),
12
+ array('value' => 'shipment', 'label'=>Mage::helper('adminhtml')->__('when orders are shipped'))
13
+ );
14
+ }
15
+ }
app/code/local/Shiptheory/Shippinglabels/controllers/Adminhtml/ShippinglabelsController.php ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ class Shiptheory_Shippinglabels_Adminhtml_ShippinglabelsController extends Mage_Adminhtml_Controller_Action
7
+ {
8
+
9
+ /**
10
+ * Shippinglabels Model
11
+ */
12
+ protected $_shippinglabelsModel = false;
13
+
14
+
15
+ public function indexAction()
16
+ {
17
+ $this->loadLayout();
18
+ $this->_setActiveMenu('sales');
19
+ $this->_addContent($this->getLayout()->createBlock('shippinglabels/adminhtml_shippinglabels'));
20
+ $this->renderLayout();
21
+ }
22
+
23
+ /**
24
+ * Trigger queue retry
25
+ *
26
+ **/
27
+
28
+ public function retryAction()
29
+ {
30
+
31
+ if($this->getRequest()->getParam('id')){
32
+
33
+ //resend 1 queued message
34
+ $ids = array($this->getRequest()->getParam('id'));
35
+
36
+ }else{
37
+
38
+ //resend entire queue
39
+ $collection = Mage::getModel('shippinglabels/history')->getCollection();
40
+ $collection->addFieldToSelect('id');
41
+ //only retry failed or pending
42
+ $collection->addFieldToFilter('status', array('in' => array(1,0)));
43
+ $ids = $collection->getData();
44
+ $queued = $collection->count();
45
+ $failed_count = 0;$success_count = 0;
46
+
47
+ }
48
+
49
+ foreach($ids as $id)
50
+ {
51
+
52
+ try{
53
+
54
+ $queued_order = Mage::getModel("shippinglabels/history")->load($id);
55
+
56
+ }catch(Exception $e){
57
+ Mage::helper('shippinglabels')->log($e);
58
+ }
59
+
60
+ if(!$post_data = $this->sendRetry($queued_order)){
61
+ $this->_getSession()->addError($this->__("Message not found"));
62
+ $failed_count++;
63
+ }else{
64
+ $success_count++;
65
+ }
66
+
67
+ unset($queued_order);
68
+
69
+ }
70
+
71
+ if(isset($queued) && $success_count>0){
72
+
73
+ //overwrite Success session messages, replace with counts
74
+ $this->_getSession()->getMessages(true);
75
+ $this->_getSession()->addSuccess($this->__($success_count."/".$queued." sent successfully"));
76
+
77
+ }elseif(isset($queued) && $failed_count>0){
78
+ $this->_getSession()->getMessages(true);
79
+ $this->_getSession()->addError($this->__($failed_count."/".$queued." failed to send"));
80
+ }
81
+
82
+
83
+ return $this->_redirect('*/*/');
84
+
85
+ }
86
+
87
+ /**
88
+ * Repost queue retry
89
+ *
90
+ **/
91
+
92
+ protected function sendRetry($queued_order){
93
+
94
+ $post_data = false;
95
+
96
+ if(!$queued_order->internalId && $queued_order->getType() != Mage::getStoreConfig('shippinglabels/constants/queue_type/config')){
97
+
98
+ $this->_getSession()->addError($this->__("Record not found"));
99
+ return false;
100
+
101
+ }
102
+
103
+ $queue_id = $queued_order->getId();
104
+ if($queued_order->getType() == Mage::getStoreConfig('shippinglabels/constants/queue_type/order')){
105
+
106
+ //get Order
107
+ $_shippinglabelsModel = 'order';
108
+ $post_data = Mage::getModel("sales/order")->load($queued_order->internalId);
109
+
110
+ if(!$post_data->getId()){
111
+ $this->_getSession()->addError($this->__("Order ".$queued_order->internalId." not found"));
112
+ return;
113
+ }
114
+
115
+ }elseif($queued_order->getType() == Mage::getStoreConfig('shippinglabels/constants/queue_type/product')){
116
+
117
+ //get Product
118
+ $_shippinglabelsModel = 'product';
119
+
120
+ $product = Mage::getModel("catalog/product")->load($queued_order->internalId);
121
+ // prepare data based on action type
122
+ switch($queued_order->getAction())
123
+ {
124
+ case 'Add':
125
+ if(!$product->getId()){
126
+ $this->_getSession()->addError($this->__("Product ".$queued_order->internalId." not found"));
127
+ return;
128
+ }
129
+ $post_data = array(
130
+ 'sku' => $product->getSKU(),
131
+ 'message_id' => Mage::helper('shippinglabels')->getMessageId()
132
+ //'website_ids' => $product->getWebsiteIds()
133
+ );
134
+ break;
135
+ case 'Update':
136
+ if(!$product->getId()){
137
+
138
+ $this->_getSession()->addError($this->__("Product ".$queued_order->internalId." not found"));
139
+ return;
140
+ }
141
+ $post_data = array(
142
+ 'sku' => $product->getSKU(),
143
+ 'oldsku' => $queued_order->getPreviousReference(),
144
+ 'message_id' => Mage::helper('shippinglabels')->getMessageId()
145
+ //'website_ids' => $product->getWebsiteIds()
146
+ );
147
+ break;
148
+ case 'Delete':
149
+ $post_data = array(
150
+ 'sku' => $queued_order->getReference(),
151
+ 'message_id' => Mage::helper('shippinglabels')->getMessageId(),
152
+ 'delete' => true
153
+ //'website_ids' => array()
154
+ );
155
+ break;
156
+ }
157
+
158
+ }elseif($queued_order->getType() == Mage::getStoreConfig('shippinglabels/constants/queue_type/config')){
159
+
160
+ //get Configuration
161
+ $_shippinglabelsModel = 'config';
162
+ $post_data = Mage::getModel('shippinglabels/config')->load();
163
+ $post_data['message_id'] = Mage::helper('shippinglabels')->getMessageId();
164
+
165
+ }else{
166
+ Mage::helper('shippinglabels')->log("Unknown Message Queue type.");
167
+ }
168
+
169
+ //we have the payload, rePOST it to Shippinglabels
170
+ try{
171
+
172
+ $shippinglabels_order = Mage::getModel("shippinglabels/{$_shippinglabelsModel}")->create($post_data, $queue_id);
173
+
174
+ }catch (Exception $e){
175
+ Mage::helper('shippinglabels')->log("Failed to add order to queue: ".$e);
176
+ }
177
+
178
+ //update retry attempts
179
+ $queued_order->setAttempts(($queued_order->getAttempts()+1))->save();
180
+
181
+ if($shippinglabels_order){
182
+
183
+ //update the local Shippinglabels order queue status
184
+ $queued_order->setStatus(Mage::getStoreConfig('shippinglabels/constants/queue_status/complete'))->save();
185
+ $this->_getSession()->addSuccess($this->__("Transmitted to Shippinglabels"));
186
+ return $post_data;
187
+
188
+ }
189
+
190
+ //if we are here, something went wrong POSTING to Shippinglabels
191
+ $this->_getSession()->addError($this->__("Transmission to Shippinglabels Failed"));
192
+ return false;
193
+
194
+ }
195
+
196
+ /**
197
+ * Mass ship orders
198
+ */
199
+
200
+ public function shipAction()
201
+ {
202
+
203
+ $order_ids = $this->getRequest()->getParam('order_ids');
204
+ foreach($order_ids as $order_id){
205
+ $order = Mage::getModel('sales/order')->load($order_id);
206
+ if($order->canShip()){
207
+
208
+ $item_qty = $order->getItemsCollection()->count();
209
+ $shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($item_qty);
210
+ $shipment = new Mage_Sales_Model_Order_Shipment_Api();
211
+
212
+ $success = false;
213
+ try{
214
+ $shipment_id = $shipment->create($order->getIncrementId());
215
+ $success = true;
216
+
217
+ }catch (Exception $e) {
218
+ $this->_getSession()->addError($this->__("Order #".$order->getIncrementId()." Failed to Ship"));
219
+ Mage::log($e,null,'madcapsule_ordership.log');
220
+ }
221
+
222
+ if($success){
223
+ $this->_getSession()->addSuccess($this->__("Order #".$order->getIncrementId()." Successfully Shipped"));
224
+ }
225
+
226
+ }else{
227
+ $this->_getSession()->addError($this->__("Order #".$order->getIncrementId()." is Not Available to Ship. Have you already shipped it?"));
228
+ }
229
+ }
230
+
231
+ $this->_redirect('adminhtml/sales_order/');
232
+ }
233
+
234
+
235
+ protected function _initAction()
236
+ {
237
+
238
+ $this->loadLayout()
239
+ ->_setActiveMenu('sales/shippinglabels')
240
+ ->_title($this->__('Sales'))->_title($this->__('Shiptheory Messages'))
241
+ ->_addBreadcrumb($this->__('Sales'), $this->__('Sales'))
242
+ ->_addBreadcrumb($this->__('Shiptheory Messages'), $this->__('Shipteory Messages'));
243
+
244
+ return $this;
245
+
246
+ }
247
+
248
+ protected function _isAllowed()
249
+ {
250
+ return Mage::getSingleton('admin/session')->isAllowed('sales/shippinglabels');
251
+ }
252
+ }
app/code/local/Shiptheory/Shippinglabels/etc/api.xml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <api>
4
+ <resources>
5
+ <shiptheory translate="title" module="shippinglabels">
6
+ <title>Shiptheory</title>
7
+ <model>shippinglabels/config_api</model>
8
+ <methods>
9
+ <list translate="title" module="shippinglabels">
10
+ <title>Get Shipping Methods</title>
11
+ <method>getShippingMethods</method>
12
+ </list>
13
+ </methods>
14
+ </shiptheory>
15
+ </resources>
16
+ <acl>
17
+ <resources>
18
+ <shiptheory translate="title" module="shippinglabels">
19
+ <title>Shiptheory</title>
20
+ <list translate="title" module="shippinglabels">
21
+ <title>List Shipping Methods</title>
22
+ <acl>config/list</acl>
23
+ </list>
24
+ </shiptheory>
25
+ </resources>
26
+ </acl>
27
+ </api>
28
+ </config>
app/code/local/Shiptheory/Shippinglabels/etc/config.xml ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Shiptheory_Shippinglabels>
5
+ <version>0.0.1</version>
6
+ </Shiptheory_Shippinglabels>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <shippinglabels>
11
+ <class>Shiptheory_Shippinglabels_Model</class>
12
+ <resourceModel>shippinglabels_mysql4</resourceModel>
13
+ </shippinglabels>
14
+ <shippinglabels_mysql4>
15
+ <class>Shiptheory_Shippinglabels_Model_Mysql4</class>
16
+ </shippinglabels_mysql4>
17
+ <shippinglabels_mysql4>
18
+ <class>Shiptheory_Shippinglabels_Model_Mysql4</class>
19
+ <entities>
20
+ <history>
21
+ <table>shippinglabels_history</table>
22
+ </history>
23
+ </entities>
24
+ </shippinglabels_mysql4>
25
+ </models>
26
+ <helpers>
27
+ <shippinglabels>
28
+ <class>Shiptheory_Shippinglabels_Helper</class>
29
+ </shippinglabels>
30
+ </helpers>
31
+ <blocks>
32
+ <shippinglabels>
33
+ <class>Shiptheory_Shippinglabels_Block</class>
34
+ </shippinglabels>
35
+ </blocks>
36
+ <events>
37
+ <admin_system_config_changed_section_shippinglabels>
38
+ <observers>
39
+ <shippinglabels_config_observer>
40
+ <class>shippinglabels/config_observer</class>
41
+ <method>configure</method>
42
+ </shippinglabels_config_observer>
43
+ </observers>
44
+ </admin_system_config_changed_section_shippinglabels>
45
+ <sales_order_shipment_save_after>
46
+ <observers>
47
+ <shippinglabels_sales_shipment_observer>
48
+ <class>shippinglabels/order_observer</class>
49
+ <method>shipment</method>
50
+ </shippinglabels_sales_shipment_observer>
51
+ </observers>
52
+ </sales_order_shipment_save_after>
53
+ </events>
54
+ <resources>
55
+ <shippinglabels_setup>
56
+ <setup>
57
+ <module>Shiptheory_Shippinglabels</module>
58
+ </setup>
59
+ <connection>
60
+ <use>core_setup</use>
61
+ </connection>
62
+ </shippinglabels_setup>
63
+ <shippinglabels_write>
64
+ <connection>
65
+ <use>core_write</use>
66
+ </connection>
67
+ </shippinglabels_write>
68
+ <shippinglabels_read>
69
+ <connection>
70
+ <use>core_read</use>
71
+ </connection>
72
+ </shippinglabels_read>
73
+ </resources>
74
+ </global>
75
+ <admin>
76
+ <routers>
77
+ <shippinglabels>
78
+ <use>admin</use>
79
+ <args>
80
+ <module>Shiptheory_Shippinglabels</module>
81
+ <frontName>shippinglabels</frontName>
82
+ </args>
83
+ </shippinglabels>
84
+ </routers>
85
+ </admin>
86
+ <adminhtml>
87
+ <events>
88
+ <core_block_abstract_prepare_layout_before>
89
+ <observers>
90
+ <shippinglabels_core_block_abstract_prepare_layout_before>
91
+ <class>shippinglabels/observer</class>
92
+ <method>addShippingAction</method>
93
+ </shippinglabels_core_block_abstract_prepare_layout_before>
94
+ </observers>
95
+ </core_block_abstract_prepare_layout_before>
96
+ </events>
97
+ <layout>
98
+ <updates>
99
+ <shiptheory>
100
+ <file>shiptheory.xml</file>
101
+ </shiptheory>
102
+ </updates>
103
+ </layout>
104
+ <menu>
105
+ <sales>
106
+ <children>
107
+ <shippinglabels translate="title" module="shippinglabels">
108
+ <title>Shiptheory Messages</title>
109
+ <sort_order>15</sort_order>
110
+ <action>shippinglabels/adminhtml_shippinglabels</action>
111
+ </shippinglabels>
112
+ </children>
113
+ </sales>
114
+ </menu>
115
+ <acl>
116
+ <resources>
117
+ <admin>
118
+ <children>
119
+ <sales>
120
+ <children>
121
+ <shippinglabels translate="title" module="shippinglabels">
122
+ <title>Shiptheory Messages</title>
123
+ <sort_order>15</sort_order>
124
+ <action>shippinglabels/adminhtml_shippinglabels</action>
125
+ </shippinglabels>
126
+ </children>
127
+ </sales>
128
+ <system>
129
+ <children>
130
+ <config>
131
+ <children>
132
+ <shippinglabels translate="title" module="shippinglabels">
133
+ <title>Shiptheory Setup</title>
134
+ <sort_order>20</sort_order>
135
+ </shippinglabels>
136
+ </children>
137
+ </config>
138
+ </children>
139
+ </system>
140
+ </children>
141
+ </admin>
142
+ </resources>
143
+ </acl>
144
+ </adminhtml>
145
+ <default>
146
+ <shippinglabels>
147
+ <misc>
148
+ <apikey>--- Obtain from Shiptheory.com ---</apikey>
149
+ </misc>
150
+ <default>
151
+ <status></status>
152
+ <retrylimit>50</retrylimit>
153
+ <apiname>Shiptheory</apiname>
154
+ <apiemail>support@shiptheory.com</apiemail>
155
+ <apiusername>shiptheory</apiusername>
156
+ <apiuserid>0</apiuserid>
157
+ </default>
158
+ <endpoint>
159
+ <order>http://quark.madcapsule.com/shiptheory.py</order>
160
+ <setup>https://shiptheory.com/magento/setup</setup>
161
+ </endpoint>
162
+ </shippinglabels>
163
+ </default>
164
+ </config>
app/code/local/Shiptheory/Shippinglabels/etc/system.xml ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <shiptheory translate="label" module="shippinglabels">
5
+ <label>Shiptheory</label>
6
+ <sort_order>600</sort_order>
7
+ </shiptheory>
8
+ </tabs>
9
+ <sections>
10
+ <shippinglabels translate="label" module="shippinglabels">
11
+ <label>Setup</label>
12
+ <tab>shiptheory</tab>
13
+ <!--<class>shiptheory-section</class>-->
14
+ <frontend_type>text</frontend_type>
15
+ <sort_order>1</sort_order>
16
+ <show_in_default>1</show_in_default>
17
+ <show_in_website>1</show_in_website>
18
+ <show_in_store>1</show_in_store>
19
+ <groups>
20
+ <hint>
21
+ <frontend_model>shippinglabels/adminhtml_system_config_fieldset_hint</frontend_model>
22
+ <sort_order>0</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>1</show_in_store>
26
+ </hint>
27
+ <misc translate="label">
28
+ <label>Shiptheory Setup</label>
29
+ <frontend_type>text</frontend_type>
30
+ <sort_order>1</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
+ <fields>
35
+ <new translate="label">
36
+ <label>New to Shiptheory?</label>
37
+ <frontend_type>button</frontend_type>
38
+ <frontend_model>shippinglabels/button_new</frontend_model>
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
+ <depends><apikey>--- Obtain from Shiptheory.com ---</apikey></depends>
44
+ </new>
45
+ <enabled translate="label">
46
+ <label>Enabled</label>
47
+ <frontend_type>select</frontend_type>
48
+ <source_model>adminhtml/system_config_source_yesno</source_model>
49
+ <sort_order>2</sort_order>
50
+ <show_in_default>1</show_in_default>
51
+ <show_in_website>1</show_in_website>
52
+ <show_in_store>1</show_in_store>
53
+ </enabled>
54
+ <apikey translate="label">
55
+ <label>API Key</label>
56
+ <frontend_type>text</frontend_type>
57
+ <sort_order>3</sort_order>
58
+ <show_in_default>1</show_in_default>
59
+ <show_in_website>1</show_in_website>
60
+ <show_in_store>1</show_in_store>
61
+ <depends><enabled>1</enabled></depends>
62
+ <comment><![CDATA[You can get this from your Shiptheory account <a href="https://shiptheory.com/magento/edit" target="_blank">here</a>]]></comment>
63
+ </apikey>
64
+ <!--<trigger translate="label">
65
+ <label>When should labels be created?</label>
66
+ <frontend_type>select</frontend_type>
67
+ <source_model>Shiptheory_Shippinglabels_Triggers</source_model>
68
+ <sort_order>4</sort_order>
69
+ <show_in_default>1</show_in_default>
70
+ <show_in_website>1</show_in_website>
71
+ <show_in_store>1</show_in_store>
72
+ <depends><enabled>1</enabled></depends>
73
+ </trigger>-->
74
+ </fields>
75
+ </misc>
76
+ <advanced translate="label">
77
+ <label>Advanced</label>
78
+ <frontend_type>text</frontend_type>
79
+ <sort_order>2</sort_order>
80
+ <show_in_default>1</show_in_default>
81
+ <show_in_website>1</show_in_website>
82
+ <show_in_store>1</show_in_store>
83
+ <fields>
84
+ <version translate="label">
85
+ <label>Version</label>
86
+ <frontend_type>select</frontend_type>
87
+ <frontend_model>Shiptheory_Shippinglabels_Block_Adminhtml_Version</frontend_model>
88
+ <sort_order>0</sort_order>
89
+ <show_in_default>1</show_in_default>
90
+ <show_in_website>1</show_in_website>
91
+ <show_in_store>1</show_in_store>
92
+ </version>
93
+ <log translate="label">
94
+ <label>Enable Logs</label>
95
+ <frontend_type>select</frontend_type>
96
+ <source_model>adminhtml/system_config_source_yesno</source_model>
97
+ <sort_order>1</sort_order>
98
+ <show_in_default>1</show_in_default>
99
+ <show_in_website>1</show_in_website>
100
+ <show_in_store>1</show_in_store>
101
+ </log>
102
+ </fields>
103
+ </advanced>
104
+ </groups>
105
+ </shippinglabels>
106
+ </sections>
107
+ </config>
app/code/local/Shiptheory/Shippinglabels/sql/shippinglabels_setup/mysql4-install-0.0.1.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @category Shiptheory
4
+ * @package Shiptheory_Shippinglabels
5
+ */
6
+ $installer = $this;
7
+
8
+ $installer->startSetup();
9
+
10
+ $installer->run("
11
+
12
+ -- DROP TABLE IF EXISTS {$this->getTable('shippinglabels/history')};
13
+ CREATE TABLE {$this->getTable('shippinglabels/history')} (
14
+ `id` int(11) NOT NULL auto_increment,
15
+ `internal_id` int(11) default NULL,
16
+ `reference` varchar(60) default NULL,
17
+ `message` varchar(200) default NULL,
18
+ `attempts` tinyint(3) default '0',
19
+ `created` timestamp NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
20
+ `status` varchar(12) default 'processing',
21
+ PRIMARY KEY (`id`)
22
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
23
+ ");
24
+
25
+ $installer->endSetup();
app/design/adminhtml/base/default/layout/shiptheory.xml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <adminhtml_system_config_edit>
4
+ <reference name="head">
5
+ <action method="addItem">
6
+ <type>skin_css</type>
7
+ <name>shiptheory/css/shiptheory.css</name>
8
+ </action>
9
+ </reference>
10
+ </adminhtml_system_config_edit>
11
+ </layout>
app/design/adminhtml/base/default/template/shiptheory/system/config/fieldset/dpd.phtml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div>
2
+ <img width="180" height="53" src="https://trello-attachments.s3.amazonaws.com/553fd41703690c3652c38f3f/180x53/ef9a829a6a65dbd662595c2bff168735/logo.png" />
3
+ <br /><br />
4
+ <?php if($this->isSetup()){ ?>
5
+ <h4>
6
+ You are all set!
7
+ </h4>
8
+ <p><br />
9
+ <ul>
10
+ <li>
11
+ 1. New orders are automatically pulled into your Shiptheory.com account
12
+ </li>
13
+ <li>
14
+ 2. Any tracking numbers are returned to Magento and the order is marked <b>Shipped</b> if not already Shipped
15
+ </li>
16
+ <li>
17
+ 3. Your <b>DPD labels</b> are ready and waiting for you to print via <a href="https://shiptheory.com">Shiptheory.com</a>
18
+ </li>
19
+ </ul>
20
+ </p>
21
+ <?php }else{ ?>
22
+ <div id="messages">
23
+ <ul class="messages">
24
+ <li class="error-msg">
25
+ <ul>
26
+ <li><span><?php echo $this->__('You need to <b>enable</a> and configure from the Setup section');?></span></li>
27
+ </ul>
28
+ </li>
29
+ </ul>
30
+ </div>
31
+ <?php } ?>
32
+ <p>
33
+ <br />Need some help? Read our <a href="http://support.shiptheory.com/solution/articles/6000004521-getting-started-with-magento-and-your-carrier" target="_blank">getting started guide</a>
34
+ </p>
35
+ <br />
36
+ </div>
app/design/adminhtml/base/default/template/shiptheory/system/config/fieldset/hint.phtml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <div>
2
+ <img width="180" height="53" src="https://trello-attachments.s3.amazonaws.com/553fd41703690c3652c38f3f/180x53/ef9a829a6a65dbd662595c2bff168735/logo.png" />
3
+ <br /><br />
4
+ <h4>
5
+ Shiptheory. Making Ship Simple.
6
+ </h4>
7
+ <p>
8
+ Need help using the Shiptheory extension? Read our <a href="http://support.shiptheory.com/solution/articles/6000004521-getting-started-with-magento-and-your-carrier" target="_blank">getting started guide</a>
9
+ </p>
10
+ <br />
11
+ </div>
app/etc/modules/Shiptheory_Dpd.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <Shiptheory_Dpd>
4
+ <active>true</active>
5
+ <codePool>local</codePool>
6
+ </Shiptheory_Dpd>
7
+ </modules>
8
+ </config>
app/etc/modules/Shiptheory_Shippinglabels.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <Shiptheory_Shippinglabels>
4
+ <active>true</active>
5
+ <codePool>local</codePool>
6
+ </Shiptheory_Shippinglabels>
7
+ </modules>
8
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Shiptheory_Dpd</name>
4
+ <version>0.0.1</version>
5
+ <stability>stable</stability>
6
+ <license>Commercial</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>DPD Label API Integration from Shiptheory</summary>
10
+ <description>Automatically print DPD labels over the API via Shiptheory</description>
11
+ <notes>First public release</notes>
12
+ <authors><author><name>Shiptheory</name><user>Shiptheory</user><email>jm@shiptheory.com</email></author></authors>
13
+ <date>2015-06-03</date>
14
+ <time>11:44:55</time>
15
+ <contents><target name="magelocal"><dir name="Shiptheory"><dir name="Shippinglabels"><dir name="Block"><dir name="Adminhtml"><dir name="Shippinglabels"><file name="Grid.php" hash="1099b2faa55eda067bb15ecfb80413a7"/></dir><file name="Shippinglabels.php" hash="05b1c45a36c12d3187fef98ae2d9c3b2"/><dir name="System"><dir name="Config"><dir name="Fieldset"><file name="Hint.php" hash="024b80c408fd77ab1812d704c10d0d4d"/></dir></dir></dir><file name="Version.php" hash="618012aaf852cd46916d4fdd84693565"/></dir><dir name="Button"><file name="New.php" hash="953ee6083efc34652fa5d94c1ca50d45"/></dir></dir><dir name="Helper"><file name="Data.php" hash="f4d82e348cc5e3b7e91982adc7a0b8f8"/></dir><dir name="Model"><dir name="Config"><file name="Api.php" hash="c7de3c569a76254325a6b05573bd83f3"/><file name="Observer.php" hash="141afba8743c87683801c7a6af03d45d"/></dir><file name="Config.php" hash="58b24c47648ece1ddf1acc1af317295b"/><dir name="History"><file name="Observer.php" hash="592bd633a817b761d1bbcfee9b7968bb"/></dir><file name="History.php" hash="62959bc10994b928255649bc4635abf9"/><dir name="Mysql4"><dir name="History"><file name="Collection.php" hash="8a747d6252f8931306471e33437b4f54"/></dir><file name="History.php" hash="bc875bf7269a0cee5ecddd1624c26346"/></dir><file name="Observer.php" hash="8b6733b5b435c4b6a52c96df7893ce22"/><dir name="Order"><file name="Observer.php" hash="4f44081b2359a4dd5f3cc25d9eec55bc"/></dir><file name="Order.php" hash="ca8bc351613977f43ad456070b2d8e10"/><file name="Version.php" hash="49415c1410ee2b5092e9c40f03b2e376"/><file name="Webservice.php" hash="ce6de35d30c4c95ba35d0e39f499e963"/></dir><file name="Triggers.php" hash="7f4d01e26f881bfaa8953a412a44271c"/><dir name="controllers"><dir name="Adminhtml"><file name="ShippinglabelsController.php" hash="bbabef05a15187bcdc2ff6c9d3f346ce"/></dir></dir><dir name="etc"><file name="api.xml" hash="2fb258d64df452f4f4a6426c4bec6e97"/><file name="config.xml" hash="73f06f6146bc9cdf5db3a175635b8c76"/><file name="system.xml" hash="ec9996a06e69215bb6b8f1ba0c5d4029"/></dir><dir name="sql"><dir name="shippinglabels_setup"><file name="mysql4-install-0.0.1.php" hash="1c8c491e7fb45b51d2251f109102dfaf"/></dir></dir></dir><dir name="Dpd"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Fieldset"><file name="Hint.php" hash="6c0994a60132b6328e1095ee6455300e"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="86337174946b2bc7b4504ccad79b3402"/></dir><dir name="etc"><file name="config.xml" hash="558eb21d131ebe76af26313efb3d1bba"/><file name="system.xml" hash="ecdd2ce0cc932cf62b5e1f4259e071ae"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Shiptheory_Shippinglabels.xml" hash="0b912d0fab3b1c2b87a687fa5ba064e2"/><file name="Shiptheory_Dpd.xml" hash="fd2be5b85b0af7a8054aab162e1ab59f"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="shiptheory"><dir name="css"><file name="shiptheory.css" hash="7bd374d2212a6ab7eaf400705999378f"/></dir><dir name="images"><file name="shiptheory-section.png" hash="42f15b05c3667db74104f4dc73af2392"/><file name="shiptheory.png" hash="42f15b05c3667db74104f4dc73af2392"/></dir></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="base"><dir name="default"><dir name="layout"><file name="shiptheory.xml" hash="f9c980e4c2b9f95dbee962831b9dd52e"/></dir><dir name="template"><dir name="shiptheory"><dir name="system"><dir name="config"><dir name="fieldset"><file name="dpd.phtml" hash="20902c5896e79fc8cbbe088a63ba2820"/><file name="hint.phtml" hash="398365cf3943f32446dbda1fbd150c3d"/></dir></dir></dir></dir></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>
skin/adminhtml/default/default/shiptheory/css/shiptheory.css ADDED
@@ -0,0 +1 @@
 
1
+ ul.tabs a.shiptheory-section span,ul.tabs a.shiptheory-section:hover span{background:url("../images/shiptheory-section.png") no-repeat scroll 0 0 transparent;height:0;overflow:hidden;padding:15px 0 4px 0;width:110px}ul.tabs a.shiptheory-section,ul.tabs a.shiptheory-section:hover{background:url("../../images/tabs_span_bg.gif") repeat-x scroll 0 100% transparent;border-bottom:medium none;padding:.5em .5em .28em 1.5em}h3.shiptheory-header{background:url("../images/shiptheory-section.png") no-repeat scroll 0 0 transparent;height:0;overflow:hidden;padding:19px 0 0 169px;width:350px;height:70px;}ul.tabs a.shiptheory-section:hover{background-color:#d8e6e6}ul.tabs a.shiptheory-section.active,ul.tabs a.shiptheory-section.active:hover{background-color:#FFF}
skin/adminhtml/default/default/shiptheory/images/shiptheory-section.png ADDED
Binary file
skin/adminhtml/default/default/shiptheory/images/shiptheory.png ADDED
Binary file