Eyemagine_HubSpot - Version 1.0.1

Version Notes

v.1.0.1: September 5, 2013
- Added controllers to handle product urls and images
- Added redirect to search results page for name when product is not available
- Minor bug fixes

Download this release

Release Info

Developer Andy
Extension Eyemagine_HubSpot
Version 1.0.1
Comparing to
See all releases


Version 1.0.1

Files changed (27) hide show
  1. app/code/community/Eyemagine/HubSpot/Block/Adminhtml/Frontend/._Utk.php +0 -0
  2. app/code/community/Eyemagine/HubSpot/Block/Adminhtml/Frontend/Button/._Regen.php +0 -0
  3. app/code/community/Eyemagine/HubSpot/Block/Adminhtml/Frontend/Button/Regen.php +38 -0
  4. app/code/community/Eyemagine/HubSpot/Block/Adminhtml/Frontend/Eyemagine/._Info.php +0 -0
  5. app/code/community/Eyemagine/HubSpot/Block/Adminhtml/Frontend/Eyemagine/._Support.php +0 -0
  6. app/code/community/Eyemagine/HubSpot/Block/Adminhtml/Frontend/Eyemagine/._Version.php +0 -0
  7. app/code/community/Eyemagine/HubSpot/Block/Adminhtml/Frontend/Eyemagine/Info.php +37 -0
  8. app/code/community/Eyemagine/HubSpot/Block/Adminhtml/Frontend/Eyemagine/Support.php +37 -0
  9. app/code/community/Eyemagine/HubSpot/Block/Adminhtml/Frontend/Eyemagine/Version.php +37 -0
  10. app/code/community/Eyemagine/HubSpot/Block/Adminhtml/Frontend/Utk.php +42 -0
  11. app/code/community/Eyemagine/HubSpot/Helper/._Data.php +0 -0
  12. app/code/community/Eyemagine/HubSpot/Helper/Data.php +337 -0
  13. app/code/community/Eyemagine/HubSpot/Model/._Observer.php +0 -0
  14. app/code/community/Eyemagine/HubSpot/Model/Observer.php +59 -0
  15. app/code/community/Eyemagine/HubSpot/controllers/._SyncController.php +0 -0
  16. app/code/community/Eyemagine/HubSpot/controllers/Adminhtml/Hubspot/._IndexController.php +0 -0
  17. app/code/community/Eyemagine/HubSpot/controllers/Adminhtml/Hubspot/IndexController.php +28 -0
  18. app/code/community/Eyemagine/HubSpot/controllers/LinkController.php +151 -0
  19. app/code/community/Eyemagine/HubSpot/controllers/SyncController.php +536 -0
  20. app/code/community/Eyemagine/HubSpot/etc/._config.xml +0 -0
  21. app/code/community/Eyemagine/HubSpot/etc/adminhtml.xml +36 -0
  22. app/code/community/Eyemagine/HubSpot/etc/config.xml +95 -0
  23. app/code/community/Eyemagine/HubSpot/etc/system.xml +163 -0
  24. app/code/community/Eyemagine/HubSpot/readme.txt +56 -0
  25. app/code/community/Eyemagine/HubSpot/sql/eyehubspot_setup/mysql4-install-1.0.0.php +26 -0
  26. app/etc/modules/Eyemagine_HubSpot.xml +26 -0
  27. package.xml +58 -0
