DelivraWebhook - Version 0.0.9

Version Notes

Initial release.

Download this release

Release Info

Developer Delivra
Extension DelivraWebhook
Version 0.0.9
Comparing to
See all releases


Version 0.0.9

Files changed (22) hide show
  1. app/code/community/Delivra/DelivraWebHook/Block/Adminhtml/Form/Field/Lists.php +19 -0
  2. app/code/community/Delivra/DelivraWebHook/Helper/Data.php +2 -0
  3. app/code/community/Delivra/DelivraWebHook/Helper/Lists.php +96 -0
  4. app/code/community/Delivra/DelivraWebHook/Model/Api2/Category.php +4 -0
  5. app/code/community/Delivra/DelivraWebHook/Model/Api2/Category/Rest/Admin/V1.php +20 -0
  6. app/code/community/Delivra/DelivraWebHook/Model/Api2/Integration.php +4 -0
  7. app/code/community/Delivra/DelivraWebHook/Model/Api2/Integration/Rest/Admin/V1.php +15 -0
  8. app/code/community/Delivra/DelivraWebHook/Model/Cart.php +17 -0
  9. app/code/community/Delivra/DelivraWebHook/Model/Observer.php +359 -0
  10. app/code/community/Delivra/DelivraWebHook/Model/Queue.php +48 -0
  11. app/code/community/Delivra/DelivraWebHook/Model/Resource/Cart.php +16 -0
  12. app/code/community/Delivra/DelivraWebHook/Model/Resource/Queue.php +78 -0
  13. app/code/community/Delivra/DelivraWebHook/Model/Resource/Queue/Collection.php +8 -0
  14. app/code/community/Delivra/DelivraWebHook/Model/System/Config/Backend/Lists.php +24 -0
  15. app/code/community/Delivra/DelivraWebHook/controllers/QuoteController.php +67 -0
  16. app/code/community/Delivra/DelivraWebHook/etc/api2.xml +61 -0
  17. app/code/community/Delivra/DelivraWebHook/etc/config.xml +138 -0
  18. app/code/community/Delivra/DelivraWebHook/etc/system.xml +115 -0
  19. app/code/community/Delivra/DelivraWebHook/sql/delivrawebhook_setup/install-0.0.7.php +42 -0
  20. app/code/community/Delivra/DelivraWebHook/sql/delivrawebhook_setup/upgrade-0.0.7-0.0.8.php +24 -0
  21. app/etc/modules/Delivra_DelivraWebHook.xml +9 -0
  22. package.xml +18 -0
