PutlerConnector - Version 1.0.0

Version Notes

This is an initial version of a Magento Putler Connector which will send Magento orders data to Putler and you will get insightful statistics about your store and business

Download this release

Release Info

Developer Nirav Mehta
Extension PutlerConnector
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (65) hide show
  1. code/.DS_Store +0 -0
  2. code/._.DS_Store +0 -0
  3. code/local/.DS_Store +0 -0
  4. code/local/._.DS_Store +0 -0
  5. code/local/._Putler +0 -0
  6. code/local/Putler/.DS_Store +0 -0
  7. code/local/Putler/._.DS_Store +0 -0
  8. code/local/Putler/._PutlerConnector +0 -0
  9. code/local/Putler/PutlerConnector/.DS_Store +0 -0
  10. code/local/Putler/PutlerConnector/._.DS_Store +0 -0
  11. code/local/Putler/PutlerConnector/._Block +0 -0
  12. code/local/Putler/PutlerConnector/._Helper +0 -0
  13. code/local/Putler/PutlerConnector/._Model +0 -0
  14. code/local/Putler/PutlerConnector/._controllers +0 -0
  15. code/local/Putler/PutlerConnector/._etc +0 -0
  16. code/local/Putler/PutlerConnector/._scripts +0 -0
  17. code/local/Putler/PutlerConnector/._sql +0 -0
  18. code/local/Putler/PutlerConnector/Block/.DS_Store +0 -0
  19. code/local/Putler/PutlerConnector/Block/._.DS_Store +0 -0
  20. code/local/Putler/PutlerConnector/Block/Adminhtml/.DS_Store +0 -0
  21. code/local/Putler/PutlerConnector/Block/Adminhtml/System/.DS_Store +0 -0
  22. code/local/Putler/PutlerConnector/Block/Adminhtml/System/Config/.DS_Store +0 -0
  23. code/local/Putler/PutlerConnector/Block/Adminhtml/System/Config/Form/Button.php +70 -0
  24. code/local/Putler/PutlerConnector/Helper/.DS_Store +0 -0
  25. code/local/Putler/PutlerConnector/Helper/._.DS_Store +0 -0
  26. code/local/Putler/PutlerConnector/Model/.DS_Store +0 -0
  27. code/local/Putler/PutlerConnector/Model/._.DS_Store +0 -0
  28. code/local/Putler/PutlerConnector/Model/Observer.php +40 -0
  29. code/local/Putler/PutlerConnector/Model/PutlerConnector.php +312 -0
  30. code/local/Putler/PutlerConnector/controllers/.DS_Store +0 -0
  31. code/local/Putler/PutlerConnector/controllers/._.DS_Store +0 -0
  32. code/local/Putler/PutlerConnector/controllers/._Adminhtml +0 -0
  33. code/local/Putler/PutlerConnector/controllers/Adminhtml/.DS_Store +0 -0
  34. code/local/Putler/PutlerConnector/controllers/Adminhtml/._.DS_Store +0 -0
  35. code/local/Putler/PutlerConnector/controllers/Adminhtml/PutlerConnectorController.php +55 -0
  36. code/local/Putler/PutlerConnector/etc/.DS_Store +0 -0
  37. code/local/Putler/PutlerConnector/etc/._.DS_Store +0 -0
  38. code/local/Putler/PutlerConnector/etc/._config.xml +0 -0
  39. code/local/Putler/PutlerConnector/etc/adminhtml.xml +23 -0
  40. code/local/Putler/PutlerConnector/etc/config.xml +43 -0
  41. code/local/Putler/PutlerConnector/etc/system.xml +59 -0
  42. code/local/Putler/PutlerConnector/scripts/.DS_Store +0 -0
  43. code/local/Putler/PutlerConnector/scripts/._.DS_Store +0 -0
  44. code/local/Putler/PutlerConnector/sql/.DS_Store +0 -0
  45. code/local/Putler/PutlerConnector/sql/._.DS_Store +0 -0
  46. design/.DS_Store +0 -0
  47. design/._.DS_Store +0 -0
  48. design/adminhtml/.DS_Store +0 -0
  49. design/adminhtml/._.DS_Store +0 -0
  50. design/adminhtml/default/.DS_Store +0 -0
  51. design/adminhtml/default/._.DS_Store +0 -0
  52. design/adminhtml/default/default/.DS_Store +0 -0
  53. design/adminhtml/default/default/._.DS_Store +0 -0
  54. design/adminhtml/default/default/template/.DS_Store +0 -0
  55. design/adminhtml/default/default/template/._.DS_Store +0 -0
  56. design/adminhtml/default/default/template/putler_putlerconnector/.DS_Store +0 -0
  57. design/adminhtml/default/default/template/putler_putlerconnector/system/.DS_Store +0 -0
  58. design/adminhtml/default/default/template/putler_putlerconnector/system/config/button.phtml +45 -0
  59. etc/.DS_Store +0 -0
  60. etc/._.DS_Store +0 -0
  61. etc/modules/.DS_Store +0 -0
  62. etc/modules/._.DS_Store +0 -0
  63. etc/modules/._Putler_PutlerConnector.xml +0 -0
  64. etc/modules/Putler_PutlerConnector.xml +10 -0
  65. package.xml +48 -0