app/code/community/Eyemagine/HubSpot/Block/Adminhtml/Frontend/._Utk.php ADDED
Binary file
app/code/community/Eyemagine/HubSpot/Block/Adminhtml/Frontend/Button/._Regen.php ADDED
Binary file
app/code/community/Eyemagine/HubSpot/Block/Adminhtml/Frontend/Button/Regen.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EYEMAGINE - The leading Magento Solution Partner
4
+ *
5
+ * HubSpot Integration with Magento
6
+ *
7
+ * @author EYEMAGINE <magento@eyemaginetech.com>
8
+ * @category Eyemagine
9
+ * @package Eyemagine_HubSpot
10
+ * @copyright Copyright (c) 2013 EYEMAGINE Technology, LLC (http://www.eyemaginetech.com)
11
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
12
+ */
13
+
14
+ class Eyemagine_HubSpot_Block_Adminhtml_Frontend_Button_Regen
15
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
16
+ {
17
+ /**
18
+ * Caches the HTML
19
+ *
20
+ * @var string
21
+ */
22
+ protected $_buttonHtml = null;
23
+
24
+
25
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
26
+ {
27
+ if ($this->_buttonHtml === null) {
28
+ $this->_buttonHtml = $this->getLayout()->createBlock('adminhtml/widget_button')
29
+ ->setId($element->getId())
30
+ ->setType('button')
31
+ ->setLabel($this->__('Regenerate'))
32
+ ->setOnClick('setLocation(\'' . Mage::helper('adminhtml')->getUrl("*/hubspot_index/regenerate") . '\')')
33
+ ->toHtml();
34
+ }
35
+
36
+ return $this->_buttonHtml;
37
+ }
38
+ }
app/code/community/Eyemagine/HubSpot/Block/Adminhtml/Frontend/Eyemagine/._Info.php ADDED
Binary file
app/code/community/Eyemagine/HubSpot/Block/Adminhtml/Frontend/Eyemagine/._Support.php ADDED
Binary file
app/code/community/Eyemagine/HubSpot/Block/Adminhtml/Frontend/Eyemagine/._Version.php ADDED
Binary file
app/code/community/Eyemagine/HubSpot/Block/Adminhtml/Frontend/Eyemagine/Info.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EYEMAGINE - The leading Magento Solution Partner
4
+ *
5
+ * HubSpot Integration with Magento
6
+ *
7
+ * @author EYEMAGINE <magento@eyemaginetech.com>
8
+ * @category Eyemagine
9
+ * @package Eyemagine_HubSpot
10
+ * @copyright Copyright (c) 2013 EYEMAGINE Technology, LLC (http://www.eyemaginetech.com)
11
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
12
+ */
13
+
14
+ class Eyemagine_HubSpot_Block_Adminhtml_Frontend_Eyemagine_Info
15
+ extends Mage_Adminhtml_Block_Abstract
16
+ implements Varien_Data_Form_Element_Renderer_Interface
17
+ {
18
+ /**
19
+ * Render element html
20
+ *
21
+ * @param Varien_Data_Form_Element_Abstract $element
22
+ * @return string
23
+ */
24
+ public function render(Varien_Data_Form_Element_Abstract $element)
25
+ {
26
+ $useContainerId = $element->getData('use_container_id');
27
+ $remoteHtml = @file_get_contents('http://www.eyemaginetech.com/canvas/info/eyehubspot.php');
28
+
29
+ if ($remoteHtml) {
30
+ return sprintf(
31
+ '<tr class="system-fieldset-sub-head" id="row_%s"><td colspan="5">%s</td></tr>',
32
+ $element->getHtmlId(),
33
+ $remoteHtml
34
+ );
35
+ }
36
+ }
37
+ }
app/code/community/Eyemagine/HubSpot/Block/Adminhtml/Frontend/Eyemagine/Support.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EYEMAGINE - The leading Magento Solution Partner
4
+ *
5
+ * HubSpot Integration with Magento
6
+ *
7
+ * @author EYEMAGINE <magento@eyemaginetech.com>
8
+ * @category Eyemagine
9
+ * @package Eyemagine_HubSpot
10
+ * @copyright Copyright (c) 2013 EYEMAGINE Technology, LLC (http://www.eyemaginetech.com)
11
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
12
+ */
13
+
14
+ class Eyemagine_HubSpot_Block_Adminhtml_Frontend_Eyemagine_Support
15
+ extends Mage_Adminhtml_Block_Abstract
16
+ implements Varien_Data_Form_Element_Renderer_Interface
17
+ {
18
+ /**
19
+ * Render element html
20
+ *
21
+ * @param Varien_Data_Form_Element_Abstract $element
22
+ * @return string
23
+ */
24
+ public function render(Varien_Data_Form_Element_Abstract $element)
25
+ {
26
+ return sprintf(
27
+ '<tr class="system-fieldset-sub-head" id="row_%s">
28
+ <td class="label"><label for="%s">%s</label></td>
29
+ <td class="value" colspan="4">%s</td>
30
+ </tr>',
31
+ $element->getHtmlId(),
32
+ $element->getHtmlId(),
33
+ $element->getLabel(),
34
+ '<a href="mailto:hubspot@eyemaginetech.com">hubspot@eyemaginetech.com</a>'
35
+ );
36
+ }
37
+ }
app/code/community/Eyemagine/HubSpot/Block/Adminhtml/Frontend/Eyemagine/Version.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EYEMAGINE - The leading Magento Solution Partner
4
+ *
5
+ * HubSpot Integration with Magento
6
+ *
7
+ * @author EYEMAGINE <magento@eyemaginetech.com>
8
+ * @category Eyemagine
9
+ * @package Eyemagine_HubSpot
10
+ * @copyright Copyright (c) 2013 EYEMAGINE Technology, LLC (http://www.eyemaginetech.com)
11
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
12
+ */
13
+
14
+ class Eyemagine_HubSpot_Block_Adminhtml_Frontend_Eyemagine_Version
15
+ extends Mage_Adminhtml_Block_Abstract
16
+ implements Varien_Data_Form_Element_Renderer_Interface
17
+ {
18
+ /**
19
+ * Render element html
20
+ *
21
+ * @param Varien_Data_Form_Element_Abstract $element
22
+ * @return string
23
+ */
24
+ public function render(Varien_Data_Form_Element_Abstract $element)
25
+ {
26
+ return sprintf(
27
+ '<tr class="system-fieldset-sub-head" id="row_%s">
28
+ <td class="label"><label for="%s">%s</label></td>
29
+ <td class="value" colspan="4">%s</td>
30
+ </tr>',
31
+ $element->getHtmlId(),
32
+ $element->getHtmlId(),
33
+ $element->getLabel(),
34
+ Mage::helper('eyehubspot')->getVersion()
35
+ );
36
+ }
37
+ }
app/code/community/Eyemagine/HubSpot/Block/Adminhtml/Frontend/Utk.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EYEMAGINE - The leading Magento Solution Partner
4
+ *
5
+ * HubSpot Integration with Magento
6
+ *
7
+ * @author EYEMAGINE <magento@eyemaginetech.com>
8
+ * @category Eyemagine
9
+ * @package Eyemagine_HubSpot
10
+ * @copyright Copyright (c) 2013 EYEMAGINE Technology, LLC (http://www.eyemaginetech.com)
11
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
12
+ */
13
+
14
+ class Eyemagine_HubSpot_Block_Adminhtml_Frontend_Utk
15
+ extends Mage_Adminhtml_Block_Abstract
16
+ implements Varien_Data_Form_Element_Renderer_Interface
17
+ {
18
+ /**
19
+ * Render element html
20
+ *
21
+ * @param Varien_Data_Form_Element_Abstract $element
22
+ * @return string
23
+ */
24
+ public function render(Varien_Data_Form_Element_Abstract $element)
25
+ {
26
+ return sprintf(
27
+ '<tr class="system-fieldset-sub-head" id="row_%s">
28
+ <td class="label"><label for="%s">%s</label></td>
29
+ <td class="value" colspan="4">%s</td>
30
+ </tr>',
31
+ $element->getHtmlId(),
32
+ $element->getHtmlId(),
33
+ $element->getLabel(),
34
+ '<p>This extension supports the HubSpot UTK Cookie and will include
35
+ the token value for orders and abandoned carts.</p>
36
+ <p>Please note, you are responsible for adding the HubSpot tracking
37
+ javascript to the site. The easiest method to add this javascript is
38
+ to add it to the System Configuration for <b>Design</b> &gt;
39
+ <b>Footer</b> &gt; <b>Miscellaneous HTML</b>.</p>'
40
+ );
41
+ }
42
+ }
app/code/community/Eyemagine/HubSpot/Helper/._Data.php ADDED
Binary file
app/code/community/Eyemagine/HubSpot/Helper/Data.php ADDED
@@ -0,0 +1,337 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EYEMAGINE - The leading Magento Solution Partner
4
+ *
5
+ * HubSpot Integration with Magento
6
+ *
7
+ * @author EYEMAGINE <magento@eyemaginetech.com>
8
+ * @category Eyemagine
9
+ * @package Eyemagine_HubSpot
10
+ * @copyright Copyright (c) 2013 EYEMAGINE Technology, LLC (http://www.eyemaginetech.com)
11
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
12
+ */
13
+
14
+ class Eyemagine_HubSpot_Helper_Data extends Mage_Core_Helper_Abstract
15
+ {
16
+ const ERROR_CODE_UNSUPPORTED_FEATURE = 9600;
17
+
18
+
19
+ /**
20
+ * Caches the version string defined in the module config.xml
21
+ *
22
+ * @var string
23
+ */
24
+ protected $_version = null;
25
+
26
+
27
+ /**
28
+ * Returns the extension version from the module config.xml
29
+ *
30
+ * @return string
31
+ */
32
+ public function getVersion()
33
+ {
34
+ if (!$this->_version) {
35
+ $info = explode('_Helper_', get_class($this));
36
+ $extensionName = array_shift($info);
37
+
38
+ $this->_version = (string)Mage::getConfig()->getNode(
39
+ 'modules/' . $extensionName . '/version'
40
+ );
41
+ }
42
+
43
+ return $this->_version;
44
+ }
45
+
46
+
47
+ /**
48
+ * Get customer group data
49
+ *
50
+ * @return array
51
+ */
52
+ public function getCustomerGroups()
53
+ {
54
+ $collection = Mage::getModel('customer/group')->getCollection();
55
+ $result = array();
56
+
57
+ foreach ($collection as $group) {
58
+ $result[$group->getId()] = $group->getCustomerGroupCode();
59
+ }
60
+
61
+ return $result;
62
+ }
63
+
64
+
65
+ /**
66
+ * Convert the object values to associative array
67
+ *
68
+ * @param Varien_Object|array $input
69
+ * @return array
70
+ */
71
+ public function convertAttributeData($input)
72
+ {
73
+ $result = array();
74
+
75
+ if (is_object($input) && $input instanceof Varien_Object) {
76
+ foreach ($input->getData() as $attribute => $value) {
77
+ if (is_object($value) || is_array($value)) {
78
+ $result[$attribute] = $this->convertAttributeData($value);
79
+ } else {
80
+ $result[$attribute] = $value;
81
+ }
82
+ }
83
+ } elseif (is_array($input)) {
84
+ foreach ($input as $k => $v) {
85
+ $result[$k] = $this->convertAttributeData($v);
86
+ }
87
+ } else {
88
+ return $input;
89
+ }
90
+
91
+ return $result;
92
+ }
93
+
94
+
95
+ /**
96
+ * Loads all relevant product and category data for the item
97
+ *
98
+ * @param Mage_Sales_Model_Order_Item|Mage_Sales_Model_Quote_Item $item
99
+ * @param int $orderStoreId
100
+ * @param int $websiteId
101
+ * @param int $maxLimit
102
+ */
103
+ public function loadCatalogData($item, $storeId, $websiteId, $maxLimit = 10)
104
+ {
105
+ $product = null;
106
+ $categories = array();
107
+ $related = array();
108
+ $upsells = array();
109
+
110
+ // load product details
111
+ if ($item->getProductId()) {
112
+ $product = Mage::getModel('catalog/product')->load($item->getProductId());
113
+
114
+ // deleted
115
+ if (!$product->getId()) {
116
+ $product = null;
117
+ }
118
+
119
+ if ($product) {
120
+ $relatedCollection = $product->getRelatedProductCollection()
121
+ ->addAttributeToSelect('name')
122
+ ->addAttributeToSelect('sku')
123
+ ->addAttributeToSelect('url_path')
124
+ ->addAttributeToSelect('image')
125
+ ->addAttributeToSelect('visibility')
126
+ ->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
127
+ ->setPageSize($maxLimit);
128
+
129
+ foreach ($relatedCollection as $p) {
130
+ $websiteIds = $p->getWebsiteIds();
131
+ if (in_array($websiteId, $websiteIds)) {
132
+ $related[$p->getId()] = $this->convertAttributeData($p);
133
+ }
134
+ }
135
+
136
+ $upsellCollection = $product->getUpSellProductCollection()
137
+ ->addAttributeToSelect('name')
138
+ ->addAttributeToSelect('sku')
139
+ ->addAttributeToSelect('url_path')
140
+ ->addAttributeToSelect('image')
141
+ ->addAttributeToSelect('visibility')
142
+ ->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
143
+ ->setPageSize($maxLimit);
144
+
145
+ foreach ($upsellCollection as $p) {
146
+ $websiteIds = $p->getWebsiteIds();
147
+ if (in_array($websiteId, $websiteIds)) {
148
+ $upsells[$p->getId()] = $this->convertAttributeData($p);
149
+ }
150
+ }
151
+
152
+ $categoryCollection = $product->getCategoryCollection()
153
+ ->addAttributeToSelect('name')
154
+ ->addAttributeToSelect('is_active')
155
+ ->addAttributeToSelect('url_path')
156
+ ->addAttributeToFilter('level', array('gt' => 1))
157
+ ->setPageSize($maxLimit);
158
+
159
+ foreach ($categoryCollection as $category) {
160
+ $storeIds = $category->getStoreIds();
161
+ if (in_array($storeId, $storeIds)) {
162
+ $categories[$category->getId()] = $this->convertAttributeData($category);
163
+ }
164
+ }
165
+
166
+ $product->setRelatedProducts($related);
167
+ $product->setUpSellProducts($upsells);
168
+ }
169
+
170
+ $item->setData('product', $product);
171
+ $item->setCategories($categories);
172
+ }
173
+ }
174
+
175
+
176
+ /**
177
+ * Load the customer recently viewed products list
178
+ *
179
+ * @param int $customerId
180
+ * @return array
181
+ */
182
+ public function getProductViewedList($customerId, $limit = 10)
183
+ {
184
+ $customerId = (int)$customerId;
185
+ $storeId = Mage::app()->getStore()->getId();
186
+ $maxpagesize = ((int)$limit) ? (int)$limit : 10;
187
+ $returnData = array();
188
+
189
+ if ($customerId) {
190
+ try {
191
+ $collection = Mage::getModel('reports/event')
192
+ ->getCollection()
193
+ ->addRecentlyFiler(
194
+ Mage_Reports_Model_Event::EVENT_PRODUCT_VIEW,
195
+ $customerId,
196
+ 0
197
+ )
198
+ ->setPageSize($maxpagesize)
199
+ ->setOrder('logged_at', Varien_Data_Collection::SORT_ORDER_DESC);
200
+
201
+ if ($storeId) {
202
+ $collection->addStoreFilter($storeId);
203
+ }
204
+
205
+ $productIds = array();
206
+
207
+ foreach ($collection as $event) {
208
+ $productIds[] = $event->getObjectId();
209
+ }
210
+
211
+ if (count($productIds)) {
212
+ $productCollection = Mage::getModel('catalog/product')
213
+ ->getCollection()
214
+ ->addAttributeToSelect('name')
215
+ ->addAttributeToSelect('sku')
216
+ ->addAttributeToSelect('price')
217
+ ->addAttributeToSelect('image')
218
+ ->addAttributeToSelect('url_path')
219
+ ->addIdFilter($productIds);
220
+
221
+ if ($storeId) {
222
+ $productCollection->setStoreId($storeId)
223
+ ->addStoreFilter($storeId);
224
+ }
225
+
226
+ foreach ($productCollection as $viewed) {
227
+ $returnData[] = $this->convertAttributeData($viewed);
228
+ }
229
+ }
230
+ } catch (Exception $e) {
231
+ $returnData['error'] = self::ERROR_CODE_UNSUPPORTED_FEATURE;
232
+ }
233
+ }
234
+
235
+ return $returnData;
236
+ }
237
+
238
+
239
+ /**
240
+ * Load the customer compare list
241
+ *
242
+ * @param int $customerId
243
+ * @return array
244
+ */
245
+ public function getProductCompareList($customerId, $limit = 10)
246
+ {
247
+ $customerId = (int)$customerId;
248
+ $storeId = Mage::app()->getStore()->getId();
249
+ $maxpagesize = ((int)$limit) ? (int)$limit : 10;
250
+ $returnData = array();
251
+
252
+ if ($customerId) {
253
+ try {
254
+ $model = Mage::getModel('catalog/product_compare_list');
255
+
256
+ $collection = $model->getItemCollection()
257
+ ->useProductItem(true)
258
+ ->setCustomerId($customerId)
259
+ ->addAttributeToSelect('name')
260
+ ->addAttributeToSelect('sku')
261
+ ->addAttributeToSelect('price')
262
+ ->addAttributeToSelect('image')
263
+ ->addAttributeToSelect('url_path')
264
+ ->addAttributeToSelect('status')
265
+ ->setOrder('catalog_compare_item_id', 'DESC');
266
+
267
+ if ($storeId) {
268
+ $collection->setStoreId($storeId)
269
+ ->addStoreFilter($storeId);
270
+ }
271
+
272
+ foreach ($collection as $compare) {
273
+ $returnData[] = $this->convertAttributeData($compare);
274
+ }
275
+ } catch (Exception $e) {
276
+ $returnData['error'] = self::ERROR_CODE_UNSUPPORTED_FEATURE;
277
+ }
278
+ }
279
+
280
+ return $returnData;
281
+ }
282
+
283
+
284
+ /**
285
+ * Load the customer wishlist
286
+ *
287
+ * @param int $customerId
288
+ * @return array
289
+ */
290
+ public function getProductWishlist($customerId, $limit = 10)
291
+ {
292
+ $customerId = (int)$customerId;
293
+ $storeId = Mage::app()->getStore()->getId();
294
+ $maxpagesize = ((int)$limit) ? (int)$limit : 10;
295
+ $returnData = array();
296
+
297
+ if ($customerId) {
298
+ try {
299
+ $model = Mage::getModel('wishlist/wishlist')
300
+ ->loadByCustomer($customerId);
301
+
302
+ $collection = $model->getProductCollection()
303
+ ->addAttributeToSelect('name')
304
+ ->addAttributeToSelect('sku')
305
+ ->addAttributeToSelect('price')
306
+ ->addAttributeToSelect('image')
307
+ ->addAttributeToSelect('url_path')
308
+ ->addAttributeToSelect('status');
309
+
310
+ foreach ($collection as $wishlist) {
311
+ $returnData[] = $this->convertAttributeData($wishlist);
312
+ }
313
+ } catch (Exception $e) {
314
+ $returnData['error'] = self::ERROR_CODE_UNSUPPORTED_FEATURE;
315
+ }
316
+ }
317
+
318
+ return $returnData;
319
+ }
320
+
321
+
322
+ /**
323
+ * Writes random access keys to the system config
324
+ *
325
+ * @param string $scope
326
+ * @param int $scopeId
327
+ */
328
+ public function generateAccessKeys($scope = 'default', $scopeId = 0)
329
+ {
330
+ $config = Mage::getConfig();
331
+ $key1 = md5(now() . rand(0, 32767) . $scope);
332
+ $key2 = md5((rand(0, 32767) * (17 + $scopeId)) . now() . 'eyehubspot');
333
+
334
+ $config->saveConfig('eyehubspot/settings/userkey', $key1, $scope, $scopeId);
335
+ $config->saveConfig('eyehubspot/settings/passcode', $key2, $scope, $scopeId);
336
+ }
337
+ }
app/code/community/Eyemagine/HubSpot/Model/._Observer.php ADDED
Binary file
app/code/community/Eyemagine/HubSpot/Model/Observer.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EYEMAGINE - The leading Magento Solution Partner
4
+ *
5
+ * HubSpot Integration with Magento
6
+ *
7
+ * @author EYEMAGINE <magento@eyemaginetech.com>
8
+ * @category Eyemagine
9
+ * @package Eyemagine_HubSpot
10
+ * @copyright Copyright (c) 2013 EYEMAGINE Technology, LLC (http://www.eyemaginetech.com)
11
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
12
+ */
13
+
14
+ class Eyemagine_HubSpot_Model_Observer
15
+ {
16
+ /**
17
+ * Updates the Hubspot User Token (UTK) if the cookie exists
18
+ *
19
+ * Event: sales_quote_collect_totals_before
20
+ *
21
+ * @param Varien_Event_Observer $observer
22
+ * @return Eyemagine_HubSpot_Model_Observer
23
+ */
24
+ public function updateHubSpotUtkForQuote(Varien_Event_Observer $observer)
25
+ {
26
+ $quote = $observer->getEvent()->getQuote();
27
+ $store = Mage::app()->getStore();
28
+
29
+ // ignore cookie if admin store
30
+ if (!$store->isAdmin()) {
31
+ $utk = isset($_COOKIE['hubspotutk']) ? $_COOKIE['hubspotutk'] : null;
32
+
33
+ if (!empty($utk)) {
34
+ $quote->setHubspotUserToken($utk);
35
+ }
36
+ }
37
+
38
+ return $this;
39
+ }
40
+
41
+
42
+ /**
43
+ * Updates the Hubspot User Token (UTK) if the cookie exists
44
+ *
45
+ * Event: sales_convert_quote_to_order
46
+ *
47
+ * @param Varien_Event_Observer $observer
48
+ * @return Eyemagine_HubSpot_Model_Observer
49
+ */
50
+ public function copyHubSpotUtk(Varien_Event_Observer $observer)
51
+ {
52
+ $quote = $observer->getEvent()->getQuote();
53
+ $order = $observer->getEvent()->getOrder();
54
+
55
+ $order->setHubspotUserToken($quote->getHubspotUserToken());
56
+
57
+ return $this;
58
+ }
59
+ }
app/code/community/Eyemagine/HubSpot/controllers/._SyncController.php ADDED
Binary file
app/code/community/Eyemagine/HubSpot/controllers/Adminhtml/Hubspot/._IndexController.php ADDED
Binary file
app/code/community/Eyemagine/HubSpot/controllers/Adminhtml/Hubspot/IndexController.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EYEMAGINE - The leading Magento Solution Partner
4
+ *
5
+ * HubSpot Integration with Magento
6
+ *
7
+ * @author EYEMAGINE <magento@eyemaginetech.com>
8
+ * @category Eyemagine
9
+ * @package Eyemagine_HubSpot
10
+ * @copyright Copyright (c) 2013 EYEMAGINE Technology, LLC (http://www.eyemaginetech.com)
11
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
12
+ */
13
+
14
+ /**
15
+ * HubSpot Integration Access Controller
16
+ */
17
+ class Eyemagine_HubSpot_Adminhtml_Hubspot_IndexController extends Mage_Adminhtml_Controller_Action
18
+ {
19
+ /**
20
+ * Regenerate the access codes for HubSpot Integration
21
+ */
22
+ public function regenerateAction()
23
+ {
24
+ Mage::helper('eyehubspot')->generateAccessKeys();
25
+
26
+ $this->_redirectReferer();
27
+ }
28
+ }
app/code/community/Eyemagine/HubSpot/controllers/LinkController.php ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EYEMAGINE - The leading Magento Solution Partner
4
+ *
5
+ * HubSpot Integration with Magento
6
+ *
7
+ * @author EYEMAGINE <magento@eyemaginetech.com>
8
+ * @category Eyemagine
9
+ * @package Eyemagine_HubSpot
10
+ * @copyright Copyright (c) 2013 EYEMAGINE Technology, LLC (http://www.eyemaginetech.com)
11
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
12
+ */
13
+
14
+ /**
15
+ * HubSpot Integration Access Controller
16
+ */
17
+ class Eyemagine_HubSpot_LinkController extends Mage_Core_Controller_Front_Action
18
+ {
19
+ /**
20
+ * Redirect the customer to the product or search page based on the product
21
+ * name if the product is not available.
22
+ */
23
+ public function productAction()
24
+ {
25
+ $searchQuery = $this->getRequest()->getParam('q');
26
+ $product = $this->_initProduct();
27
+ $url = null;
28
+ $permanente = false;
29
+
30
+ // load the product if it exists
31
+ if ($product) {
32
+ $helper = Mage::helper('catalog/product');
33
+
34
+ if ($helper->canShow($product)) {
35
+ $url = $helper->getProductUrl($product);
36
+ $permanente = true;
37
+ }
38
+ }
39
+
40
+ // fallback to search query if product and product url is not available
41
+ if (empty($url)) {
42
+ if (strlen($searchQuery)) {
43
+ // use the provided search query string (based on product name)
44
+ $url = Mage::helper('catalogsearch')->getResultUrl($searchQuery);
45
+ } elseif ($product && strlen($product->getName())) {
46
+ // product exists but is disabled or invisible
47
+ $url = Mage::helper('catalogsearch')->getResultUrl($product->getName());
48
+ } else {
49
+ // final fallback to home page
50
+ $url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
51
+ }
52
+
53
+ // adds message that the product is unavailable
54
+ $session = Mage::getSingleton('checkout/session');
55
+ $session->addNotice(Mage::getStoreConfig('eyehubspot/settings/unavailable_msg'));
56
+ }
57
+
58
+ // finally send the url redirect
59
+ Mage::app()->getResponse()
60
+ ->setRedirect($url, ($permanente) ? 301 : 302)
61
+ ->sendResponse();
62
+ }
63
+
64
+
65
+ /**
66
+ * Resamples the product image and returns the contents as raw data
67
+ */
68
+ public function imageAction()
69
+ {
70
+ // set up min max of values for the resize (smallest 50, largest 640)
71
+ $size = (int)($this->getRequest()->getParam('size'));
72
+ $size = ($size > 0) ? min(max(50, $size), 640) : 100;
73
+
74
+ // render the thumbnail and get the server path
75
+ $product = $this->_initProduct(false);
76
+ $helper = Mage::helper('catalog/image');
77
+ $url = $helper->init($product, 'thumbnail')->resize($size ? min(max(50, $size), 640) : 100);
78
+ $serverPath = str_replace(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB), '', (string)$url);
79
+ $file = @realpath($serverPath);
80
+ $pathinfo = pathinfo($url);
81
+
82
+ // add the mime-type header
83
+ switch ($pathinfo['extension']) {
84
+ case 'jpg':
85
+ header('Content-Type: image/jpeg');
86
+ break;
87
+ case 'png':
88
+ header('Content-Type: image/png');
89
+ break;
90
+ case 'gif':
91
+ header('Content-Type: image/gif');
92
+ break;
93
+ case 'xbm':
94
+ header('Content-Type: image/x-xbitmap');
95
+ break;
96
+ case 'wbpm':
97
+ header('Content-Type: image/vnd.wap.wbmp');
98
+ break;
99
+ default:
100
+ header('Content-Type: image/jpeg');
101
+ break;
102
+ }
103
+
104
+ // add the size header, and output
105
+ if ($file && file_exists($file)) {
106
+ header('Content-Length: ' . filesize($file));
107
+ ob_clean();
108
+ flush();
109
+ readfile($file);
110
+ } else {
111
+ // alt delivery method that will take more system resources but is
112
+ // unlikely to fail on servers running OS versions other than Linux
113
+ echo file_get_contents($url);
114
+ }
115
+
116
+ exit;
117
+ }
118
+
119
+
120
+ /**
121
+ * Loads and returns the product if it exists or null
122
+ *
123
+ * The addition of the $nullIfNoLoad allows the returning of an empty
124
+ * product for the image action so that it can load the placeholder image.
125
+ *
126
+ * Allows loading the product by ID or SKU.
127
+ *
128
+ * @param boolean $nullIfNoLoad
129
+ * @return Mage_Catalog_Model_Product|null
130
+ */
131
+ protected function _initProduct($nullIfNoLoad = true)
132
+ {
133
+ $productId = (int)$this->getRequest()->getParam('id');
134
+ $productSku = $this->getRequest()->getParam('sku');
135
+ $product = null;
136
+
137
+ if ($productId) {
138
+ $product = Mage::getModel('catalog/product')->load($productId);
139
+ } elseif (strlen($productSku)) {
140
+ $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $productSku);
141
+ }
142
+
143
+ if ($product && $nullIfNoLoad && !$product->getId()) {
144
+ $product = null;
145
+ } elseif (!$nullIfNoLoad && !$product) {
146
+ $product = Mage::getModel('catalog/product');
147
+ }
148
+
149
+ return $product;
150
+ }
151
+ }
app/code/community/Eyemagine/HubSpot/controllers/SyncController.php ADDED
@@ -0,0 +1,536 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EYEMAGINE - The leading Magento Solution Partner
4
+ *
5
+ * HubSpot Integration with Magento
6
+ *
7
+ * @author EYEMAGINE <magento@eyemaginetech.com>
8
+ * @category Eyemagine
9
+ * @package Eyemagine_HubSpot
10
+ * @copyright Copyright (c) 2013 EYEMAGINE Technology, LLC (http://www.eyemaginetech.com)
11
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
12
+ */
13
+
14
+ /**
15
+ * HubSpot Integration Access Controller
16
+ */
17
+ class Eyemagine_HubSpot_SyncController extends Mage_Core_Controller_Front_Action
18
+ {
19
+ /**
20
+ * Error codes
21
+ */
22
+ const ERROR_CODE_SECURE = 9001;
23
+ const ERROR_CODE_ISSECURE = 9002;
24
+ const ERROR_CODE_INVALID_STORECODE = 9003;
25
+ const ERROR_CODE_INVALID_REQUEST = 9004;
26
+ const ERROR_CODE_INVALID_CREDENTIALS = 9005;
27
+ const ERROR_CODE_UNKNOWN_EXCEPTION = 9006;
28
+ const ERROR_CODE_SYSTEM_CONFIG_DISABLED = 9020;
29
+ const ERROR_CODE_UNSUPPORTED_SQL = 9500;
30
+ const ERROR_CODE_UNSUPPORTED_FEATURE = 9600;
31
+
32
+ /**
33
+ * preset values definitions
34
+ */
35
+ const MAX_CUSTOMER_PERPAGE = 100;
36
+ const MAX_ORDER_PERPAGE = 20;
37
+ const MAX_ASSOC_PRODUCT_LIMIT = 10;
38
+ const IS_ABANDONED_IN_SECS = 3600;
39
+ const LONG_DATE_FORMAT = 'l, F j, Y \a\t h:i A \U\T\C';
40
+
41
+
42
+ /**
43
+ * Generate a list of customers updated since start date
44
+ */
45
+ public function getcustomersAction()
46
+ {
47
+ if (!$this->_authenticate()) {
48
+ return;
49
+ }
50
+
51
+ try {
52
+ $request = $this->getRequest();
53
+ $helper = Mage::helper('eyehubspot');
54
+ $maxperpage = $request->getParam('maxperpage', self::MAX_CUSTOMER_PERPAGE);
55
+ $start = date('Y-m-d H:i:s', $request->getParam('start', 0));
56
+ $end = date('Y-m-d H:i:s', time() - 300);
57
+ $websiteId = Mage::app()->getWebsite()->getId();
58
+ $storeId = Mage::app()->getStore()->getId();
59
+ $custGroups = $helper->getCustomerGroups();
60
+ $collection = Mage::getModel('customer/customer')->getCollection();
61
+ $customerData = array();
62
+
63
+ $collection->addAttributeToSelect('*')
64
+ ->addFieldToFilter('updated_at', array(
65
+ 'from' => $start,
66
+ 'to' => $end,
67
+ 'date' => true
68
+ ))
69
+ ->setOrder('updated_at', Varien_Data_Collection::SORT_ORDER_ASC)
70
+ ->setPageSize($maxperpage);
71
+
72
+ // only add the filter if website id > 0
73
+ if ($websiteId) {
74
+ $collection->addFieldToFilter('website_id', array('eq' => $websiteId));
75
+ }
76
+
77
+ foreach ($collection as $customer) {
78
+ if ($customer->getDefaultBilling()) {
79
+ $customer->setDefaultBillingAddress(
80
+ $helper->convertAttributeData($customer->getDefaultBillingAddress())
81
+ );
82
+ }
83
+
84
+ if ($customer->getDefaultShipping()) {
85
+ $customer->setDefaultShippingAddress(
86
+ $helper->convertAttributeData($customer->getDefaultShippingAddress())
87
+ );
88
+ }
89
+
90
+ // clear password hash
91
+ $customer->unsetData('password_hash');
92
+
93
+ $groupId = (int)$customer->getGroupId();
94
+
95
+ if (isset($custGroups[$groupId])) {
96
+ $customer->setCustomerGroup($custGroups[$groupId]);
97
+ }
98
+
99
+ $customerData[$customer->getId()] = $customer->getData();
100
+ }
101
+ } catch (Exception $e) {
102
+ $this->_outputError(
103
+ self::ERROR_CODE_UNKNOWN_EXCEPTION,
104
+ 'Unknown exception on request',
105
+ $e
106
+ );
107
+ return;
108
+ }
109
+
110
+ $this->_outputJson(array(
111
+ 'customers' => $customerData,
112
+ 'website' => $websiteId,
113
+ 'store' => $storeId
114
+ ));
115
+ }
116
+
117
+
118
+ /**
119
+ * Get order data
120
+ */
121
+ public function getordersAction()
122
+ {
123
+ if (!$this->_authenticate()) {
124
+ return;
125
+ }
126
+
127
+ try {
128
+ $request = $this->getRequest();
129
+ $helper = Mage::helper('eyehubspot');
130
+ $maxperpage = $request->getParam('maxperpage', self::MAX_ORDER_PERPAGE);
131
+ $maxAssociated = $request->getParam('maxassoc', self::MAX_ASSOC_PRODUCT_LIMIT);
132
+ $start = date('Y-m-d H:i:s', $request->getParam('start', 0));
133
+ $end = date('Y-m-d H:i:s', time() - 300);
134
+ $websiteId = Mage::app()->getWebsite()->getId();
135
+ $store = Mage::app()->getStore();
136
+ $storeId = Mage::app()->getStore()->getId();
137
+ $custGroups = $helper->getCustomerGroups();
138
+ $collection = Mage::getModel('sales/order')->getCollection();
139
+ $ordersData = array();
140
+
141
+ // setup the query and page size
142
+ $collection->addFieldToFilter('updated_at', array(
143
+ 'from' => $start,
144
+ 'to' => $end,
145
+ 'date' => true
146
+ ))
147
+ ->setOrder('updated_at', Varien_Data_Collection::SORT_ORDER_ASC)
148
+ ->setPageSize($maxperpage);
149
+
150
+ // only add the filter if store id > 0
151
+ if ($storeId) {
152
+ $collection->addFieldToFilter('store_id', array('eq' => $storeId));
153
+ }
154
+
155
+ // in order to get the full order details, have to load each order
156
+ foreach ($collection as $order) {
157
+ $result = $helper->convertAttributeData($order);
158
+ $groupId = (int)$order->getCustomerGroupId();
159
+
160
+ $result['customer_group'] = (isset($custGroups[$groupId])) ? $custGroups[$groupId] : 'Guest';
161
+ $result['website_id'] = $websiteId;
162
+ $result['store_url'] = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
163
+ $result['media_url'] = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
164
+ $result['shipping_address'] = $helper->convertAttributeData($order->getShippingAddress());
165
+ $result['billing_address'] = $helper->convertAttributeData($order->getBillingAddress());
166
+ $result['items'] = array();
167
+
168
+ foreach ($order->getAllItems() as $item) {
169
+ $helper->loadCatalogData($item, $storeId, $websiteId, $maxAssociated);
170
+ $result['items'][] = $helper->convertAttributeData($item);
171
+ }
172
+
173
+ $ordersData[$order->getId()] = $result;
174
+ }
175
+ } catch (Exception $e) {
176
+ $this->_outputError(
177
+ self::ERROR_CODE_UNKNOWN_EXCEPTION,
178
+ 'Unknown exception on request',
179
+ $e
180
+ );
181
+ return;
182
+ }
183
+
184
+ $this->_outputJson(array(
185
+ 'orders' => $ordersData,
186
+ 'website' => $websiteId,
187
+ 'store' => $storeId
188
+ ));
189
+ }
190
+
191
+
192
+ /**
193
+ * Loads all abandoned carts (only those created by registered customers)
194
+ */
195
+ public function getabandonedAction()
196
+ {
197
+ if (!$this->_authenticate()) {
198
+ return;
199
+ }
200
+
201
+ try {
202
+ $request = $this->getRequest();
203
+ $helper = Mage::helper('eyehubspot');
204
+ $maxperpage = $request->getParam('maxperpage', self::MAX_ORDER_PERPAGE);
205
+ $maxAssociated = $request->getParam('maxassoc', self::MAX_ASSOC_PRODUCT_LIMIT);
206
+ $start = date('Y-m-d H:i:s', $request->getParam('start', 0));
207
+ $end = date('Y-m-d H:i:s', time() - $request->getParam('offset', self::IS_ABANDONED_IN_SECS));
208
+ $websiteId = Mage::app()->getWebsite()->getId();
209
+ $store = Mage::app()->getStore();
210
+ $storeId = Mage::app()->getStore()->getId();
211
+ $custGroups = $helper->getCustomerGroups();
212
+ $collection = Mage::getModel('sales/quote')->getCollection();
213
+ $returnData = array();
214
+
215
+ // setup the query and page size
216
+ $collection->addFieldToFilter('updated_at', array(
217
+ 'from' => $start,
218
+ 'to' => $end,
219
+ 'date' => true
220
+ ))
221
+ ->addFieldToFilter('is_active', array('neq' => 0))
222
+ ->addFieldToFilter('customer_email', array('like' => '%@%'))
223
+ ->addFieldToFilter('items_count', array('gt' => 0))
224
+ ->setOrder('updated_at', Varien_Data_Collection::SORT_ORDER_ASC)
225
+ ->setPageSize($maxperpage);
226
+
227
+ // only add the filter if store id > 0
228
+ if ($storeId) {
229
+ $collection->addFieldToFilter('store_id', array('eq' => $storeId));
230
+ }
231
+
232
+ foreach ($collection as $cart) {
233
+ $result = $helper->convertAttributeData($cart);
234
+ $groupId = (int)$cart->getCustomerGroupId();
235
+
236
+ if (isset($custGroups[$groupId])) {
237
+ $result['customer_group'] = $custGroups[$groupId];
238
+ } else {
239
+ $result['customer_group'] = 'Guest';
240
+ }
241
+
242
+ $result['website_id'] = $websiteId;
243
+ $result['store_url'] = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
244
+ $result['media_url'] = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
245
+ $result['shipping_address'] = $helper->convertAttributeData($cart->getShippingAddress());
246
+ $result['billing_address'] = $helper->convertAttributeData($cart->getBillingAddress());
247
+ $result['items'] = array();
248
+
249
+ foreach ($cart->getAllItems() as $item) {
250
+ $helper->loadCatalogData($item, $cartStoreId, $websiteId, $maxAssociated);
251
+ $result['items'][] = $helper->convertAttributeData($item);
252
+ }
253
+
254
+ // make sure there are items before adding to return
255
+ if (count($result['items'])) {
256
+ $returnData[$cart->getId()] = $result;
257
+ }
258
+ }
259
+ } catch (Exception $e) {
260
+ $this->_outputError(
261
+ self::ERROR_CODE_UNKNOWN_EXCEPTION,
262
+ 'Unknown exception on request',
263
+ $e
264
+ );
265
+ return;
266
+ }
267
+
268
+ $this->_outputJson(array(
269
+ 'abandoned' => $returnData,
270
+ 'website' => $websiteId,
271
+ 'store' => $storeId
272
+ ));
273
+ }
274
+
275
+
276
+ /**
277
+ * Retrieves recent activity for customers (sorted by last visit date)
278
+ */
279
+ function getactivityAction()
280
+ {
281
+ if (!$this->_authenticate()) {
282
+ return;
283
+ }
284
+
285
+ try {
286
+ $request = $this->getRequest();
287
+ $helper = Mage::helper('eyehubspot');
288
+ $maxperpage = $request->getParam('maxperpage', self::MAX_CUSTOMER_PERPAGE);
289
+ $maxAssociated = $request->getParam('maxassoc', self::MAX_ASSOC_PRODUCT_LIMIT);
290
+ $start = date('Y-m-d H:i:s', $request->getParam('start', 0));
291
+ $end = date('Y-m-d H:i:s', time() - 300);
292
+ $websiteId = Mage::app()->getWebsite()->getId();
293
+ $store = Mage::app()->getStore();
294
+ $storeId = Mage::app()->getStore()->getId();
295
+ $collection = Mage::getModel('customer/customer')->getCollection();
296
+ $resource = Mage::getSingleton('core/resource');
297
+ $read = $resource->getConnection('core_read');
298
+ $customerData = array();
299
+
300
+ try {
301
+ // because of limitations in the log areas of magento, we cannot use the
302
+ // standard collection to retreive the results
303
+ $select = $read->select()
304
+ ->from(array('lc' => $resource->getTableName('log/customer')))
305
+ ->joinInner(
306
+ array('lv' => $resource->getTableName('log/visitor')),
307
+ 'lc.visitor_id = lv.visitor_id'
308
+ )
309
+ ->joinInner(
310
+ array('vi' => $resource->getTableName('log/visitor_info')),
311
+ 'lc.visitor_id = vi.visitor_id'
312
+ )
313
+ ->joinInner(
314
+ array('c' => $resource->getTableName('customer/entity')),
315
+ 'c.entity_id = lc.customer_id',
316
+ array('email' => 'email', 'customer_since' => 'created_at')
317
+ )
318
+ ->joinInner(
319
+ array('p' => $resource->getTableName('log/url_info_table')),
320
+ 'p.url_id = lv.last_url_id',
321
+ array('last_url' => 'p.url', 'last_referer' => 'p.referer')
322
+ )
323
+ ->where('lc.customer_id > 0')
324
+ ->where("lv.last_visit_at >= '$start'")
325
+ ->where("lv.last_visit_at < '$end'")
326
+ ->order('lv.last_visit_at')
327
+ ->limit($maxperpage);
328
+
329
+ $collection = $read->fetchAll($select);
330
+ } catch (Exception $e) {
331
+ $this->_outputError(self::ERROR_CODE_UNSUPPORTED_SQL, 'DB Exception on query', $e);
332
+ return;
333
+ }
334
+
335
+ foreach ($collection as $assoc) {
336
+ $log = new Varien_Object($assoc);
337
+ $customerId = $log->getCustomerId();
338
+
339
+ // merge and replace older data with newer
340
+ if (isset($customerData[$customerId])) {
341
+ $temp = $customerData[$customerId];
342
+ $log->addData($temp->getData());
343
+ $log->setFirstVisitAt($temp->getFirstVisitAt());
344
+ } else {
345
+ $log->setViewed($helper->getProductViewedList($customerId, $maxAssociated));
346
+ $log->setCompare($helper->getProductCompareList($customerId, $maxAssociated));
347
+ $log->setWishlist($helper->getProductWishlist($customerId, $maxAssociated));
348
+ }
349
+
350
+ $log->unsetData('session_id');
351
+ $customerData[$customerId] = $log;
352
+ }
353
+ } catch (Exception $e) {
354
+ $this->_outputError(
355
+ self::ERROR_CODE_UNKNOWN_EXCEPTION,
356
+ 'Unknown exception on request',
357
+ $e
358
+ );
359
+ return;
360
+ }
361
+
362
+ $this->_outputJson(array(
363
+ 'visitors' => $helper->convertAttributeData($customerData),
364
+ 'website' => $websiteId,
365
+ 'store' => $storeId
366
+ ));
367
+ }
368
+
369
+
370
+ /**
371
+ * Display information about the Magento stores that are installed
372
+ */
373
+ public function getstoresAction()
374
+ {
375
+ if (!$this->_authenticate()) {
376
+ return;
377
+ }
378
+
379
+ // get state names
380
+ $regionModel = Mage::getModel('directory/region');
381
+ $storeData = array();
382
+ $edition = method_exists('Mage', 'getEdition') ? Mage::getEdition() : '';
383
+
384
+ foreach (Mage::app()->getStores(true, true) as $storeCode => $store) {
385
+ $storeId = $store->getId();
386
+ $region = null;
387
+
388
+ if (is_object($regionModel)) {
389
+ $regionId = (int)Mage::getStoreConfig('shipping/origin/region_id', $storeId);
390
+
391
+ if ($regionModel->getId() != $regionId) {
392
+ $regionModel->load($regionId);
393
+ }
394
+
395
+ $region = $regionModel->getDefaultName();
396
+ }
397
+
398
+ $storeData[$storeCode] = array(
399
+ 'store_id' => $storeId,
400
+ 'store_code' => $storeCode,
401
+ 'website_id' => $store->getWebsiteId(),
402
+ 'store_name' => Mage::getStoreConfig('system/store/name', $storeId),
403
+ 'business_name' => Mage::getStoreConfig('general/store_information/name', $storeId),
404
+ 'email' => Mage::getStoreConfig('trans_email/ident_general/email', $storeId),
405
+ 'magento_state' => $region,
406
+ 'magento_country' => Mage::getStoreConfig('general/store_information/merchant_country', $storeId),
407
+ 'base_url' => $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB),
408
+ 'secure_base_url' => $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true),
409
+ 'media_url' => $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA),
410
+ 'locale_code' => Mage::getStoreConfig('general/locale/code', $storeId),
411
+ );
412
+ }
413
+
414
+ $this->_outputJson(array(
415
+ 'stores' => $storeData,
416
+ 'script_version' => Mage::helper('eyehubspot')->getVersion(),
417
+ 'magento_version' => Mage::getVersion(),
418
+ 'magento_edition' => $edition,
419
+ ));
420
+ }
421
+
422
+
423
+ /**
424
+ * Display information about the current Magento store
425
+ */
426
+ public function getinfoAction()
427
+ {
428
+ if (!$this->_authenticate()) {
429
+ return;
430
+ }
431
+
432
+ $store = Mage::app()->getStore();
433
+ $storeId = $store->getId();
434
+ $regionModel = Mage::getModel('directory/region');
435
+ $edition = method_exists('Mage', 'getEdition') ? Mage::getEdition() : '';
436
+ $storeData = array();
437
+ $region = null;
438
+
439
+ if (is_object($regionModel)) {
440
+ $regionId = (int)Mage::getStoreConfig('shipping/origin/region_id', $storeId);
441
+
442
+ if ($regionModel->getId() != $regionId) {
443
+ $regionModel->load($regionId);
444
+ }
445
+
446
+ $region = $regionModel->getDefaultName();
447
+ }
448
+
449
+ $storeData = array(
450
+ 'store_id' => $storeId,
451
+ 'store_code' => $store->getCode(),
452
+ 'website_id' => $store->getWebsiteId(),
453
+ 'store_name' => Mage::getStoreConfig('system/store/name', $storeId),
454
+ 'business_name' => Mage::getStoreConfig('general/store_information/name', $storeId),
455
+ 'magento_email' => Mage::getStoreConfig('trans_email/ident_general/email', $storeId),
456
+ 'magento_state' => $region,
457
+ 'magento_country' => Mage::getStoreConfig('general/store_information/merchant_country', $storeId),
458
+ 'base_url' => $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, false),
459
+ 'secure_base_url' => $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true),
460
+ 'media_url' => $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA, false),
461
+ 'locale_code' => Mage::getStoreConfig('general/locale/code', $storeId),
462
+ );
463
+
464
+ $this->_outputJson(array(
465
+ 'info' => $storeData,
466
+ 'script_version' => Mage::helper('eyehubspot')->getVersion(),
467
+ 'magento_version' => Mage::getVersion(),
468
+ 'magento_edition' => $edition,
469
+ ));
470
+ }
471
+
472
+
473
+ /**
474
+ * Verify that the requestor has valid access
475
+ *
476
+ * @return boolean
477
+ */
478
+ protected function _authenticate()
479
+ {
480
+ $enabled = (int)Mage::getStoreConfig('eyehubspot/settings/active');
481
+ $key1 = Mage::getStoreConfig('eyehubspot/settings/userkey');
482
+ $key2 = Mage::getStoreConfig('eyehubspot/settings/passcode');
483
+
484
+ if (!$enabled) {
485
+ $this->_outputError(
486
+ self::ERROR_CODE_SYSTEM_CONFIG_DISABLED,
487
+ 'Magento System Configuration has disabled access to this resource.
488
+ To re-enable, please go to Magento Admin > System > Configuration >
489
+ Services > HubSpot Integration.'
490
+ );
491
+ return false;
492
+
493
+ } elseif ($enabled && !empty($key1) && !empty($key2)) {
494
+ if ((strcasecmp($key1, $this->getRequest()->getParam('ukey')) == 0)
495
+ && (strcasecmp($key2, $this->getRequest()->getParam('code')) == 0)
496
+ ) {
497
+ return true;
498
+ }
499
+ }
500
+
501
+ $this->_outputError(self::ERROR_CODE_INVALID_CREDENTIALS, 'Invalid user key and/or access code');
502
+
503
+ return false;
504
+ }
505
+
506
+
507
+ /**
508
+ * Function used to output an error and quit.
509
+ *
510
+ * @param integer $code
511
+ * @param string $error
512
+ * @param Exception $e
513
+ */
514
+ public function _outputError($code, $error, Exception $e = null)
515
+ {
516
+ $this->_outputJson(array(
517
+ 'error' => $error,
518
+ 'code' => $code,
519
+ 'extra' => ($e && $authen) ? $e->getMessage() : ''
520
+ ));
521
+ }
522
+
523
+
524
+ /**
525
+ * Flushes the data as JSON response
526
+ *
527
+ * @param mixed $data
528
+ */
529
+ protected function _outputJson($data)
530
+ {
531
+ $this->getResponse()
532
+ ->clearHeaders()
533
+ ->setHeader('Content-Type', 'application/json;charset=utf-8')
534
+ ->setBody(Mage::helper('core')->jsonEncode($data));
535
+ }
536
+ }
app/code/community/Eyemagine/HubSpot/etc/._config.xml ADDED
Binary file
app/code/community/Eyemagine/HubSpot/etc/adminhtml.xml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * EYEMAGINE - The leading Magento Solution Partner
5
+ *
6
+ * HubSpot Integration with Magento
7
+ *
8
+ * @author EYEMAGINE <magento@eyemaginetech.com>
9
+ * @category Eyemagine
10
+ * @package Eyemagine_HubSpot
11
+ * @copyright Copyright (c) 2013 EYEMAGINE Technology, LLC (http://www.eyemaginetech.com)
12
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
13
+ */
14
+ -->
15
+ <config>
16
+ <acl>
17
+ <resources>
18
+ <admin>
19
+ <children>
20
+ <system>
21
+ <children>
22
+ <config>
23
+ <children>
24
+ <eyehubspot translate="title" module="eyehubspot">
25
+ <title>HubSpot Integration</title>
26
+ <sort_order>0</sort_order>
27
+ </eyehubspot>
28
+ </children>
29
+ </config>
30
+ </children>
31
+ </system>
32
+ </children>
33
+ </admin>
34
+ </resources>
35
+ </acl>
36
+ </config>
app/code/community/Eyemagine/HubSpot/etc/config.xml ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * EYEMAGINE - The leading Magento Solution Partner
5
+ *
6
+ * HubSpot Integration with Magento
7
+ *
8
+ * @author EYEMAGINE <magento@eyemaginetech.com>
9
+ * @category Eyemagine
10
+ * @package Eyemagine_HubSpot
11
+ * @copyright Copyright (c) 2013 EYEMAGINE Technology, LLC (http://www.eyemaginetech.com)
12
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
13
+ */
14
+ -->
15
+ <config>
16
+ <modules>
17
+ <Eyemagine_HubSpot>
18
+ <version>1.0.1</version>
19
+ </Eyemagine_HubSpot>
20
+ </modules>
21
+ <global>
22
+ <models>
23
+ <eyehubspot>
24
+ <class>Eyemagine_HubSpot_Model</class>
25
+ </eyehubspot>
26
+ </models>
27
+ <resources>
28
+ <eyehubspot_setup>
29
+ <setup>
30
+ <module>Eyemagine_HubSpot</module>
31
+ </setup>
32
+ </eyehubspot_setup>
33
+ </resources>
34
+ <blocks>
35
+ <eyehubspot>
36
+ <class>Eyemagine_HubSpot_Block</class>
37
+ </eyehubspot>
38
+ </blocks>
39
+ <helpers>
40
+ <eyehubspot>
41
+ <class>Eyemagine_HubSpot_Helper</class>
42
+ </eyehubspot>
43
+ </helpers>
44
+ <events>
45
+ <sales_quote_collect_totals_before>
46
+ <observers>
47
+ <eyehubspot>
48
+ <class>eyehubspot/observer</class>
49
+ <method>updateHubSpotUtkForQuote</method>
50
+ </eyehubspot>
51
+ </observers>
52
+ </sales_quote_collect_totals_before>
53
+ <sales_convert_quote_to_order>
54
+ <observers>
55
+ <eyehubspot>
56
+ <class>eyehubspot/observer</class>
57
+ <method>copyHubSpotUtk</method>
58
+ </eyehubspot>
59
+ </observers>
60
+ </sales_convert_quote_to_order>
61
+ </events>
62
+ </global>
63
+ <admin>
64
+ <routers>
65
+ <adminhtml>
66
+ <args>
67
+ <modules>
68
+ <Eyemagine_HubSpot before="Mage_Adminhtml">Eyemagine_HubSpot_Adminhtml</Eyemagine_HubSpot>
69
+ </modules>
70
+ </args>
71
+ </adminhtml>
72
+ </routers>
73
+ </admin>
74
+ <frontend>
75
+ <routers>
76
+ <eyehubspot>
77
+ <use>standard</use>
78
+ <args>
79
+ <module>Eyemagine_HubSpot</module>
80
+ <frontName>eyehubspot</frontName>
81
+ </args>
82
+ </eyehubspot>
83
+ </routers>
84
+ <secure_url>
85
+ <eyehubspot>/eyehubspot/</eyehubspot>
86
+ </secure_url>
87
+ </frontend>
88
+ <default>
89
+ <eyehubspot>
90
+ <settings>
91
+ <unavailable_msg>The requested product is currently not available. Here are some other products you might be interested in.</unavailable_msg>
92
+ </settings>
93
+ </eyehubspot>
94
+ </default>
95
+ </config>
app/code/community/Eyemagine/HubSpot/etc/system.xml ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * EYEMAGINE - The leading Magento Solution Partner
5
+ *
6
+ * HubSpot Integration with Magento
7
+ *
8
+ * @author EYEMAGINE <magento@eyemaginetech.com>
9
+ * @category Eyemagine
10
+ * @package Eyemagine_HubSpot
11
+ * @copyright Copyright (c) 2013 EYEMAGINE Technology, LLC (http://www.eyemaginetech.com)
12
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
13
+ */
14
+ -->
15
+ <config>
16
+ <sections>
17
+ <eyehubspot translate="label" module="eyehubspot">
18
+ <label>HubSpot Integration</label>
19
+ <tab>service</tab>
20
+ <frontend_type>text</frontend_type>
21
+ <sort_order>300</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
+ <groups>
26
+ <info translate="label">
27
+ <label>About</label>
28
+ <frontend_type>text</frontend_type>
29
+ <sort_order>1</sort_order>
30
+ <expanded>1</expanded>
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
+ <info translate="label">
36
+ <label>Extension Info</label>
37
+ <frontend_model>eyehubspot/adminhtml_frontend_eyemagine_info</frontend_model>
38
+ <sort_order>0</sort_order>
39
+ <show_in_default>1</show_in_default>
40
+ <show_in_website>1</show_in_website>
41
+ <show_in_store>1</show_in_store>
42
+ </info>
43
+ <heading_info translate="label">
44
+ <label>Installed Extension Details</label>
45
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
46
+ <sort_order>10</sort_order>
47
+ <show_in_default>1</show_in_default>
48
+ <show_in_website>1</show_in_website>
49
+ <show_in_store>1</show_in_store>
50
+ </heading_info>
51
+ <version translate="label">
52
+ <label>Version</label>
53
+ <frontend_type>note</frontend_type>
54
+ <frontend_model>eyehubspot/adminhtml_frontend_eyemagine_version</frontend_model>
55
+ <sort_order>20</sort_order>
56
+ <show_in_default>1</show_in_default>
57
+ <show_in_website>1</show_in_website>
58
+ <show_in_store>1</show_in_store>
59
+ </version>
60
+ <supportemail translate="label">
61
+ <label>Support Email</label>
62
+ <frontend_type>note</frontend_type>
63
+ <frontend_model>eyehubspot/adminhtml_frontend_eyemagine_support</frontend_model>
64
+ <sort_order>50</sort_order>
65
+ <show_in_default>1</show_in_default>
66
+ <show_in_website>1</show_in_website>
67
+ <show_in_store>1</show_in_store>
68
+ </supportemail>
69
+ </fields>
70
+ </info>
71
+ <settings translate="label">
72
+ <label>HubSpot Integration Settings</label>
73
+ <frontend_type>text</frontend_type>
74
+ <sort_order>100</sort_order>
75
+ <expanded>1</expanded>
76
+ <show_in_default>1</show_in_default>
77
+ <show_in_website>1</show_in_website>
78
+ <show_in_store>1</show_in_store>
79
+ <fields>
80
+ <active translate="label">
81
+ <label>Enable</label>
82
+ <sort_order>1</sort_order>
83
+ <frontend_type>select</frontend_type>
84
+ <source_model>adminhtml/system_config_source_yesno</source_model>
85
+ <comment>Must be enabled for sync access</comment>
86
+ <show_in_default>1</show_in_default>
87
+ <show_in_website>1</show_in_website>
88
+ <show_in_store>1</show_in_store>
89
+ </active>
90
+ <userkey translate="label">
91
+ <label>User Key</label>
92
+ <frontend_type>label</frontend_type>
93
+ <sort_order>100</sort_order>
94
+ <show_in_default>1</show_in_default>
95
+ <show_in_website>0</show_in_website>
96
+ <show_in_store>0</show_in_store>
97
+ <tooltip>Copy this field to the HubSpot Magento app</tooltip>
98
+ </userkey>
99
+ <passcode translate="label">
100
+ <label>Access Code</label>
101
+ <frontend_type>label</frontend_type>
102
+ <sort_order>110</sort_order>
103
+ <show_in_default>1</show_in_default>
104
+ <show_in_website>0</show_in_website>
105
+ <show_in_store>0</show_in_store>
106
+ </passcode>
107
+ <regen translate="label">
108
+ <label>Regenerate Access Codes</label>
109
+ <frontend_type>button</frontend_type>
110
+ <frontend_model>eyehubspot/adminhtml_frontend_button_regen</frontend_model>
111
+ <sort_order>120</sort_order>
112
+ <depends><active>1</active></depends>
113
+ <show_in_default>1</show_in_default>
114
+ <show_in_website>0</show_in_website>
115
+ <show_in_store>0</show_in_store>
116
+ </regen>
117
+
118
+ <!-- Link Options -->
119
+ <heading_notifications translate="label">
120
+ <label>Link Options</label>
121
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
122
+ <sort_order>200</sort_order>
123
+ <depends><active>1</active></depends>
124
+ <show_in_default>1</show_in_default>
125
+ <show_in_website>1</show_in_website>
126
+ <show_in_store>1</show_in_store>
127
+ </heading_notifications>
128
+ <unavailable_msg translate="label">
129
+ <label>Product Unavailable Message</label>
130
+ <frontend_type>textarea</frontend_type>
131
+ <sort_order>210</sort_order>
132
+ <depends><active>1</active></depends>
133
+ <show_in_default>1</show_in_default>
134
+ <show_in_website>1</show_in_website>
135
+ <show_in_store>1</show_in_store>
136
+ <tooltip>Display this message and the search results when requested product is not available on frontend.</tooltip>
137
+ </unavailable_msg>
138
+ </fields>
139
+ </settings>
140
+ <utk translate="label">
141
+ <label>HubSpot UTK</label>
142
+ <frontend_type>text</frontend_type>
143
+ <sort_order>200</sort_order>
144
+ <expanded>1</expanded>
145
+ <show_in_default>1</show_in_default>
146
+ <show_in_website>1</show_in_website>
147
+ <show_in_store>1</show_in_store>
148
+ <fields>
149
+ <utk translate="label">
150
+ <label>Compatibility Note</label>
151
+ <frontend_type>label</frontend_type>
152
+ <frontend_model>eyehubspot/adminhtml_frontend_utk</frontend_model>
153
+ <sort_order>100</sort_order>
154
+ <show_in_default>1</show_in_default>
155
+ <show_in_website>0</show_in_website>
156
+ <show_in_store>0</show_in_store>
157
+ </utk>
158
+ </fields>
159
+ </utk>
160
+ </groups>
161
+ </eyehubspot>
162
+ </sections>
163
+ </config>
app/code/community/Eyemagine/HubSpot/readme.txt ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * EYEMAGINE - The leading Magento Solution Partner
3
+ *
4
+ * HubSpot Integration with Magento
5
+ *
6
+ * @author EYEMAGINE <magento@eyemaginetech.com>
7
+ * @category Eyemagine
8
+ * @package Eyemagine_HubSpot
9
+ * @copyright Copyright (c) 2013 EYEMAGINE Technology, LLC (http://www.eyemaginetech.com)
10
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
11
+ */
12
+
13
+ -------------------------------------------------------------------------------
14
+ DESCRIPTION:
15
+ -------------------------------------------------------------------------------
16
+
17
+ Integration with Magento and HubSpot which syncs Magento customers with HubSpot
18
+ Contacts along with customer attributes, order history, abandoned carts, recent
19
+ history, and lifetime statistics.
20
+
21
+ When the HubSpot UTK javascript is included in the site, this integration will
22
+ also include timeline and user activity analytics.
23
+
24
+ To enable HubSpot Syncing you must activate the extension in the Magento Admin:
25
+
26
+ System > Configuration > Services > HubSpot Integration > Settings
27
+
28
+
29
+
30
+
31
+ Module Files:
32
+
33
+ - app/code/community/Eyemagine/HubSpot/
34
+ - app/etc/modules/Eyemagine_HubSpot.xml
35
+
36
+
37
+ -------------------------------------------------------------------------------
38
+ COMPATIBILITY:
39
+ -------------------------------------------------------------------------------
40
+
41
+ - Magento Enterprise Edition 1.10.1.0 to 1.12.0.2
42
+ - Magento Community Edition 1.4.2.0 to 1.7.0.2
43
+
44
+
45
+ -------------------------------------------------------------------------------
46
+ RELEASE NOTES:
47
+ -------------------------------------------------------------------------------
48
+
49
+ v.1.0.1: September 5, 2013
50
+ - Added controllers to handle product urls and images
51
+ - Added redirect to search results page for name when product is not
52
+ available
53
+ - Minor bug fixes
54
+
55
+ v.1.0.0: July 8, 2013
56
+ - Initial release.
app/code/community/Eyemagine/HubSpot/sql/eyehubspot_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EYEMAGINE - The leading Magento Solution Partner
4
+ *
5
+ * HubSpot Integration with Magento
6
+ *
7
+ * @author EYEMAGINE <magento@eyemaginetech.com>
8
+ * @category Eyemagine
9
+ * @package Eyemagine_HubSpot
10
+ * @copyright Copyright (c) 2013 EYEMAGINE Technology, LLC (http://www.eyemaginetech.com)
11
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
12
+ */
13
+
14
+ $installer = $this;
15
+ /* @var $installer Mage_Core_Model_Resource_Setup */
16
+
17
+ $installer->startSetup();
18
+
19
+ $installer->getConnection()->addColumn($installer->getTable('sales/quote'),
20
+ 'hubspot_user_token', 'VARCHAR(40) DEFAULT NULL');
21
+ $installer->getConnection()->addColumn($installer->getTable('sales/order'),
22
+ 'hubspot_user_token', 'VARCHAR(40) DEFAULT NULL');
23
+
24
+ $installer->endSetup();
25
+
26
+ Mage::helper('eyehubspot')->generateAccessKeys();
app/etc/modules/Eyemagine_HubSpot.xml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * EYEMAGINE - The leading Magento Solution Partner
5
+ *
6
+ * HubSpot Integration with Magento
7
+ *
8
+ * @author EYEMAGINE <magento@eyemaginetech.com>
9
+ * @category Eyemagine
10
+ * @package Eyemagine_HubSpot
11
+ * @copyright Copyright (c) 2013 EYEMAGINE Technology, LLC (http://www.eyemaginetech.com)
12
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
13
+ */
14
+ -->
15
+ <config>
16
+ <modules>
17
+ <Eyemagine_HubSpot>
18
+ <active>true</active>
19
+ <codePool>community</codePool>
20
+ <depends>
21
+ <Mage_Sales />
22
+ <Mage_Checkout />
23
+ </depends>
24
+ </Eyemagine_HubSpot>
25
+ </modules>
26
+ </config>
package.xml ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Eyemagine_HubSpot</name>
4
+ <version>1.0.1</version>
5
+ <stability>stable</stability>
6
+ <license>Academic Free License (AFL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Integration with Magento and HubSpot which syncs Magento customers with HubSpot&#xD;
10
+ Contacts along with customer attributes, order history, abandoned carts, recent&#xD;
11
+ history, and lifetime statistics.</summary>
12
+ <description>Connecting Magento and HubSpot helps you increase online sales from new customers and increase repeat sales from existing customers. This connector passes all customer data and attributes from your Magento store into HubSpot, including: &#xD;
13
+ &#xD;
14
+ &#x2022; Order Information &#xD;
15
+ &#x2022; Recent Activity &#xD;
16
+ &#x2022; Browser Type &#xD;
17
+ &#x2022; Abandoned Carts &#xD;
18
+ &#x2022; Lifetime Customer Statistics &#xD;
19
+ &#x2022; Average Order Value &#xD;
20
+ &#x2022; Items per Order &#xD;
21
+ and more... &#xD;
22
+ &#xD;
23
+ Specifically, the EYEMAGINE connector empowers you to: &#xD;
24
+ &#xD;
25
+ Automate and personalize your abandoned cart nurturing. &#xD;
26
+ &#xD;
27
+ Personalize your follow-up emails with images, URLs, and names for the most valuable products in any abandoned cart. Using the HubSpot workflow tool, you can send a timed series of personalized emails to your contacts who abandoned a cart, automating the follow-up process and increasing conversions from cart abandoners. &#xD;
28
+ &#xD;
29
+ Automate and personalize your upsell, cross-sell, and reorder emails. &#xD;
30
+ &#xD;
31
+ If you've set up your Magento shopping cart with upsell and related product details for your top sellers, then you can create personalized emails for people who purchase them. Send a timed series that automatically incorporates product images, names, and URLs for upsell and cross-sell items and start marketing like Amazon! &#xD;
32
+ &#xD;
33
+ Laser target your one-off emails and product launches. &#xD;
34
+ &#xD;
35
+ The HubSpot/Magento connector syncs all your historical data for customers, making it possible to create lists of every person who purchased particular products or categories. &#xD;
36
+ Launching a new product? Create a list of everyone who has ever purchased something similar from you, email them about the new line, and watch your engagement rates and sales soar! &#xD;
37
+ Want to send a special deal to your VIPs? You can build a list of everyone whose total order value is above a certain amount. &#xD;
38
+ Want to reengage lapsed customers? You can build a list and email people who haven't purchased in over 30 days, 60 days, 90 days, etc. &#xD;
39
+ Want to see which of your customers are also social media influencers? You can build a list of customers who have more than 10,000 followers on Twitter. The possibilities for personalized engagement are enormous. &#xD;
40
+ &#xD;
41
+ Nurture customers to become repeat customers through Social Inbox and Smart Content. &#xD;
42
+ &#xD;
43
+ HubSpot's Social Inbox and Smart Content tools help you break out of the inbox and personalize customer experience on your website and on social media. Social Inbox will show you (among many other things) a Twitter feed of all your customers, allowing you to hear what they're saying and respond with helpful content and advice, further building your relationship with them. And Smart Content will allow you to change what a visitor sees on your site according to any rules you create. Has someone purchased items in category A? Change your homepage hero image when they visit to automatically feature a product in that category, and transform your site to function like the market leaders in eCommerce. &#xD;
44
+ &#xD;
45
+ Attribute revenue generated to specific marketing channels and campaigns. &#xD;
46
+ &#xD;
47
+ Hubspot's suite of analytics and reporting tools allows you to quickly and easily see which traffic sources or marketing actions turned into revenue for you during any given time period. Generate a report in seconds and email it to anyone in the company--you can even set up recurring reports so everyone can keep track of the company's progress. </description>
48
+ <notes>v.1.0.1: September 5, 2013&#xD;
49
+ - Added controllers to handle product urls and images&#xD;
50
+ - Added redirect to search results page for name when product is not available&#xD;
51
+ - Minor bug fixes</notes>
52
+ <authors><author><name>Andy</name><user>Etemadi</user><email>andy@eyemaginetech.com</email></author></authors>
53
+ <date>2013-09-07</date>
54
+ <time>01:18:53</time>
55
+ <contents><target name="magecommunity"><dir name="Eyemagine"><dir name="HubSpot"><dir name="Block"><dir name="Adminhtml"><dir name="Frontend"><dir name="Button"><file name="Regen.php" hash="31d9a3424a324f1cc6c21412d8046c57"/><file name="._Regen.php" hash="03ec92c7aa4a80b83dab35ae888c547b"/></dir><dir name="Eyemagine"><file name="Info.php" hash="449fdc53d298c9b3bad85ac31e2af96b"/><file name="Support.php" hash="30973b30159141089efc97687126ac8e"/><file name="Version.php" hash="fe79bdeb2695012c35a9b037af94bcc2"/><file name="._Info.php" hash="ce0cf7ed20da8016624555bbb5968191"/><file name="._Support.php" hash="d7af6eacee8bbc688f3be8c5b681b7bb"/><file name="._Version.php" hash="aa0f9e438f113f370a375ec75e45dfdc"/></dir><file name="Utk.php" hash="84cfea35ab594c1bb0f7f2d965ced829"/><file name="._Utk.php" hash="a4c1f2bab0767a83af323589a3181513"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="c73ff88cfe25bd7ae72627f0c107783e"/><file name="._Data.php" hash="9c68a0caf545ef711c3e211076d31607"/></dir><dir name="Model"><file name="Observer.php" hash="571c281b23a692c4bfa2420116edab7d"/><file name="._Observer.php" hash="9f900637bde9683431d89da9174b57fb"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Hubspot"><file name="IndexController.php" hash="c0f81e5933ae380c6deceea8f312104e"/><file name="._IndexController.php" hash="14ef1a094333b6261a631537df4a98b8"/></dir></dir><file name="LinkController.php" hash="1509d308b0d0433777a3121bea9eebc9"/><file name="SyncController.php" hash="f8d554ffa31d0b66ca92cb8bc58fd3f9"/><file name="._SyncController.php" hash="29711776eb99fdc6b890d04af2bc8a3a"/></dir><dir name="etc"><file name="adminhtml.xml" hash="149f8f88c67b1ee6a0fb889253f712c5"/><file name="config.xml" hash="97b120b3678fdbad2ea780c0284f65b1"/><file name="system.xml" hash="9ab8850df7db20a3228fc4a8007ad3e7"/><file name="._config.xml" hash="e10af298d19d562bc2d7bcbe4fa8ea24"/></dir><file name="readme.txt" hash="1a817206bc66e6c2c0402ccb6b9bc6af"/><dir name="sql"><dir name="eyehubspot_setup"><file name="mysql4-install-1.0.0.php" hash="cac9b6905f2b37259d07ad0a2b5ff746"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Eyemagine_HubSpot.xml" hash="5421226b68c90caf4f439005f0d9de70"/></dir></target></contents>
56
+ <compatible/>
57
+ <dependencies><required><php><min>5.3.0</min><max>5.5.0</max></php></required></dependencies>
58
+ </package>