app/code/community/Delivra/DelivraWebHook/Block/Adminhtml/Form/Field/Lists.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Delivra_DelivraWebhook_Block_Adminhtml_Form_Field_Lists extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
4
+ {
5
+ public function __construct()
6
+ {
7
+ $this->addColumn('listname', array(
8
+ 'label' => Mage::helper('adminhtml')->__('Account'),
9
+ 'style' => 'width:120px',
10
+ ));
11
+ $this->addColumn('apikey', array(
12
+ 'label' => Mage::helper('adminhtml')->__('API Key'),
13
+ 'style' => 'width:200px',
14
+ ));
15
+ $this->_addAfter = false;
16
+ $this->_addButtonLabel = Mage::helper('adminhtml')->__('Add List');
17
+ parent::__construct();
18
+ }
19
+ }
app/code/community/Delivra/DelivraWebHook/Helper/Data.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ class Delivra_DelivraWebHook_Helper_Data extends Mage_Core_Helper_Abstract {}
app/code/community/Delivra/DelivraWebHook/Helper/Lists.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Delivra_DelivraWebHook_Helper_Lists {
3
+ public function setConfigValue($listname, $apikey, $store = null)
4
+ {
5
+ $value = Mage::getStoreConfig("delivrawebhook/connection/lists", $store);
6
+ $value = $this->_unserializeValue($value);
7
+
8
+ $value[$listname] = $apikey;
9
+ $value = $this->_serializeValue($value);
10
+ Mage::getConfig()->saveConfig('delivrawebhook/connection/lists', $value, 'default', 0);
11
+ }
12
+
13
+ public function getConfigValues($store = null)
14
+ {
15
+ $value = Mage::getStoreConfig("delivrawebhook/connection/lists", $store);
16
+ $value = $this->_unserializeValue($value);
17
+ return $value;
18
+ }
19
+
20
+ public function removeList($listName, $store = null) {
21
+ $value = Mage::getStoreConfig("delivrawebhook/connection/lists", $store);
22
+ $value = $this->_unserializeValue($value);
23
+
24
+ unset($value[$listname]);
25
+ $value = $this->_serializeValue($value);
26
+ Mage::getConfig()->saveConfig('delivrawebhook/connection/lists', $value, 'default', 0);
27
+ }
28
+
29
+ protected function _serializeValue($value)
30
+ {
31
+ return json_encode($value);
32
+ }
33
+
34
+ protected function _unserializeValue($value)
35
+ {
36
+ return json_decode($value, true);
37
+ }
38
+
39
+ public function makeArrayFieldValue($value)
40
+ {
41
+ $value = $this->_unserializeValue($value);
42
+ if(is_null($value)) {
43
+ $value = '';
44
+ }
45
+
46
+ if (is_array($value)){
47
+ return $this->_encodeArrayFieldValue($value);
48
+ } else {
49
+ return null;
50
+ }
51
+ }
52
+
53
+ public function makeStorableArrayFieldValue($value)
54
+ {
55
+ $value = $this->_decodeArrayFieldValue($value);
56
+ $value = $this->_serializeValue($value);
57
+ return $value;
58
+ }
59
+
60
+ protected function _decodeArrayFieldValue(array $value)
61
+ {
62
+ if (!is_array($value)){
63
+ return $value;
64
+ }
65
+
66
+ $result = array();
67
+ unset($value['__empty']);
68
+ foreach ($value as $_id => $row) {
69
+ if (!is_array($row) || !array_key_exists('listname', $row)|| !array_key_exists('apikey', $row)) {
70
+ continue;
71
+ }
72
+ $listname = $row['listname'];
73
+ $apikey = $row['apikey'];
74
+ $result[$listname] = $apikey;
75
+ }
76
+ return $result;
77
+ }
78
+
79
+ protected function _encodeArrayFieldValue(array $value)
80
+ {
81
+ if (!is_array($value)){
82
+ return $value;
83
+ }
84
+
85
+ $result = array();
86
+ foreach ($value as $listname => $apikey) {
87
+ $_id = Mage::helper('core')->uniqHash('_');
88
+ $result[$_id] = array(
89
+ 'listname' => $listname,
90
+ 'apikey' => $apikey
91
+ );
92
+ }
93
+ return $result;
94
+ }
95
+
96
+ }
app/code/community/Delivra/DelivraWebHook/Model/Api2/Category.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ class Delivra_DelivraWebHook_Model_Api2_Category extends Mage_Api2_Model_Resource
3
+ {
4
+ }
app/code/community/Delivra/DelivraWebHook/Model/Api2/Category/Rest/Admin/V1.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Delivra_DelivraWebHook_Model_Api2_Category_Rest_Admin_V1 extends Delivra_DelivraWebHook_Model_Api2_Category
4
+ {
5
+ protected function _retrieveCollection() {
6
+ $categories = Mage::getModel('catalog/category')
7
+ ->getCollection()->addAttributeToSelect('name');
8
+
9
+ $d = array();
10
+ $i = 0;
11
+ foreach ($categories as $category) {
12
+ Mage::log($category->getName());
13
+ $category->setCategoryName($category->getName());
14
+ $d[$i] = array("entity_id" => $category->getId(), "category_name" => $category->getName());
15
+ $i = $i + 1;
16
+ }
17
+
18
+ return $d;
19
+ }
20
+ }
app/code/community/Delivra/DelivraWebHook/Model/Api2/Integration.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ class Delivra_DelivraWebHook_Model_Api2_Integration extends Mage_Api2_Model_Resource
3
+ {
4
+ }
app/code/community/Delivra/DelivraWebHook/Model/Api2/Integration/Rest/Admin/V1.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Delivra_DelivraWebHook_Model_Api2_Integration_Rest_Admin_V1 extends Delivra_DelivraWebHook_Model_Api2_Integration
4
+ {
5
+ protected function _update($integrationData)
6
+ {
7
+ Mage::getConfig()->saveConfig('delivrawebhook/connection/url', $integrationData["url"], 'default', 0);
8
+ Mage::helper('delivrawebhook/lists')->setConfigValue($integrationData["list_name"], $integrationData["api_key"]);
9
+ }
10
+
11
+ protected function _delete() {
12
+ $list = $this->getRequest()->getParam('id');
13
+ Mage::helper('delivrawebhook/lists')->removeList($list);
14
+ }
15
+ }
app/code/community/Delivra/DelivraWebHook/Model/Cart.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Delivra_DelivraWebHook_Model_Cart extends Mage_Core_Model_Abstract {
4
+ protected function _construct() {
5
+ $this->_init('delivrawebhook/cart');
6
+ }
7
+
8
+ /**
9
+ * Add a new item to the cart
10
+ */
11
+ public function addToCart($quoteData) {
12
+ Mage::log('Inserting cart value', null, 'delivra.log');
13
+
14
+ $this->_getResource()->addToCart($this, $quoteData);
15
+ return $this;
16
+ }
17
+ }
app/code/community/Delivra/DelivraWebHook/Model/Observer.php ADDED
@@ -0,0 +1,359 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Delivra_DelivraWebHook_Model_Observer {
4
+
5
+ /**
6
+ * Respond to a order save event
7
+ */
8
+ public function saveOrder($observer) {
9
+ $order = $observer->getEvent()->getOrder();
10
+ $this->handleOrderUpdate($order, $order->getStatus());
11
+ return $this;
12
+ }
13
+
14
+ /**
15
+ * Respond to a new order event
16
+ */
17
+ public function postOrder($observer) {
18
+ //$this->handleOrderUpdate($observer->getEvent()->getOrder(), "pending");
19
+ return $this;
20
+ }
21
+
22
+ /**
23
+ * Respond to a cancel order event
24
+ */
25
+ public function cancelOrder($observer) {
26
+ //$this->handleOrderUpdate($observer->getPayment()->getOrder(), "cancelled");
27
+ return $this;
28
+ }
29
+
30
+ /**
31
+ * Respond to a fulfill order event
32
+ */
33
+ public function fulfillOrder($observer) {
34
+ //$this->handleOrderUpdate($observer->getEvent()->getShipment()->getOrder(), "fulfilled");
35
+ return $this;
36
+ }
37
+
38
+ /**
39
+ * Respond to a customer update event
40
+ */
41
+ public function updateCustomer($observer) {
42
+ try {
43
+ $customer = $observer->getEvent()->getCustomer();
44
+ $customerData = $customer->getData();
45
+ $address = $customer->getPrimaryBillingAddress();
46
+ if ($address) {
47
+ $customerData['primaryBillingAddress'] = $address->getData();
48
+ }
49
+ $webhookEnabled = Mage::getStoreConfig('delivrawebhook/customer/enable', $customerData['store_id']);
50
+ if ($webhookEnabled) {
51
+ $customerEvent = new stdClass;
52
+ $customerEvent->data = $customerData;
53
+ $customerEvent->event = "Update";
54
+ $customerEvent->entityType = "customer";
55
+ $queue = Mage::getModel('delivrawebhook/queue');
56
+ $queue->enqueue($customerEvent);
57
+ }
58
+ } catch (Exception $ex) {
59
+ Mage::logException($e);
60
+ }
61
+
62
+ return $this;
63
+ }
64
+
65
+ /**
66
+ * Respond to cron event. Process abandoned carts
67
+ */
68
+ public function processAbandonedCarts($schedule) {
69
+ $adapter = Mage::getSingleton('core/resource')->getConnection('sales_read');
70
+ $minuteSetting = Mage::app()->getWebsite()->getConfig('delivrawebhook/cart/delayMins');
71
+ $minutes = intval($minuteSetting);
72
+
73
+ if($minutes > 0){
74
+ $from = $adapter->getDateSubSql(
75
+ $adapter->quote(now()),
76
+ $minutes,
77
+ Varien_Db_Adapter_Interface::INTERVAL_MINUTE);
78
+ $to = $adapter->getDateSubSql(
79
+ $adapter->quote(now()),
80
+ 14,
81
+ Varien_Db_Adapter_Interface::INTERVAL_DAY);
82
+ $quotes = Mage::getModel('sales/quote')->getCollection()
83
+ ->addFieldToFilter('converted_at', array('null' => true))
84
+ ->addFieldToFilter('customer_email', array('notnull' => true))
85
+ ->addFieldToFilter('items_count', array('gteq' => 1))
86
+ ->addFieldToFilter('reserved_order_id', array('null' => true))
87
+ ->addFieldToFilter('created_at', array('from' => $to))
88
+ ->addFieldToFilter('updated_at', array('to' => $from));
89
+
90
+ $quotes->getSelect()->joinLeft( array('cart' => 'delivrawebhook_cart'), 'main_table.entity_id = cart.quote_id', array('cart.cart_id'));
91
+ $quotes->addFieldToFilter('cart.cart_id', array('null' => true));
92
+
93
+ foreach($quotes as $quote) {
94
+ $webhookEnabled = Mage::getStoreConfig('delivrawebhook/cart/enable', $quote['store_id']);
95
+ if ($webhookEnabled) {
96
+ Mage::log('cart hook enabled');
97
+ $data = $quote->getData();
98
+ $data['url'] = Mage::getUrl('delivrawebhook/quote/restorecart',array('_nosid'=>true));
99
+ $data['url'].= '?quote='. $quote->getId();
100
+ $items = $quote->getAllItems();
101
+ foreach($items as $item) {
102
+ $itemData = array();
103
+ $product = Mage::getModel('catalog/product')->load($item->getProductId());
104
+ $itemData['entity_id'] = $item->getId();
105
+ $itemData['product_id'] = $item->getProductId();
106
+ $itemData['parent_item_id'] = $item->getParentItemId();
107
+ $itemData['name'] = $item->getName();
108
+ $itemData['created_at'] = $item->getCreatedAt();
109
+ $itemData['weight'] = $item->getWeight();
110
+ $itemData['sku'] = $product->getSku();
111
+ $productMediaConfig = Mage::getModel('catalog/product_media_config');
112
+ $itemData['image'] = Mage::getModel('catalog/product_media_config')->getMediaUrl( $product->getSmallImage() );
113
+ $itemData['qty_ordered'] = $item->getQty();
114
+ $itemData['price'] = $item->getPrice();
115
+ $itemData['description'] = $product->getDescription();
116
+ $categories = $product->getCategoryCollection()->addAttributeToSelect('name');
117
+ $categoryNames = array();
118
+ foreach($categories as $category) {
119
+ $categoryNames[] = $category->getName();
120
+ }
121
+
122
+ $itemData['categories'] = $categoryNames;
123
+ $itemData['size'] = $product->getAttributeText('size');
124
+ $itemData['color'] = $product->getAttributeText("color");
125
+
126
+ $data['line_items'][] = $itemData;
127
+ }
128
+
129
+ $customerId = $quote->getCustomerId();
130
+
131
+ if ($customerId) {
132
+ $customer = Mage::getModel('customer/customer')->load($customerId);
133
+ $data['customer'] = $customer->getData();
134
+ $data['customer']['customer_id'] = $quote->getCustomerId();
135
+ //$data['customer']['primaryBillingAddress'] = $customer->getPrimaryBillingAddress()->getData();
136
+
137
+ $billing_address = $customer->getPrimaryBillingAddress();
138
+ if ($billing_address) {
139
+ $data['customer']['primaryBillingAddress'] = $billing_address->getData();
140
+ }
141
+
142
+ $data['url'].= '&id='. $customerId;
143
+ }else{
144
+ $data['customer'] = array();
145
+ $data['customer']['customer_id'] = $quote->getCustomerId();
146
+ $data['customer']['email'] = $quote->getCustomerEmail();
147
+ $data['customer']['firstname'] = $quote->getCustomerFirstname();
148
+ $data['customer']['lastname'] = $quote->getCustomerLastname();
149
+ $billing_address = $quote->getBillingAddress();
150
+ if ($billing_address) {
151
+ $data['customer']['primaryBillingAddress'] = $billing_address->getData();
152
+ }
153
+ }
154
+
155
+ $cartEvent = new stdClass;
156
+ $cartEvent->data = $data;
157
+ $cartEvent->event = "Abandoned";
158
+ $cartEvent->entityType = "cart";
159
+ $queue = Mage::getModel('delivrawebhook/queue');
160
+ $queue->enqueue($cartEvent);
161
+
162
+ //if successful add to cart table
163
+ $cart = Mage::getModel('delivrawebhook/cart');
164
+ $cart->addToCart($data);
165
+ }
166
+ }
167
+ }else{
168
+ Mage::log('abandoned cart delay not set');
169
+ }
170
+ }
171
+
172
+ protected function cleanupQueue($queue) {
173
+ $queue->cleanup();
174
+ }
175
+
176
+ /**
177
+ * Respond to cron event. Process pending queue items
178
+ */
179
+ public function scheduledSend($schedule) {
180
+ $queue = Mage::getModel('delivrawebhook/queue');
181
+ $pending = $queue->dequeueStart();
182
+ $this->cleanupQueue($queue);
183
+ if ($pending && !empty($pending)) {
184
+ $connectedLists = Mage::helper('delivrawebhook/lists')->getConfigValues();
185
+ foreach ($connectedLists as $listName => $apiKey) {
186
+ foreach($pending as $key => $value) {
187
+ Mage::log('Delivra Queue - Processing item '.$key.' - '.$value['added_at'], null, 'delivra.log');
188
+ $urlBase = Mage::getStoreConfig('delivrawebhook/connection/url', $value['store_id']);
189
+ $url = $urlBase.'/WebHooks/Magento/Api/'.$value['entity_type'].'Event.ashx';
190
+ Mage::log($url);
191
+
192
+ $headers = array('X-Delivra-Listname' => $listName, 'X-Delivra-Apikey' => $apiKey);
193
+
194
+ $message = "Delivra Web Hook\r\n";
195
+ try {
196
+ $response = $this->proxy($value['serialized_data'], $url, $headers);
197
+ if ($response->status != '200') {
198
+ throw new Exception($response->body);
199
+ }
200
+ $responseObj = json_decode($response->body);
201
+ $message = $message."Response:\r\n".$responseObj->d;
202
+ $queue->dequeueComplete($key);
203
+ } catch (Exception $ex) {
204
+ $message = $message."There was an error sending to Delivra.";
205
+ $attempts = $value['retry_count'];
206
+ $retry = $attempts <= 5;
207
+ $queue->dequeueError($key, $retry);
208
+
209
+ if ($retry) {
210
+ $message = $message." Retry scheduled.";
211
+ } else {
212
+ $message = $message." The maximum number of retry attempts has been exceeded. Giving up.";
213
+ }
214
+ }
215
+
216
+ if ($value['entity_type'] === 'order') {
217
+ $order = Mage::getModel('sales/order')->load($value['entity_id']);
218
+ $historyItem = $order->addStatusHistoryComment(
219
+ $message,
220
+ false);
221
+ $historyItem->setIsCustomerNotified(Mage_Sales_Model_Order_Status_History::CUSTOMER_NOTIFICATION_NOT_APPLICABLE);
222
+ $historyItem->save();
223
+
224
+ $order->save();
225
+ }
226
+ }
227
+ }
228
+ }
229
+ }
230
+
231
+ /**
232
+ * Handle order events
233
+ */
234
+ private function handleOrderUpdate($order, $status) {
235
+ try {
236
+ $frontName = Mage::app()->getRequest()->getRouteName();
237
+ if ($frontName) {
238
+ $orderData = $this->transformOrder($order);
239
+ $webhookEnabled = Mage::getStoreConfig('delivrawebhook/order/enable', $orderData['store_id']);
240
+
241
+ if ($webhookEnabled) {
242
+ $webHookOrder = new stdClass;
243
+ $webHookOrder->data = $orderData;
244
+ $webHookOrder->event = $status;
245
+ $webHookOrder->entityType = "order";
246
+ $queue = Mage::getModel('delivrawebhook/queue');
247
+ $queue->enqueue($webHookOrder);
248
+ }
249
+ }
250
+ } catch (Exception $ex) {
251
+ Mage::logException($ex);
252
+ }
253
+ }
254
+
255
+ /**
256
+ * Call remote api
257
+ */
258
+ private function proxy($data, $url, $headerValues) {
259
+ $output = new stdClass();
260
+ $ch = curl_init();
261
+ $body = $data;
262
+
263
+ $headers = array('Content-Type: application/json', 'Content-Length: '.strlen($body), 'Expect:');
264
+
265
+ foreach($headerValues as $key => $value) {
266
+ $headers[] = $key.': '.$value;
267
+ }
268
+
269
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
270
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
271
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
272
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
273
+ curl_setopt($ch, CURLOPT_TIMEOUT, 60);
274
+ curl_setopt($ch, CURLOPT_URL, $url);
275
+ curl_setopt($ch, CURLOPT_HEADER, 1);
276
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
277
+
278
+ // ignore cert issues
279
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
280
+
281
+ $response = curl_exec($ch);
282
+ $output->status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
283
+ curl_close($ch);
284
+
285
+ $arr = explode("\r\n\r\n", $response, 2);
286
+ if (count($arr) == 2) {
287
+ $output->header = $arr[0];
288
+ $output->body = $arr[1];
289
+ } else {
290
+ $output->body = "Unexpected response";
291
+ }
292
+
293
+ return $output;
294
+ }
295
+
296
+ /**
297
+ * Construct the payload for an order event service call
298
+ */
299
+ private function transformOrder($orderIn) {
300
+ $orderOut = $orderIn->getData();
301
+ $orderOut["status"] = $orderIn->getStatus();
302
+ $orderOut['line_items'] = array();
303
+
304
+ $productMediaConfig = Mage::getModel('catalog/product_media_config');
305
+ $visibleItems = $orderIn->getAllItems();
306
+ foreach($visibleItems as $item) {
307
+ $itemData = $item->getData();
308
+ $product = Mage::getModel('catalog/product')->load($item->getProductId());
309
+ $categories = $product->getCategoryCollection()->addAttributeToSelect('name');
310
+ $categoryNames = array();
311
+ foreach($categories as $category) {
312
+ $categoryNames[] = $category->getName();
313
+ }
314
+
315
+ $itemData['categories'] = $categoryNames;
316
+ $itemData['imageUrl'] = $productMediaConfig->getMediaUrl($product->getSmallImage());
317
+ $itemData['description'] = $product->getDescription();
318
+ $itemData['status'] = $item->getStatus();
319
+ $itemData['size'] = $product->getAttributeText('size');
320
+ $itemData['color'] = $product->getAttributeText("color");
321
+ $orderOut['line_items'][] = $itemData;
322
+ }
323
+ $customerId = $orderIn->getCustomerId();
324
+ if ($customerId) {
325
+ $customer = Mage::getModel('customer/customer')->load($customerId);
326
+ if ($customer) {
327
+ $orderOut['customer'] = $customer->getData();
328
+ $orderOut['customer']['customer_id'] = $orderIn->getCustomerId();
329
+ $orderOut['customer']['primaryBillingAddress'] = $customer->getPrimaryBillingAddress()->getData();
330
+ }
331
+ } else {
332
+ $customer['firstname'] = $orderOut['customer_firstname'];
333
+ $customer['middlename'] = $orderOut['customer_middlename'];
334
+ $customer['lastname'] = $orderOut['customer_lastname'];
335
+ $customer['email'] = $orderOut['customer_email'];
336
+ $orderOut['customer'] = $customer;
337
+ }
338
+ $shipping_address = $orderIn->getShippingAddress();
339
+ if ($shipping_address) {
340
+ $orderOut['shipping_address'] = $shipping_address->getData();
341
+ }
342
+
343
+ $billing_address = $orderIn->getBillingAddress();
344
+ if ($billing_address) {
345
+ $orderOut['billing_address'] = $billing_address->getData();
346
+ }
347
+
348
+ $payment = $orderIn->getPayment()->getData();
349
+ foreach($payment as $key => $value) {
350
+ if (strpos($key, 'cc_') !== 0) {
351
+ $orderOut['payment'][$key] = $value;
352
+ }
353
+ }
354
+
355
+ $session = Mage::getModel('core/session');
356
+ $orderOut['visitor'] = $session->getValidatorData();
357
+ return $orderOut;
358
+ }
359
+ }
app/code/community/Delivra/DelivraWebHook/Model/Queue.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Delivra_DelivraWebHook_Model_Queue extends Mage_Core_Model_Abstract {
4
+ protected function _construct() {
5
+ $this->_init('delivrawebhook/queue');
6
+ }
7
+
8
+ /**
9
+ * Add a new item to the queue
10
+ */
11
+ public function enqueue($orderData) {
12
+ Mage::log('Inserting queue value', null, 'delivra.log');
13
+
14
+ $this->_getResource()->addMessageToQueue($this, $orderData);
15
+ return $this;
16
+ }
17
+
18
+ /**
19
+ * Gets the pending items and places them in state of processing
20
+ */
21
+ public function dequeueStart() {
22
+ return $this->_getResource()->getPending($this);
23
+ }
24
+
25
+ /**
26
+ * Called when a queue item has been successfully processed
27
+ */
28
+ public function dequeueComplete($queueId) {
29
+ Mage::log('removing from queue: '.$queueId, null, 'delivra.log');
30
+ $this->_getResource()->delete($queueId);
31
+ }
32
+
33
+ /**
34
+ * Called when a queue item encountered an error while processing
35
+ */
36
+ public function dequeueError($queueId, $retry = true) {
37
+ Mage::log('updating queue item for error: '.$queueId, null, 'delivra.log');
38
+ if ($retry) {
39
+ $this->_getResource()->reset($queueId);
40
+ } else {
41
+ $this->_getResource()->delete($queueId);
42
+ }
43
+ }
44
+
45
+ public function cleanup() {
46
+ $this->_getResource()->cleanup($this);
47
+ }
48
+ }
app/code/community/Delivra/DelivraWebHook/Model/Resource/Cart.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Delivra_DelivraWebHook_Model_Resource_Cart extends Mage_Core_Model_Resource_Db_Abstract {
4
+ protected function _construct() {
5
+ $this->_init('delivrawebhook/cart', 'cart_id');
6
+ }
7
+
8
+ public function addToCart($cart, $quoteData) {
9
+ $adapter = $this->_getWriteAdapter();
10
+
11
+ $data = array();
12
+ $data["store_id"] = $quoteData['store_id'];
13
+ $data["quote_id"] = $quoteData['entity_id'];
14
+ $adapter->insert($this->getMainTable(), $data);
15
+ }
16
+ }
app/code/community/Delivra/DelivraWebHook/Model/Resource/Queue.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Delivra_DelivraWebHook_Model_Resource_Queue extends Mage_Core_Model_Resource_Db_Abstract {
4
+ protected function _construct() {
5
+ $this->_init('delivrawebhook/queue', 'webhookqueue_id');
6
+ }
7
+
8
+ /**
9
+ * Adds a new entry to the message queue to be processed in the next cycle
10
+ */
11
+ public function addMessageToQueue($queue, $orderData) {
12
+ $adapter = $this->_getWriteAdapter();
13
+
14
+ $data = array();
15
+ $data["queue_status"] = 1;
16
+ $data["retry_count"] = 0;
17
+ $data["added_at"] = Mage::getSingleton('core/date')->gmtDate();
18
+ $data["next_attempt_at"] = Mage::getSingleton('core/date')->gmtDate();
19
+ $data["entity_id"] = $orderData->data["entity_id"];
20
+
21
+ $data["serialized_data"] = json_encode($orderData);
22
+ $data["entity_type"] = $orderData->entityType;
23
+ $adapter->insert($this->getMainTable(), $data);
24
+ }
25
+
26
+ /**
27
+ * Gets all queue entries that are ready to be sent based on status and scheduled time
28
+ */
29
+ public function getPending($queue) {
30
+ $adapter = $this->_getWriteAdapter();
31
+ $adapter->beginTransaction();
32
+ try {
33
+ $readyStatuses = array(1, 3);
34
+ $select = $adapter->select()->from($this->getMainTable())->where('queue_status IN (?)', $readyStatuses)->where('next_attempt_at <= ?', Mage::getSingleton('core/date')->gmtDate(Zend_Date::ISO_8601));
35
+ $result = $adapter->fetchAssoc($select);
36
+ $data['last_attempt_at'] = Mage::getSingleton('core/date')->gmtDate(Zend_Date::ISO_8601);
37
+ $data['queue_status'] = 2;
38
+ $adapter->update($this->getMainTable(), $data, array('queue_status IN (?)' => $readyStatuses));
39
+
40
+ $adapter->commit();
41
+ } catch (Exception $ex) {
42
+ $adapter->rollBack();
43
+ }
44
+
45
+ if ($result) {
46
+ return $result;
47
+ }
48
+
49
+ return array();
50
+ }
51
+
52
+ /**
53
+ * Removes an item from the queue
54
+ */
55
+ public function delete($queueId) {
56
+ $adapter = $this->_getWriteAdapter();
57
+ $adapter->delete($this->getMainTable(), array('webhookqueue_id = ?' => $queueId));
58
+ }
59
+
60
+ /**
61
+ * Sets a queue item to be retried in the future
62
+ */
63
+ public function reset($queueId) {
64
+ $adapter = $this->_getWriteAdapter();
65
+ $newDate = new Zend_Date(Mage::getSingleton('core/date')->gmtDate(Zend_Date::ISO_8601), Zend_Date::ISO_8601);
66
+ $newDate = $newDate->addHour('1')->get(Zend_Date::ISO_8601);
67
+ $adapter->update($this->getMainTable(), array('queue_status' => 3, 'retry_count' => new Zend_Db_Expr('retry_count + 1'), 'next_attempt_at' => $newDate), array('webhookqueue_id = ?' => $queueId));
68
+ }
69
+
70
+ public function cleanup() {
71
+ $adapter = $this->_getWriteAdapter();
72
+
73
+ $newDate = new Zend_Date(Mage::getSingleton('core/date')->gmtDate(Zend_Date::ISO_8601), Zend_Date::ISO_8601);
74
+ $newDate = $newDate->addHour('-12')->get(Zend_Date::ISO_8601);
75
+
76
+ $adapter->delete($this->getMainTable(), array('added_at <= ?' => $newDate, 'queue_status = ?' => 2));
77
+ }
78
+ }
app/code/community/Delivra/DelivraWebHook/Model/Resource/Queue/Collection.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Delivra_DelivraWebHook_Model_Resource_Queue_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract {
4
+ protected function _construct() {
5
+ $this->_map['fields']['webhookqueue_id'] = 'main_table.webhookqueue_id';
6
+ $this->_init('delivrawebhook/queue');
7
+ }
8
+ }
app/code/community/Delivra/DelivraWebHook/Model/System/Config/Backend/Lists.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Delivra_DelivraWebhook_Model_System_Config_Backend_Lists extends Mage_Core_Model_Config_Data
4
+ {
5
+ /**
6
+ * Process data after load
7
+ */
8
+ protected function _afterLoad()
9
+ {
10
+ $value = $this->getValue();
11
+ $value = Mage::helper('delivrawebhook/lists')->makeArrayFieldValue($value);
12
+ $this->setValue($value);
13
+ }
14
+
15
+ /**
16
+ * Prepare data before save
17
+ */
18
+ protected function _beforeSave()
19
+ {
20
+ $value = $this->getValue();
21
+ $value = Mage::helper('delivrawebhook/lists')->makeStorableArrayFieldValue($value);
22
+ $this->setValue($value);
23
+ }
24
+ }
app/code/community/Delivra/DelivraWebHook/controllers/QuoteController.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Delivra_DelivraWebHook_QuoteController extends Mage_Core_Controller_Front_Action
4
+ {
5
+ public function preDispatch()
6
+ {
7
+ parent::preDispatch();
8
+ }
9
+
10
+ public function restorecartAction() {
11
+ $customerId = $this->getRequest()->getParam('id');
12
+ $quoteId = (int) $this->getRequest()->getParam('quote');
13
+
14
+ //clear existing cart
15
+ $quote = Mage::getModel('checkout/cart')->getQuote();
16
+ if ($quote->getId())
17
+ {
18
+ $quote->setIsActive(0)->save();
19
+ }
20
+
21
+ $quote = Mage::getModel('sales/quote')->load($quoteId);
22
+
23
+ //logout current user if opening cart for someone else
24
+ if(Mage::getSingleton('customer/session')->isLoggedIn()) {
25
+ $customerData = Mage::getSingleton('customer/session')->getCustomer();
26
+ $sessionCustomerId = $customerData->getId();
27
+ if($sessionCustomerId != $customerId){
28
+ Mage::getSingleton('customer/session')->logout();
29
+ }
30
+ }
31
+
32
+ //if loading cart that is already linked with order, just show empty cart
33
+ $quote = Mage::getModel('sales/quote')->load($quoteId);
34
+ $orderId = $quote->getReservedOrderId();
35
+ if($orderId){
36
+ $this->_redirect('checkout/cart');
37
+ return;
38
+ }
39
+
40
+ //if cart is associated with a customer then make sure user is logged in
41
+ if($customerId){
42
+ if (!Mage::getSingleton('customer/session')->authenticate($this)) {
43
+ $this->setFlag('', self::FLAG_NO_DISPATCH, true);
44
+ }else{
45
+ $userSession = Mage::getSingleton('customer/session');
46
+
47
+ if ($quote->getId())
48
+ {
49
+ $quote->setIsActive(1)->save();
50
+ }
51
+
52
+ $this->_redirect('checkout/cart');
53
+ }
54
+ }else{
55
+ //guest
56
+ if ($quote->getId())
57
+ {
58
+ $userSession = Mage::getSingleton('customer/session');
59
+ $quote->setIsActive(1);
60
+ $quote->save();
61
+ Mage::getSingleton('checkout/session')->setQuoteId($quoteId);
62
+ }
63
+
64
+ $this->_redirect('checkout/cart');
65
+ }
66
+ }
67
+ }
app/code/community/Delivra/DelivraWebHook/etc/api2.xml ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <api2>
3
+ <resource_groups>
4
+ <delivrawebhook translate="title" module="Delivra_DelivraWebHook">
5
+ <title>Integration API</title>
6
+ <sort_order>10</sort_order>
7
+ </delivrawebhook>
8
+ </resource_groups>
9
+ <resources>
10
+ <integration translate="title" module="Delivra_DelivraWebHook">
11
+ <group>delivrawebhook_integration</group>
12
+ <model>delivrawebhook/api2_integration</model>
13
+ <title>Delivra Integration</title>
14
+ <sort_order>10</sort_order>
15
+ <privileges>
16
+ <admin>
17
+ <create>1</create>
18
+ </admin>
19
+ </privileges>
20
+ <attributes>
21
+ <list_name>List name</list_name>
22
+ <api_key>API Key</api_key>
23
+ <url>URL</url>
24
+ </attributes>
25
+ <routes>
26
+ <route_entity>
27
+ <route>/delivra/integration</route>
28
+ <action_type>entity</action_type>
29
+ </route_entity>
30
+ <route_delete>
31
+ <route>/delivra/integration/:id</route>
32
+ <action_type>entity</action_type>
33
+ </route_delete>
34
+ </routes>
35
+ <versions>1</versions>
36
+ </integration>
37
+ <category translate="title" module="Delivra_DelivraWebHook">
38
+ <group>delivrawebhook_category</group>
39
+ <model>delivrawebhook/api2_category</model>
40
+ <title>Delivra Category</title>
41
+ <sort_order>10</sort_order>
42
+ <privileges>
43
+ <admin>
44
+ <create>1</create>
45
+ </admin>
46
+ </privileges>
47
+ <attributes>
48
+ <entity_id>Category Id</entity_id>
49
+ <category_name>Category Name</category_name>
50
+ </attributes>
51
+ <routes>
52
+ <route_collection>
53
+ <route>/delivra/category</route>
54
+ <action_type>collection</action_type>
55
+ </route_collection>
56
+ </routes>
57
+ <versions>1</versions>
58
+ </category>
59
+ </resources>
60
+ </api2>
61
+ </config>
app/code/community/Delivra/DelivraWebHook/etc/config.xml ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Delivra_DelivraWebHook>
5
+ <version>0.0.9</version>
6
+ </Delivra_DelivraWebHook>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <delivrawebhook>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>Delivra_DelivraWebHook</module>
14
+ <frontName>delivrawebhook</frontName>
15
+ </args>
16
+ </delivrawebhook>
17
+ </routers>
18
+ </frontend>
19
+ <global>
20
+ <blocks>
21
+ <delivrawebhook>
22
+ <class>Delivra_DelivraWebHook_Block</class>
23
+ </delivrawebhook>
24
+ </blocks>
25
+ <models>
26
+ <delivrawebhook>
27
+ <class>Delivra_DelivraWebHook_Model</class>
28
+ <resourceModel>delivrawebhook_resource</resourceModel>
29
+ </delivrawebhook>
30
+ <delivrawebhook_resource>
31
+ <class>Delivra_DelivraWebHook_Model_Resource</class>
32
+ <entities>
33
+ <queue>
34
+ <table>delivrawebhook_queue</table>
35
+ </queue>
36
+ <cart>
37
+ <table>delivrawebhook_cart</table>
38
+ </cart>
39
+ </entities>
40
+ </delivrawebhook_resource>
41
+ </models>
42
+ <events>
43
+ <sales_order_save_after>
44
+ <observers>
45
+ <Delivra_DelivraWebHook_Model_Observer>
46
+ <class>Delivra_DelivraWebHook_Model_Observer</class>
47
+ <method>saveOrder</method>
48
+ </Delivra_DelivraWebHook_Model_Observer>
49
+ </observers>
50
+ </sales_order_save_after>
51
+ <sales_order_place_after>
52
+ <observers>
53
+ <Delivra_DelivraWebHook_Model_Observer>
54
+ <class>Delivra_DelivraWebHook_Model_Observer</class>
55
+ <method>postOrder</method>
56
+ </Delivra_DelivraWebHook_Model_Observer>
57
+ </observers>
58
+ </sales_order_place_after>
59
+ <sales_order_payment_cancel>
60
+ <observers>
61
+ <Delivra_DelivraWebHook_Model_Observer>
62
+ <class>Delivra_DelivraWebHook_Model_Observer</class>
63
+ <method>cancelOrder</method>
64
+ </Delivra_DelivraWebHook_Model_Observer>
65
+ </observers>
66
+ </sales_order_payment_cancel>
67
+ <sales_order_shipment_save_after>
68
+ <observers>
69
+ <Delivra_DelivraWebHook_Model_Observer>
70
+ <class>Delivra_DelivraWebHook_Model_Observer</class>
71
+ <method>fulfillOrder</method>
72
+ </Delivra_DelivraWebHook_Model_Observer>
73
+ </observers>
74
+ </sales_order_shipment_save_after>
75
+ <customer_save_after>
76
+ <observers>
77
+ <Delivra_DelivraWebHook_Model_Observer>
78
+ <class>Delivra_DelivraWebHook_Model_Observer</class>
79
+ <method>updateCustomer</method>
80
+ </Delivra_DelivraWebHook_Model_Observer>
81
+ </observers>
82
+ </customer_save_after>
83
+ </events>
84
+ <resources>
85
+ <delivrawebhook_setup>
86
+ <setup>
87
+ <module>Delivra_DelivraWebHook</module>
88
+ </setup>
89
+ </delivrawebhook_setup>
90
+ </resources>
91
+ <helpers>
92
+ <delivrawebhook>
93
+ <class>Delivra_DelivraWebHook_Helper</class>
94
+ </delivrawebhook>
95
+ </helpers>
96
+ </global>
97
+ <crontab>
98
+ <jobs>
99
+ <devlirawebhook_processqueue>
100
+ <schedule>
101
+ <cron_expr>*/5 * * * *</cron_expr>
102
+ </schedule>
103
+ <run>
104
+ <model>delivrawebhook/observer::scheduledSend</model>
105
+ </run>
106
+ </devlirawebhook_processqueue>
107
+ <devlirawebhook_abandonedcart>
108
+ <schedule>
109
+ <cron_expr>*/5 * * * *</cron_expr>
110
+ </schedule>
111
+ <run>
112
+ <model>delivrawebhook/observer::processAbandonedCarts</model>
113
+ </run>
114
+ </devlirawebhook_abandonedcart>
115
+ </jobs>
116
+ </crontab>
117
+ <adminhtml>
118
+ <acl>
119
+ <resources>
120
+ <admin>
121
+ <children>
122
+ <system>
123
+ <children>
124
+ <config>
125
+ <children>
126
+ <delivrawebhook>
127
+ <title>Delivra Webhook Module Section</title>
128
+ </delivrawebhook>
129
+ </children>
130
+ </config>
131
+ </children>
132
+ </system>
133
+ </children>
134
+ </admin>
135
+ </resources>
136
+ </acl>
137
+ </adminhtml>
138
+ </config>
app/code/community/Delivra/DelivraWebHook/etc/system.xml ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <tabs>
3
+ <delivra_extensions translate="label" module="delivrawebhook">
4
+ <label>Delivra Extensions</label>
5
+ <sort_order>99999</sort_order>
6
+ </delivra_extensions>
7
+ </tabs>
8
+ <sections>
9
+ <delivrawebhook translate="label" module="delivrawebhook">
10
+ <label>Web Hook Settings</label>
11
+ <tab>delivra_extensions</tab>
12
+ <frontend_type>text</frontend_type>
13
+ <sort_order>1000</sort_order>
14
+ <show_in_default>1</show_in_default>
15
+ <show_in_website>1</show_in_website>
16
+ <show_in_store>1</show_in_store>
17
+ <groups>
18
+ <connection translate="connection">
19
+ <label>Devlira Connection Details</label>
20
+ <frontend_type>text</frontend_type>
21
+ <sort_order>1</sort_order>
22
+ <show_in_default>1</show_in_default>
23
+ <show_in_website>1</show_in_website>
24
+ <show_in_store>1</show_in_store>
25
+ <fields>
26
+ <lists>
27
+ <label>Connected Accounts</label>
28
+ <frontend_model>delivrawebhook/adminhtml_form_field_lists</frontend_model>
29
+ <backend_model>delivrawebhook/system_config_backend_lists</backend_model>
30
+ <sort_order>6</sort_order>
31
+ <show_in_default>1</show_in_default>
32
+ <show_in_website>0</show_in_website>
33
+ <show_in_store>0</show_in_store>
34
+ </lists>
35
+ <url>
36
+ <label>URL</label>
37
+ <frontend_type>text</frontend_type>
38
+ <sort_order>2</sort_order>
39
+ <show_in_default>1</show_in_default>
40
+ <show_in_website>0</show_in_website>
41
+ <show_in_store>0</show_in_store>
42
+ <comment><![CDATA[This is the Delivra URL.]]></comment>
43
+ </url>
44
+ </fields>
45
+ </connection>
46
+ <order translate="label">
47
+ <label>Order Web Hook</label>
48
+ <frontend_type>text</frontend_type>
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
+ <fields>
54
+ <enable translate="label">
55
+ <label>Enable Order Web Hook</label>
56
+ <frontend_type>select</frontend_type>
57
+ <source_model>adminhtml/system_config_source_yesno</source_model>
58
+ <sort_order>0</sort_order>
59
+ <show_in_default>1</show_in_default>
60
+ <show_in_website>1</show_in_website>
61
+ <show_in_store>1</show_in_store>
62
+ </enable>
63
+ </fields>
64
+ </order>
65
+ <customer translate="customer">
66
+ <label>Customer Web Hook</label>
67
+ <frontend_type>text</frontend_type>
68
+ <sort_order>3</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
+ <fields>
73
+ <enable translate="label">
74
+ <label>Enable Customer Web Hook</label>
75
+ <frontend_type>select</frontend_type>
76
+ <source_model>adminhtml/system_config_source_yesno</source_model>
77
+ <sort_order>0</sort_order>
78
+ <show_in_default>1</show_in_default>
79
+ <show_in_website>1</show_in_website>
80
+ <show_in_store>1</show_in_store>
81
+ </enable>
82
+ </fields>
83
+ </customer>
84
+ <cart translate="cart">
85
+ <label>Cart Web Hook</label>
86
+ <frontend_type>text</frontend_type>
87
+ <sort_order>4</sort_order>
88
+ <show_in_default>1</show_in_default>
89
+ <show_in_website>1</show_in_website>
90
+ <show_in_store>1</show_in_store>
91
+ <fields>
92
+ <enable translate="label">
93
+ <label>Enable Cart Web Hook</label>
94
+ <frontend_type>select</frontend_type>
95
+ <source_model>adminhtml/system_config_source_yesno</source_model>
96
+ <sort_order>0</sort_order>
97
+ <show_in_default>1</show_in_default>
98
+ <show_in_website>1</show_in_website>
99
+ <show_in_store>1</show_in_store>
100
+ </enable>
101
+ <delayMins>
102
+ <label>Abandoned Cart Time</label>
103
+ <frontend_type>text</frontend_type>
104
+ <sort_order>1</sort_order>
105
+ <show_in_default>1</show_in_default>
106
+ <show_in_website>0</show_in_website>
107
+ <show_in_store>0</show_in_store>
108
+ <comment><![CDATA[Enter the number of minutes that the system should wait before considering an unupdated cart to be abandoned.]]></comment>
109
+ </delayMins>
110
+ </fields>
111
+ </cart>
112
+ </groups>
113
+ </delivrawebhook>
114
+ </sections>
115
+ </config>
app/code/community/Delivra/DelivraWebHook/sql/delivrawebhook_setup/install-0.0.7.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+ $table = $installer->getConnection()
7
+ ->newTable($installer->getTable('delivrawebhook/queue'))
8
+ ->addColumn('webhookqueue_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
9
+ 'identity' => true,
10
+ 'unsigned' => true,
11
+ 'nullable' => false,
12
+ 'primary' => true
13
+ ), 'WebHook Queue Id')
14
+ ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
15
+ 'unsigned' => true,
16
+ 'default' => '0',
17
+ ), 'Store Id')
18
+ ->addColumn('serialized_data', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array(
19
+ ), 'Serialized Data')
20
+ ->addColumn('queue_status', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
21
+ 'unsigned' => true,
22
+ 'default' => '0',
23
+ ), 'Queue Status')
24
+ ->addColumn('added_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
25
+ ), 'Added At')
26
+ ->addColumn('last_attempt_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
27
+ ), 'Last Attempt At')
28
+ ->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
29
+ 'unsigned' => true,
30
+ 'nullable' => false
31
+ ), 'Entity Id')
32
+ ->addColumn('entity_type', Varien_Db_Ddl_Table::TYPE_TEXT, '16', array(
33
+ ), 'Entity Type')
34
+ ->addColumn('next_attempt_at', Varien_Db_Ddl_Table::TYPE_TIMESTAMP, null, array(
35
+ ), 'Next Attempt At')
36
+ ->addColumn('retry_count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
37
+ 'unsigned' => true,
38
+ 'nullable' => false
39
+ ), 'Retry Count');
40
+ $installer->getConnection()->createTable($table);
41
+
42
+ $installer->endSetup();
app/code/community/Delivra/DelivraWebHook/sql/delivrawebhook_setup/upgrade-0.0.7-0.0.8.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+
6
+ $table = $installer->getConnection()
7
+ ->newTable($installer->getTable('delivrawebhook/cart'))
8
+ ->addColumn('cart_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
9
+ 'identity' => true,
10
+ 'unsigned' => true,
11
+ 'nullable' => false,
12
+ 'primary' => true
13
+ ), 'WebHook Cart Id')
14
+ ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
15
+ 'unsigned' => true,
16
+ 'default' => '0',
17
+ ), 'Store Id')
18
+ ->addColumn('quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
19
+ 'unsigned' => true,
20
+ 'default' => '0',
21
+ ), 'Store Id');
22
+ $installer->getConnection()->createTable($table);
23
+
24
+ $installer->endSetup();
app/etc/modules/Delivra_DelivraWebHook.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Delivra_DelivraWebHook>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Delivra_DelivraWebHook>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>DelivraWebhook</name>
4
+ <version>0.0.9</version>
5
+ <stability>stable</stability>
6
+ <license>MIT</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Increase email marketing ROI. Send personal, just-in-time emails, reward customers, and track purchases.</summary>
10
+ <description>Use Delivra for email marketing to promote your Magento store and increase sales. Delivra gives you everything you need to send targeted, personalized emails to your customers and track ROI. You can even automate sending emails based on customer action, inaction, or time. </description>
11
+ <notes>Initial release.</notes>
12
+ <authors><author><name>Delivra</name><user>Delivra</user><email>dev@delivra.com</email></author></authors>
13
+ <date>2016-06-17</date>
14
+ <time>13:40:29</time>
15
+ <contents><target name="mageetc"><dir><dir name="modules"><file name="Delivra_DelivraWebHook.xml" hash="0ef3c7d0a7c75f7780d3f685fb676f25"/></dir></dir></target><target name="magecommunity"><dir><dir name="Delivra"><dir name="DelivraWebHook"><dir name="Block"><dir name="Adminhtml"><dir name="Form"><dir name="Field"><file name="Lists.php" hash="fcba602339ea947270283c8a844f4346"/></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="9dc1723ba579337f7754441670d83ea7"/><file name="Lists.php" hash="122ab5ee9e0182c01850221052614785"/></dir><dir name="Model"><dir name="Api2"><dir name="Category"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="d33675bd9f419a80f6dcdc03e44cc561"/></dir></dir></dir><file name="Category.php" hash="cef11dc127f1feb98aeb0c26b75e5d43"/><dir name="Integration"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="ec36c7227fb5c82b8e15159d8e962b8e"/></dir></dir></dir><file name="Integration.php" hash="a6747c35bce76017f3589e5dd66cf1f7"/></dir><file name="Cart.php" hash="63bf229a3af9dec7a5a696238b098029"/><file name="Observer.php" hash="dba5c6842d3496cc73d9eba4a6bc0652"/><file name="Queue.php" hash="6f86cad61ec6a7b25df5ce909197ef1e"/><dir name="Resource"><file name="Cart.php" hash="4052b8b193d954a41bc05fcbe3e7922a"/><dir name="Queue"><file name="Collection.php" hash="d5ef10f453ebb06dd72b2503b8b6b610"/></dir><file name="Queue.php" hash="86c5944bf231fb34b620fed366691c12"/></dir><dir name="System"><dir name="Config"><dir name="Backend"><file name="Lists.php" hash="af4168ec071e89d8577da19d64d4b171"/></dir></dir></dir></dir><dir name="controllers"><file name="QuoteController.php" hash="da565ab21387ef01b866140898c05291"/></dir><dir name="etc"><file name="api2.xml" hash="5c8624af953b42c15f68643f8ae4aa0a"/><file name="config.xml" hash="369835bd184a2b0d679169fb851340bc"/><file name="system.xml" hash="10a65afc831122b61fda63b692e74ba5"/></dir><dir name="sql"><dir name="delivrawebhook_setup"><file name="install-0.0.7.php" hash="516788464c500213b91af6783fccc163"/><file name="upgrade-0.0.7-0.0.8.php" hash="a8824731d387f948c67a41dd0f52e941"/></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>