code/.DS_Store ADDED
Binary file
code/._.DS_Store ADDED
Binary file
code/local/.DS_Store ADDED
Binary file
code/local/._.DS_Store ADDED
Binary file
code/local/._Putler ADDED
Binary file
code/local/Putler/.DS_Store ADDED
Binary file
code/local/Putler/._.DS_Store ADDED
Binary file
code/local/Putler/._PutlerConnector ADDED
Binary file
code/local/Putler/PutlerConnector/.DS_Store ADDED
Binary file
code/local/Putler/PutlerConnector/._.DS_Store ADDED
Binary file
code/local/Putler/PutlerConnector/._Block ADDED
Binary file
code/local/Putler/PutlerConnector/._Helper ADDED
Binary file
code/local/Putler/PutlerConnector/._Model ADDED
Binary file
code/local/Putler/PutlerConnector/._controllers ADDED
Binary file
code/local/Putler/PutlerConnector/._etc ADDED
Binary file
code/local/Putler/PutlerConnector/._scripts ADDED
Binary file
code/local/Putler/PutlerConnector/._sql ADDED
Binary file
code/local/Putler/PutlerConnector/Block/.DS_Store ADDED
Binary file
code/local/Putler/PutlerConnector/Block/._.DS_Store ADDED
Binary file
code/local/Putler/PutlerConnector/Block/Adminhtml/.DS_Store ADDED
Binary file
code/local/Putler/PutlerConnector/Block/Adminhtml/System/.DS_Store ADDED
Binary file
code/local/Putler/PutlerConnector/Block/Adminhtml/System/Config/.DS_Store ADDED
Binary file
code/local/Putler/PutlerConnector/Block/Adminhtml/System/Config/Form/Button.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Atwix
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+
15
+ * @category Atwix Mod
16
+ * @package Atwix_Tweaks
17
+ * @author Atwix Core Team
18
+ * @copyright Copyright (c) 2012 Atwix (http://www.atwix.com)
19
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
+ */
21
+
22
+ class Putler_PutlerConnector_Block_Adminhtml_System_Config_Form_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
23
+ {
24
+ /*
25
+ * Set template
26
+ */
27
+ protected function _construct()
28
+ {
29
+ parent::_construct();
30
+ $this->setTemplate('Putler_putlerconnector/system/config/button.phtml');
31
+ }
32
+
33
+ /**
34
+ * Return element html
35
+ *
36
+ * @param Varien_Data_Form_Element_Abstract $element
37
+ * @return string
38
+ */
39
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
40
+ {
41
+ return $this->_toHtml();
42
+ }
43
+
44
+ /**
45
+ * Return ajax url for button
46
+ *
47
+ * @return string
48
+ */
49
+ public function getAjaxCheckUrl()
50
+ {
51
+ return Mage::helper('adminhtml')->getUrl('adminhtml/adminhtml_putlerconnector/check');
52
+ }
53
+
54
+ /**
55
+ * Generate button html
56
+ *
57
+ * @return string
58
+ */
59
+ public function getButtonHtml()
60
+ {
61
+
62
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
63
+ 'id' => 'putler_validate_button',
64
+ 'label' => $this->helper('adminhtml')->__('Save & Send Past Orders to Putler'),
65
+ 'onclick' => 'javascript:check(); return false;'
66
+ ));
67
+
68
+ return $button->toHtml();
69
+ }
70
+ }
code/local/Putler/PutlerConnector/Helper/.DS_Store ADDED
Binary file
code/local/Putler/PutlerConnector/Helper/._.DS_Store ADDED
Binary file
code/local/Putler/PutlerConnector/Model/.DS_Store ADDED
Binary file
code/local/Putler/PutlerConnector/Model/._.DS_Store ADDED
Binary file
code/local/Putler/PutlerConnector/Model/Observer.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Putler_PutlerConnector_Model_Observer {
5
+
6
+ /**
7
+ * Subscribw the user, during checkout.
8
+ *
9
+ * @return void
10
+ */
11
+ public function postOrderDataToPutler($observer)
12
+ {
13
+
14
+ $order = $observer->getOrder();
15
+ if($order->getState() == Mage_Sales_Model_Order::STATE_COMPLETE){
16
+
17
+ $email = Mage::getStoreConfig('putlersettings/general/putler_email');
18
+ $api_token = Mage::getStoreConfig('putlersettings/general/putler_api_token');
19
+
20
+ if($email != '' && $api_token != '') {
21
+ $putler_connector = Mage::getModel ( 'putler_putlerconnector/PutlerConnector');
22
+ $result = $putler_connector->validateApiInfo ($email, $api_token);
23
+ if ($result) {
24
+
25
+ $order = $observer->getEvent ()->getOrder ();
26
+ $orders_data = $putler_connector->preapreOrdersTosend ( array($order) );
27
+ $result = $putler_connector->postOrdersToPutler ( $orders_data );
28
+ if ($result) {
29
+ Mage::log( 'Data have been sent successfully to putler' );
30
+ }
31
+ } else {
32
+ Mage::log( 'Error while sending data to putler' );
33
+ }
34
+ } else {
35
+ Mage::log( 'Putler email and api token are blank' );
36
+ }
37
+ }
38
+ }
39
+
40
+ }
code/local/Putler/PutlerConnector/Model/PutlerConnector.php ADDED
@@ -0,0 +1,312 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Putler_PutlerConnector_Model_PutlerConnector {
4
+
5
+ var $api_url = 'http://api.putler.com/inbound/';
6
+ var $email_address = '';
7
+ var $api_token = '';
8
+
9
+ var $text_domain = 'putler_connector';
10
+
11
+ var $version = 1.0;
12
+ private $name = 'magento';
13
+
14
+ function __construct() {
15
+
16
+ }
17
+ function validateApiInfo($email, $token) {
18
+ // Validate with API server
19
+
20
+ $this->api_token = $token;
21
+ $this->email_address = $email;
22
+ $post_data = array ('action' => 'validate', 'headers' => array ('Authorization' => 'Basic ' . base64_encode ( $email . ':' . $token ), 'User-Agent' => 'Putler Connector/' . $this->version ) );
23
+ $result = $this->makeRequest ( $post_data );
24
+
25
+ if ($result ['ACK'] == 'Success') {
26
+ return true;
27
+ }
28
+
29
+ //TODO: Check errors if any
30
+ return false;
31
+ }
32
+
33
+ function postOrdersToPutler($orders) {
34
+
35
+
36
+ if (empty ( $orders )) {
37
+ return true;
38
+ }
39
+
40
+ $oid = ob_start ();
41
+ $fp = fopen ( 'php://output', 'a+' );
42
+ foreach ( ( array ) $orders as $index => $row ) {
43
+ if ($index == 0) {
44
+ fputcsv ( $fp, array_keys ( $row ) );
45
+ }
46
+ fputcsv ( $fp, $row );
47
+ }
48
+ fclose ( $fp );
49
+ $csv_data = ob_get_clean ();
50
+ if (ob_get_clean () > 0) {
51
+ ob_end_clean ();
52
+ }
53
+
54
+
55
+ $post_data = array ('headers' => array ('Content-Type' => 'text/csv', 'Authorization' => 'Basic ' . base64_encode ( $this->email_address . ':' . $this->api_token ), 'User-Agent' => 'Putler Connector/' . $this->version ), 'timeout' => 120, 'body' => $csv_data );
56
+
57
+ $result = $this->makeRequest ( $post_data, true );
58
+
59
+ //TODO: Check if result contains error
60
+ $server_response_default = array ('ACK' => 'Failure', 'MESSAGE' => 'Unknown Response', $this->text_domain );
61
+ $server_response = $result;
62
+ $server_response = array_merge ( $server_response_default, $server_response );
63
+
64
+ if ($server_response ['ACK'] == "Success") {
65
+ return true;
66
+ }
67
+
68
+ return false;
69
+
70
+ //TODO: Throw an error if any
71
+ }
72
+
73
+ function makeRequest($post_data, $raw_data = false) {
74
+ /* Prepare a data to send on klawoo */
75
+
76
+
77
+ $client = new Zend_Http_Client ( $this->api_url );
78
+ if (isset ( $post_data ['headers'] )) {
79
+ $headers = $post_data ['headers'];
80
+ $client->setHeaders ( $headers );
81
+ }
82
+
83
+ $data = array();
84
+ if (isset ( $post_data ['body'] )) {
85
+ $data = $post_data ['body'];
86
+ }
87
+
88
+ if($raw_data) {
89
+ $client->setRawData($data);
90
+ } else {
91
+ $client->setParameterPost ( $data );
92
+ $client->setParameterPost ( 'action', $post_data ['action'] );
93
+ }
94
+
95
+
96
+ $result = $client->request ( Zend_Http_Client::POST );
97
+ $response = json_decode ( $result->getBody (), true );
98
+
99
+ return $response;
100
+ }
101
+
102
+ function getOrders() {
103
+ // Note: Only fetch Completed Orders for now. Other Statuses
104
+ $orders = Mage::getModel ( 'sales/order' )->getCollection ()->addAttributeToSelect ( "*" )->addAttributeToFilter ( 'status', array ('complete') );
105
+ $orders_data = $this->preapreOrdersTosend ( $orders );
106
+ return $orders_data;
107
+ }
108
+
109
+ function preapreOrdersTosend($orders) {
110
+
111
+ foreach ( $orders as $order ) {
112
+ //$order = Mage::getModel ( 'sales/order' );
113
+
114
+ $order_id = $order->getId();
115
+ $order_total = round ( $order->getSubtotal(), 2 );
116
+
117
+ $dateInGMT = date ( 'm/d/Y', ( int ) $order->getCreatedAtStoreDate()->getTimestamp() );
118
+ $timeInGMT = date ( 'h:i:s A', ( int ) $order->getCreatedAtStoreDate()->getTimestamp() );
119
+
120
+
121
+ $order_status = $order->getStatus();
122
+ if(in_array($order_status, array('on-hold', 'pending', 'failed'))) {
123
+ $order_status_display = 'Pending';
124
+ } else if (in_array($order_status, array('complete', 'processing', 'refunded'))) {
125
+ $order_status_display = 'Completed';
126
+ } else if ($order_status == "cancelled") {
127
+ $order_status_display = 'Cancelled';
128
+ }
129
+
130
+ $response ['Date'] = $dateInGMT;
131
+ $response ['Time'] = $timeInGMT;
132
+ $response ['Time_Zone'] = 'GMT';
133
+
134
+ $billing_name = $order->getCustomerFirstname() . ' ' . $order->getCustomerLastname();
135
+ $response ['Source'] = $this->name;
136
+ $response ['Name'] = $billing_name;
137
+ $response ['Type'] = 'Shopping Cart Payment Received';
138
+
139
+ $response ['Status'] = ucfirst ( $order_status_display );
140
+
141
+ $order_curency = $order->getOrderCurrencyCode();
142
+ $response ['Currency'] = $order_curency;
143
+
144
+ $shipping_amount = round ($order->getShippingAmount(), 2);
145
+ $response ['Gross'] = $order->getSubtotal() + $shipping_amount;
146
+ $response ['Fee'] = 0.00;
147
+ $response ['Net'] = $order->getSubtotal() + $shipping_amount;
148
+
149
+ $response ['From_Email_Address'] = $order->getCustomerEmail();
150
+ $response ['To_Email_Address'] = '';
151
+ $response ['Transaction_ID'] = $order_id;
152
+ $response ['Counterparty_Status'] = '';
153
+ $response ['Address_Status'] = '';
154
+ $response ['Item_Title'] = 'Shopping Cart';
155
+ $response ['Item_ID'] = 0; // Set to 0 for main Order Transaction row
156
+ $response ['Shipping_and_Handling_Amount'] = ($shipping_amount > 0) ? $shipping_amount : 0.00;
157
+ $response ['Insurance_Amount'] = '';
158
+
159
+ $discount_amount = $order->getBaseDiscountAmount();
160
+ $response ['Discount'] = ( $discount_amount > 0 ) ? round ( $discount_amount, 2 ) : 0.00;
161
+
162
+ $order_tax = $order->getBaseShippingTaxAmount();
163
+ $response ['Sales_Tax'] = ( $order_tax > 0) ? round ($order_tax, 2 ) : 0.00;
164
+
165
+ $response ['Option_1_Name'] = '';
166
+ $response ['Option_1_Value'] = '';
167
+ $response ['Option_2_Name'] = '';
168
+ $response ['Option_2_Value'] = '';
169
+
170
+ $response ['Auction_Site'] = '';
171
+ $response ['Buyer_ID'] = '';
172
+ $response ['Item_URL'] = '';
173
+ $response ['Closing_Date'] = '';
174
+ $response ['Escrow_ID'] = '';
175
+ $response ['Invoice_ID'] = '';
176
+ $response ['Reference_Txn_ID'] = '';
177
+ $response ['Invoice_Number'] = '';
178
+ $response ['Custom_Number'] = '';
179
+
180
+
181
+ $response ['Quantity'] = (int) $order->getTotalQtyOrdered();
182
+ $response ['Receipt_ID'] = '';
183
+
184
+ $response ['Balance'] = '';
185
+ $response ['Note'] = $order->getCustomerNote();
186
+
187
+ $address_info = $this->getOrderShippingInfo($order);
188
+
189
+ $response ['Address_Line_1'] = $address_info['Address_Line_1'];
190
+ $response ['Address_Line_2'] = $address_info['Address_Line_2'];
191
+ $response ['Town_City'] = $address_info['Town_City'];
192
+ $response ['State_Province'] = $address_info['State_Province'];
193
+ $response ['Zip_Postal_Code'] = $address_info['Zip_Postal_Code'];
194
+ $response ['Country'] = $address_info['Country'];
195
+ $response ['Contact_Phone_Number'] = $address_info['Contact_Phone_Number'];
196
+ $response ['Subscription_ID'] = '';
197
+
198
+ $transactions [] = $response;
199
+ $parent_ids = array();
200
+
201
+ foreach($order->getItemsCollection() as $item) {
202
+
203
+ $item_data = $item->getData();
204
+
205
+ if($item_data['parent_item_id'] != '' && !isset($item_data['has_children'])) {
206
+ continue;
207
+ }
208
+
209
+
210
+ $product_options = unserialize($item_data['product_options']);
211
+
212
+ $order_item = array ();
213
+ $order_item ['Type'] = 'Shopping Cart Item';
214
+
215
+ $order_item ['Item_Title'] = $item_data['name'];
216
+ $order_item ['Item_ID'] = $item_data['sku'];
217
+
218
+ $order_item ['Gross'] = round ( $item_data['row_total'], 2 );
219
+ $order_item['Quantity'] = $item_data['qty_ordered'];
220
+ // / $order_item['Net'] = $item_data['row_total'];
221
+
222
+ //TODO: Handle Variations
223
+ if(isset($product_options['attributes_info']) && count($product_options['attributes_info']) > 0) {
224
+ //$product_id = $product_options['product'];
225
+ //$_product = Mage::getModel('catalog/product')->load($product_id);
226
+ //$attributes = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
227
+ $attributes = $product_options['attributes_info'];
228
+
229
+
230
+ if(count($attributes > 0)) {
231
+ if(count($attributes <= 2)) {
232
+ $order_item ['Option_1_Name'] = (isset($attributes[0]['label'])) ? $attributes[0]['label'] : '';
233
+ $order_item ['Option_1_Value'] = (isset($attributes[0]['label'])) ? $attributes[0]['value'] : '';
234
+ $order_item ['Option_2_Name'] = (isset($attributes[1]['label'])) ? $attributes[1]['label'] : '';
235
+ $order_item ['Option_2_Value'] = (isset($attributes[1]['label'])) ? $attributes[1]['value'] : '';
236
+ } else {
237
+ $option_1_value_str = '';
238
+ foreach ($attributes as $attribute) {
239
+ $option_1_value_str .= $attribute['label'] . ':'.$attribute['value'] . ', ';
240
+ }
241
+ $order_item ['Option_1_Name'] = '';
242
+ $order_item ['Option_1_Value'] = rtrim($option_1_value_str, ',');
243
+ }
244
+ }
245
+ }
246
+
247
+ $transactions [] = array_merge ( $response, $order_item );
248
+
249
+ if ($order_status == "refunded") {
250
+
251
+ $modified_timestamp = $order->getUpdatedAtStoreDate()->getTimestamp();
252
+
253
+ $response ['Date'] = date ( 'm/d/Y', ( int ) $modified_timestamp );
254
+ $response ['Time'] = date ( 'h:i:s A', ( int ) $modified_timestamp );
255
+
256
+ $response ['Type'] = 'Refund';
257
+ $response ['Status'] = 'Completed';
258
+ $response ['Gross'] = - $order_total;
259
+ $response ['Net'] = - $order_total;
260
+ $response ['Transaction_ID'] = $order_id . '_R';
261
+ $response ['Reference_Txn_ID'] = $order_id;
262
+
263
+ $transactions [] = $response;
264
+ }
265
+ }
266
+ }
267
+ return $transactions;
268
+ }
269
+
270
+ function getOrderShippingInfo($order) {
271
+ $shippingAddress = !$order->getIsVirtual() ? $order->getShippingAddress() : null;
272
+ $address_line1 = "";
273
+ $district = "";
274
+ // correct for District
275
+ if(strpos($shippingAddress->getData("street"), "\n")){
276
+ $tmp = explode("\n", $shippingAddress->getData("street"));
277
+ $district = $tmp[1];
278
+ $address_line1 = $tmp[0];
279
+ }
280
+ if($address_line1 == ""){
281
+ $address_line1 = $shippingAddress->getData("street");
282
+ }
283
+
284
+ return array(
285
+ "Address_Line_2" => $shippingAddress ? $shippingAddress->getName() : '',
286
+ "Address_Line_1" => $shippingAddress ? $shippingAddress->getData("company") : '',
287
+ "shipping_street" => $shippingAddress ? $address_line1 : '',
288
+ "shipping_district" => $shippingAddress ? $district : '',
289
+ "Zip_Postal_Code" => $shippingAddress ? $shippingAddress->getData("postcode") : '',
290
+ "Town_City" => $shippingAddress ? $shippingAddress->getData("city") : '',
291
+ "State_Province" => $shippingAddress ? $shippingAddress->getRegionCode() : '',
292
+ "Country" => $shippingAddress ? $shippingAddress->getCountry() : '',
293
+ "Contact_Phone_Number" => $shippingAddress ? $shippingAddress->getData("telephone") : ''
294
+ );
295
+ }
296
+
297
+ function getOrderLineDetails($order) {
298
+ $lines = array();
299
+ foreach($order->getItemsCollection() as $prod)
300
+ {
301
+ $line = array();
302
+ $_product = Mage::getModel('catalog/product')->load($prod->getProductId());
303
+ $line['sku'] = $_product->getSku();
304
+ $line['order_quantity'] = (int)$prod->getQtyOrdered();
305
+ $lines[] = $line;
306
+ }
307
+ return $lines;
308
+ }
309
+
310
+ }
311
+
312
+ ?>
code/local/Putler/PutlerConnector/controllers/.DS_Store ADDED
Binary file
code/local/Putler/PutlerConnector/controllers/._.DS_Store ADDED
Binary file
code/local/Putler/PutlerConnector/controllers/._Adminhtml ADDED
Binary file
code/local/Putler/PutlerConnector/controllers/Adminhtml/.DS_Store ADDED
Binary file
code/local/Putler/PutlerConnector/controllers/Adminhtml/._.DS_Store ADDED
Binary file
code/local/Putler/PutlerConnector/controllers/Adminhtml/PutlerConnectorController.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Atwix
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+
15
+ * @category Atwix Mod
16
+ * @package Atwix_Tweaks
17
+ * @author Atwix Core Team
18
+ * @copyright Copyright (c) 2012 Atwix (http://www.atwix.com)
19
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
+ */
21
+
22
+ class Putler_PutlerConnector_Adminhtml_PutlerConnectorController extends Mage_Adminhtml_Controller_Action
23
+ {
24
+ /**
25
+ * Return some checking result
26
+ *
27
+ * @return void
28
+ */
29
+ public function checkAction() {
30
+ $api_token = trim($this->getRequest()->getParam('api_token'));
31
+ $email = trim($this->getRequest()->getParam('email'));
32
+ if($api_token != '' && $email != ''){
33
+ $putler_connector = Mage::getModel('putler_putlerconnector/PutlerConnector', $email, $api_token);
34
+ $putler_connector = Mage::getModel('putler_putlerconnector/PutlerConnector');
35
+ $result = $putler_connector->validateApiInfo($email, $api_token);
36
+ if($result) {
37
+ $config = new Mage_Core_Model_Config();
38
+ $config->saveConfig('putlersettings/general/putler_email', $email);
39
+ $config->saveConfig('putlersettings/general/putler_api_token', $api_token);
40
+ $orders = $putler_connector->getOrders();
41
+ $result = $putler_connector->postOrdersToPutler($orders);
42
+ if($result) {
43
+ $response = array('ACK' => 'SUCCESS', 'MESSAGE' => 'Settings Saved Successfully');
44
+ }
45
+ } else {
46
+ $response = array('ACK(' => 'FAILURE', 'MESSAGE' => 'Validation failed. Please Check Your Putler Email Address And API Token');
47
+ }
48
+ } else {
49
+ $response = array('ACK(' => 'FAILURE', 'MESSAGE' => 'Your Putler Email Address And API Token Should Not Be Blank');
50
+ }
51
+
52
+ $this->getResponse()->setHeader('Content-type', 'application/json');
53
+ $this->getResponse()->setBody(json_encode($response));
54
+ }
55
+ }
code/local/Putler/PutlerConnector/etc/.DS_Store ADDED
Binary file
code/local/Putler/PutlerConnector/etc/._.DS_Store ADDED
Binary file
code/local/Putler/PutlerConnector/etc/._config.xml ADDED
Binary file
code/local/Putler/PutlerConnector/etc/adminhtml.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+
3
+ <config>
4
+ <acl>
5
+ <resources>
6
+ <admin>
7
+ <children>
8
+ <system>
9
+ <children>
10
+ <config>
11
+ <children>
12
+ <putlersettings>
13
+ <title>Putler</title>
14
+ </putlersettings>
15
+ </children>
16
+ </config>
17
+ </children>
18
+ </system>
19
+ </children>
20
+ </admin>
21
+ </resources>
22
+ </acl>
23
+ </config>
code/local/Putler/PutlerConnector/etc/config.xml ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Putler_PutlerConnector>
5
+ <version>1.0</version>
6
+ </Putler_PutlerConnector>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <putler_putlerconnector>
11
+ <class>Putler_PutlerConnector_Model</class>
12
+ <resourceModel>putlerconnector_resource</resourceModel>
13
+ </putler_putlerconnector>
14
+ </models>
15
+ <blocks>
16
+ <putler_putlerconnector>
17
+ <class>Putler_PutlerConnector_Block</class>
18
+ </putler_putlerconnector>
19
+ </blocks>
20
+ <events>
21
+ <sales_order_save_commit_after>
22
+ <observers>
23
+ <post_order_data_to_putler_on_order_complete>
24
+ <type>singleton</type>
25
+ <class>Putler_PutlerConnector_Model_Observer</class>
26
+ <method>postOrderDataToPutler</method>
27
+ </post_order_data_to_putler_on_order_complete>
28
+ </observers>
29
+ </sales_order_save_commit_after>
30
+ </events>
31
+ </global>
32
+ <admin>
33
+ <routers>
34
+ <adminhtml>
35
+ <args>
36
+ <modules>
37
+ <putlerconnecotr after="Mage_Adminhtml">Putler_PutlerConnector</putlerconnecotr>
38
+ </modules>
39
+ </args>
40
+ </adminhtml>
41
+ </routers>
42
+ </admin>
43
+ </config>
code/local/Putler/PutlerConnector/etc/system.xml ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <config>
4
+ <tabs>
5
+ <putler translate="label">
6
+ <label>Putler</label>
7
+ <sort_order>150</sort_order>
8
+ </putler>
9
+ </tabs>
10
+ <sections>
11
+ <putlersettings translate="label" module="adminhtml">
12
+ <label>Settings</label>
13
+ <tab>putler</tab>
14
+ <sort_order>10</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <groups>
19
+ <general translate="label comment">
20
+ <label>Putler Settings</label>
21
+ <sort_order>50</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
+ <comment></comment>
26
+ <fields>
27
+ <putler_email translate="label comment">
28
+ <label>Your Putler Email Address</label>
29
+ <frontend_type>text</frontend_type>
30
+ <sort_order>10</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
+ </putler_email>
35
+
36
+ <putler_api_token translate="label comment">
37
+ <label>Your Putler API Token</label>
38
+ <frontend_type>text</frontend_type>
39
+ <sort_order>11</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
+ </putler_api_token>
44
+
45
+ <putler_validate translate="label">
46
+ <label></label>
47
+ <frontend_type>button</frontend_type>
48
+ <frontend_model>putler_putlerconnector/adminhtml_system_config_form_button</frontend_model>
49
+ <sort_order>20</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
+ </putler_validate>
54
+ </fields>
55
+ </general>
56
+ </groups>
57
+ </putlersettings>
58
+ </sections>
59
+ </config>
code/local/Putler/PutlerConnector/scripts/.DS_Store ADDED
Binary file
code/local/Putler/PutlerConnector/scripts/._.DS_Store ADDED
Binary file
code/local/Putler/PutlerConnector/sql/.DS_Store ADDED
Binary file
code/local/Putler/PutlerConnector/sql/._.DS_Store ADDED
Binary file
design/.DS_Store ADDED
Binary file
design/._.DS_Store ADDED
Binary file
design/adminhtml/.DS_Store ADDED
Binary file
design/adminhtml/._.DS_Store ADDED
Binary file
design/adminhtml/default/.DS_Store ADDED
Binary file
design/adminhtml/default/._.DS_Store ADDED
Binary file
design/adminhtml/default/default/.DS_Store ADDED
Binary file
design/adminhtml/default/default/._.DS_Store ADDED
Binary file
design/adminhtml/default/default/template/.DS_Store ADDED
Binary file
design/adminhtml/default/default/template/._.DS_Store ADDED
Binary file
design/adminhtml/default/default/template/putler_putlerconnector/.DS_Store ADDED
Binary file
design/adminhtml/default/default/template/putler_putlerconnector/system/.DS_Store ADDED
Binary file
design/adminhtml/default/default/template/putler_putlerconnector/system/config/button.phtml ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Atwix
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+
15
+ * @category Atwix Mod
16
+ * @package Atwix_Tweaks
17
+ * @author Atwix Core Team
18
+ * @copyright Copyright (c) 2012 Atwix (http://www.atwix.com)
19
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
20
+ * @var $this Atwix_Tweaks_Block_Adminhtml_System_Config_Form_Button
21
+ */
22
+ ?>
23
+
24
+ <script type="text/javascript">
25
+ //<![CDATA[
26
+ function check() {
27
+ var email = document.getElementById('putlersettings_general_putler_email').value;
28
+ var api_token = document.getElementById('putlersettings_general_putler_api_token').value;
29
+ new Ajax.Request('<?php echo $this->getAjaxCheckUrl() ?>', {
30
+ method: 'get',
31
+ parameters: {email: email, api_token: api_token},
32
+ dataType: 'json',
33
+ onSuccess: function(response){
34
+ if (response.responseJSON.ACK == 'SUCCESS'){
35
+ alert(response.responseJSON.MESSAGE);
36
+ } else {
37
+ alert(response.responseJSON.MESSAGE);
38
+ }
39
+ }
40
+ });
41
+ }
42
+ //]]>
43
+ </script>
44
+
45
+ <?php echo $this->getButtonHtml() ?>
etc/.DS_Store ADDED
Binary file
etc/._.DS_Store ADDED
Binary file
etc/modules/.DS_Store ADDED
Binary file
etc/modules/._.DS_Store ADDED
Binary file
etc/modules/._Putler_PutlerConnector.xml ADDED
Binary file
etc/modules/Putler_PutlerConnector.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <config>
4
+ <modules>
5
+ <Putler_PutlerConnector>
6
+ <active>true</active>
7
+ <codePool>local</codePool>
8
+ </Putler_PutlerConnector>
9
+ </modules>
10
+ </config>
package.xml ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>PutlerConnector</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>osl</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Track Magento orders on desktop and mobile with Putler - Insightful reporting that grows your business.&#xD;
10
+ &#xD;
11
+ Magento Putler Connector sends transactions to Putler using Putler's Inbound API. All past orders are sent when you first configure this extension. Future orders will be sent to Putler automatically.&#xD;
12
+ &#xD;
13
+ You need a Putler account (Free or Paid), and a Magento based store to use this extension.&#xD;
14
+ </summary>
15
+ <description>Installation&#xD;
16
+ &#xD;
17
+ Ensure you have latest version of Magento extension installed&#xD;
18
+ Unzip and upload contents of the extension to your magento root directory&#xD;
19
+ Activate the extension through Administration &gt; System &gt; Configuration &gt; Advance menu in Magento&#xD;
20
+ Make sure 'Putler_PutlerConnector' is listed on this page.&#xD;
21
+ &#xD;
22
+ Configuration&#xD;
23
+ &#xD;
24
+ Go to Administration &gt; System &gt; Configuration &gt; Putler &gt; Settings&#xD;
25
+ &#xD;
26
+ This is where you need to enter Putler API Token and Putler Email Address to sync your past Magento transactions to Putler and start tracking Magento transactions with Putler.&#xD;
27
+ &#xD;
28
+ Enter your Putler Email Address.&#xD;
29
+ Enter your Putler API Token which you will get once you add a new account "Putler Inbound API" in Putler&#xD;
30
+ Click on "Save &amp; Send Past Orders to Putler" to send all the Magento past orders to Putler.&#xD;
31
+ &#xD;
32
+ All past orders will be sent to Putler. New orders will be automatically synced.&#xD;
33
+ &#xD;
34
+ Where to find your Putler API Token?&#xD;
35
+ &#xD;
36
+ Sign up for a free account at: Putler&#xD;
37
+ Download and install Putler on your desktop&#xD;
38
+ Add a new account - select "Putler Inbound API" as the account type&#xD;
39
+ Note down the API Token and copy the same API Token in Putler Connector Settings&#xD;
40
+ </description>
41
+ <notes>This is an initial version of a Magento Putler Connector which will send Magento orders data to Putler and you will get insightful statistics about your store and business</notes>
42
+ <authors><author><name>Nirav Mehta</name><user>putler</user><email>support@putler.com</email></author></authors>
43
+ <date>2014-03-12</date>
44
+ <time>10:26:55</time>
45
+ <contents></contents>
46
+ <compatible/>
47
+ <dependencies><required><php><min>5.2.0</min><max>5.5.0</max></php></required></dependencies>
48
+ </package>