ActiveCampaign_Subscriptions - Version 1.5.5

Version Notes

Fix for bulk export from Magento (import into ActiveCampaign) causing an issue when there is a lot of data. Also modified how we get Magento newsletter subscribers (some versions have it located in another variable).

Download this release

Release Info

Developer ActiveCampaign, Inc.
Extension ActiveCampaign_Subscriptions
Version 1.5.5
Comparing to
See all releases


Code changes from version 1.5.4 to 1.5.5

app/code/community/ActiveCampaign/Subscriptions/activecampaign-api-php/Connector.class.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
 
 
 
3
  class AC_Connector {
4
 
5
  public $url;
@@ -26,21 +28,28 @@ class AC_Connector {
26
  $this->api_key = $api_key;
27
  }
28
 
 
 
 
 
 
29
  public function credentials_test() {
30
  $test_url = "{$this->url}&api_action=user_me&api_output={$this->output}";
31
  $r = $this->curl($test_url);
32
  if (is_object($r) && (int)$r->result_code) {
33
  // successful
34
  $r = true;
35
- }
36
- else {
37
- // failed
38
  $r = false;
39
  }
40
  return $r;
41
  }
42
 
43
- // debug function (nicely outputs variables)
 
 
44
  public function dbg($var, $continue = 0, $element = "pre", $extra = "") {
45
  echo "<" . $element . ">";
46
  echo "Vartype: " . gettype($var) . "\n";
@@ -55,6 +64,13 @@ class AC_Connector {
55
  if (!$continue) exit();
56
  }
57
 
 
 
 
 
 
 
 
58
  public function curl($url, $params_data = array(), $verb = "", $custom_method = "") {
59
  if ($this->version == 1) {
60
  // find the method from the URL.
@@ -145,14 +161,14 @@ class AC_Connector {
145
  $data .= "{$key}=" . urlencode($value) . "&";
146
  }
147
  }
 
148
  }
149
  else {
150
- // not an array - perhaps serialized or JSON string?
151
- // just pass it as data
152
- $data = "data={$params_data}";
153
  }
154
 
155
- $data = rtrim($data, "& ");
156
  curl_setopt($request, CURLOPT_HTTPHEADER, array("Expect:"));
157
  $debug_str1 .= "curl_setopt(\$ch, CURLOPT_HTTPHEADER, array(\"Expect:\"));\n";
158
  if ($this->debug) {
@@ -165,16 +181,22 @@ class AC_Connector {
165
  }
166
  curl_setopt($request, CURLOPT_SSL_VERIFYPEER, false);
167
  curl_setopt($request, CURLOPT_SSL_VERIFYHOST, 0);
168
- curl_setopt($request, CURLOPT_FOLLOWLOCATION, true);
169
  $debug_str1 .= "curl_setopt(\$ch, CURLOPT_SSL_VERIFYPEER, false);\n";
170
  $debug_str1 .= "curl_setopt(\$ch, CURLOPT_SSL_VERIFYHOST, 0);\n";
171
- $debug_str1 .= "curl_setopt(\$ch, CURLOPT_FOLLOWLOCATION, true);\n";
172
  $response = curl_exec($request);
 
 
 
 
173
  $debug_str1 .= "curl_exec(\$ch);\n";
174
  if ($this->debug) {
175
  $this->dbg($response, 1, "pre", "Description: Raw response");
176
  }
177
  $http_code = curl_getinfo($request, CURLINFO_HTTP_CODE);
 
 
 
 
178
  $debug_str1 .= "\$http_code = curl_getinfo(\$ch, CURLINFO_HTTP_CODE);\n";
179
  if ($this->debug) {
180
  $this->dbg($http_code, 1, "pre", "Description: Response HTTP code");
@@ -190,19 +212,20 @@ class AC_Connector {
190
  }
191
  if ( !is_object($object) || (!isset($object->result_code) && !isset($object->succeeded) && !isset($object->success)) ) {
192
  // add methods that only return a string
193
- $string_responses = array("tracking_event_remove", "contact_list", "form_html", "tracking_site_status", "tracking_event_status", "tracking_whitelist", "tracking_log", "tracking_site_list", "tracking_event_list");
194
  if (in_array($method, $string_responses)) {
195
  return $response;
196
  }
197
- // something went wrong
198
- return "An unexpected problem occurred with the API request. Some causes include: invalid JSON or XML returned. Here is the actual response from the server: ---- " . $response;
 
 
199
  }
200
 
201
  if ($this->debug) {
202
  echo "<textarea style='height: 300px; width: 600px;'>" . $debug_str1 . "</textarea>";
203
  }
204
 
205
- header("HTTP/1.1 " . $http_code);
206
  $object->http_code = $http_code;
207
 
208
  if (isset($object->result_code)) {
@@ -222,5 +245,3 @@ class AC_Connector {
222
  }
223
 
224
  }
225
-
226
- ?>
1
  <?php
2
 
3
+ require_once(dirname(__FILE__) . "/exceptions/RequestException.php");
4
+
5
  class AC_Connector {
6
 
7
  public $url;
28
  $this->api_key = $api_key;
29
  }
30
 
31
+ /**
32
+ * @return boolean Whether or not the API credentials are valid.
33
+ *
34
+ * Tests the API URL and key using the user_me API method.
35
+ */
36
  public function credentials_test() {
37
  $test_url = "{$this->url}&api_action=user_me&api_output={$this->output}";
38
  $r = $this->curl($test_url);
39
  if (is_object($r) && (int)$r->result_code) {
40
  // successful
41
  $r = true;
42
+ } else {
43
+ // failed - log it
44
+ $this->curl_response_error = $r;
45
  $r = false;
46
  }
47
  return $r;
48
  }
49
 
50
+ /**
51
+ * Standard debug function (nicely outputs variables).
52
+ */
53
  public function dbg($var, $continue = 0, $element = "pre", $extra = "") {
54
  echo "<" . $element . ">";
55
  echo "Vartype: " . gettype($var) . "\n";
64
  if (!$continue) exit();
65
  }
66
 
67
+ /**
68
+ * @param string url The API URL with the relevant method params.
69
+ * @param array params_data The GET or POST parameters (keys and values).
70
+ * @param string verb The HTTP verb (GET, POST, DELETE, etc).
71
+ * @param string custom_method Any custom method that gets handled differently (such as how we process the response).
72
+ * @return object The response object from the curl request.
73
+ */
74
  public function curl($url, $params_data = array(), $verb = "", $custom_method = "") {
75
  if ($this->version == 1) {
76
  // find the method from the URL.
161
  $data .= "{$key}=" . urlencode($value) . "&";
162
  }
163
  }
164
+ $data = rtrim($data, "& ");
165
  }
166
  else {
167
+ // Pass it as an array into the curl request.
168
+ // This avoids any issue where the transfer might get chunked or broken up due to a large post string/body.
169
+ $data = array("data" => $params_data);
170
  }
171
 
 
172
  curl_setopt($request, CURLOPT_HTTPHEADER, array("Expect:"));
173
  $debug_str1 .= "curl_setopt(\$ch, CURLOPT_HTTPHEADER, array(\"Expect:\"));\n";
174
  if ($this->debug) {
181
  }
182
  curl_setopt($request, CURLOPT_SSL_VERIFYPEER, false);
183
  curl_setopt($request, CURLOPT_SSL_VERIFYHOST, 0);
 
184
  $debug_str1 .= "curl_setopt(\$ch, CURLOPT_SSL_VERIFYPEER, false);\n";
185
  $debug_str1 .= "curl_setopt(\$ch, CURLOPT_SSL_VERIFYHOST, 0);\n";
 
186
  $response = curl_exec($request);
187
+ $curl_error = curl_error($request);
188
+ if (!$response && $curl_error) {
189
+ return $curl_error;
190
+ }
191
  $debug_str1 .= "curl_exec(\$ch);\n";
192
  if ($this->debug) {
193
  $this->dbg($response, 1, "pre", "Description: Raw response");
194
  }
195
  $http_code = curl_getinfo($request, CURLINFO_HTTP_CODE);
196
+ if (!preg_match("/^[2-3][0-9]{2}/", $http_code)) {
197
+ // If not 200 or 300 range HTTP code, return custom error.
198
+ return "HTTP code $http_code returned";
199
+ }
200
  $debug_str1 .= "\$http_code = curl_getinfo(\$ch, CURLINFO_HTTP_CODE);\n";
201
  if ($this->debug) {
202
  $this->dbg($http_code, 1, "pre", "Description: Response HTTP code");
212
  }
213
  if ( !is_object($object) || (!isset($object->result_code) && !isset($object->succeeded) && !isset($object->success)) ) {
214
  // add methods that only return a string
215
+ $string_responses = array("tags_list", "segment_list", "tracking_event_remove", "contact_list", "form_html", "tracking_site_status", "tracking_event_status", "tracking_whitelist", "tracking_log", "tracking_site_list", "tracking_event_list");
216
  if (in_array($method, $string_responses)) {
217
  return $response;
218
  }
219
+
220
+ $requestException = new RequestException;
221
+ $requestException->setFailedMessage($response);
222
+ throw $requestException;
223
  }
224
 
225
  if ($this->debug) {
226
  echo "<textarea style='height: 300px; width: 600px;'>" . $debug_str1 . "</textarea>";
227
  }
228
 
 
229
  $object->http_code = $http_code;
230
 
231
  if (isset($object->result_code)) {
245
  }
246
 
247
  }
 
 
app/code/community/ActiveCampaign/Subscriptions/controllers/Adminhtml/SubscriptionsController.php CHANGED
@@ -1,334 +1,328 @@
1
- <?php
2
-
3
- define("ACTIVECAMPAIGN_URL", "");
4
- define("ACTIVECAMPAIGN_API_KEY", "");
5
- require_once(Mage::getBaseDir() . "/app/code/community/ActiveCampaign/Subscriptions/activecampaign-api-php/ActiveCampaign.class.php");
6
-
7
- class ActiveCampaign_Subscriptions_Adminhtml_SubscriptionsController extends Mage_Adminhtml_Controller_action
8
- {
9
-
10
- protected function _initAction() {
11
- $this->loadLayout()
12
- ->_setActiveMenu('subscriptions/items')
13
- ->_addBreadcrumb(Mage::helper('adminhtml')->__('Connections Manager'), Mage::helper('adminhtml')->__('Connection Manager'));
14
-
15
- return $this;
16
- }
17
-
18
- protected function dbg($var, $continue = 0, $element = "pre")
19
- {
20
- echo "<" . $element . ">";
21
- echo "Vartype: " . gettype($var) . "\n";
22
- if ( is_array($var) )
23
- {
24
- echo "Elements: " . count($var) . "\n\n";
25
- }
26
- elseif ( is_string($var) )
27
- {
28
- echo "Length: " . strlen($var) . "\n\n";
29
- }
30
- print_r($var);
31
- echo "</" . $element . ">";
32
- if (!$continue) exit();
33
- }
34
-
35
- public function indexAction() {
36
- $this->_initAction()
37
- ->renderLayout();
38
- }
39
-
40
- public function editAction() {
41
- $id = $this->getRequest()->getParam('id');
42
- $model = Mage::getModel('subscriptions/subscriptions')->load($id);
43
-
44
- if ($model->getId() || $id == 0) {
45
- $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
46
-
47
- if (!empty($data)) {
48
- $model->setData($data);
49
- }
50
-
51
- Mage::register('subscriptions_data', $model);
52
-
53
- $this->loadLayout();
54
- $this->_setActiveMenu('subscriptions/items');
55
-
56
- //$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Connection Manager'), Mage::helper('adminhtml')->__('Connection Manager'));
57
- //$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));
58
-
59
- $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
60
-
61
- $this->_addContent($this->getLayout()->createBlock('subscriptions/adminhtml_subscriptions_edit'))
62
- ->_addLeft($this->getLayout()->createBlock('subscriptions/adminhtml_subscriptions_edit_tabs'));
63
-
64
- $this->renderLayout();
65
- } else {
66
- Mage::getSingleton('adminhtml/session')->addError(Mage::helper('subscriptions')->__('Item does not exist'));
67
- $this->_redirect('*/*/');
68
- }
69
- }
70
-
71
- public function newAction() {
72
- $this->_forward('edit');
73
- }
74
-
75
- public function saveAction() {
76
-
77
- if ($data = $this->getRequest()->getPost()) {
78
-
79
- //$this->dbg($data);
80
-
81
- /*
82
- if (isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
83
- try {
84
- // Starting upload
85
- $uploader = new Varien_File_Uploader('filename');
86
-
87
- // Any extention would work
88
- $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
89
- $uploader->setAllowRenameFiles(false);
90
-
91
- // Set the file upload mode
92
- // false -> get the file directly in the specified folder
93
- // true -> get the file in the product like folders
94
- // (file.jpg will go in something like /media/f/i/file.jpg)
95
- $uploader->setFilesDispersion(false);
96
-
97
- // We set media as the upload dir
98
- $path = Mage::getBaseDir('media') . DS ;
99
- $uploader->save($path, $_FILES['filename']['name'] );
100
-
101
- } catch (Exception $e) {
102
-
103
- }
104
-
105
- //this way the name is saved in DB
106
- $data['filename'] = $_FILES['filename']['name'];
107
- }
108
- */
109
-
110
- $model = Mage::getModel('subscriptions/subscriptions');
111
-
112
- $api_url = $data["api_url"];
113
- $api_key = $data["api_key"];
114
-
115
- $ac = new ActiveCampaign($api_url, $api_key);
116
-
117
- $test_connection = $ac->credentials_test();
118
-
119
- if (!$test_connection) {
120
- Mage::getSingleton("adminhtml/session")->addError("Invalid API URL or Key. Please check to make sure both values are correct.");
121
- Mage::getSingleton('adminhtml/session')->setFormData($data);
122
- $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
123
- return;
124
- }
125
- else {
126
- // get AC account details
127
- $account = $ac->api("account/view");
128
- $data["account_url"] = $account->account;
129
-
130
- //$data["cdate"] = "NOW()";
131
-
132
- $list_values = $data["list_value"];
133
- $list_ids = array();
134
-
135
- // example (converts to): ["mthommes6.activehosted.com-5","mthommes6.activehosted.com-13"]
136
- $data["list_value"] = json_encode($data["list_value"]);
137
- $data["form_value"] = json_encode($data["form_value"]);
138
-
139
- //$this->dbg($data);
140
-
141
- $model->setData($data)->setId($this->getRequest()->getParam('id'));
142
-
143
- if (isset($data["export_confirm"]) && (int)$data["export_confirm"]) {
144
-
145
- // exporting Newsletter subscribers to ActiveCampaign
146
-
147
- $subscribers_magento = Mage::getResourceModel('newsletter/subscriber_collection')->showStoreInfo()->showCustomerInfo()->getData();
148
- //$this->dbg($subscribers_magento);
149
-
150
- $subscribers_ac = array();
151
-
152
- foreach ($list_values as $acct_listid) {
153
- // IE: mthommes6.activehosted.com-13
154
- $acct_listid = explode("-", $acct_listid);
155
- $list_ids[] = (int)$acct_listid[1];
156
- }
157
-
158
- foreach ($subscribers_magento as $subscriber) {
159
-
160
- $subscribers_ac_ = array(
161
- "email" => $subscriber["subscriber_email"],
162
- "first_name" => $subscriber["customer_firstname"],
163
- "last_name" => $subscriber["customer_lastname"],
164
- );
165
-
166
- // add lists
167
- $p = array();
168
- $status = array();
169
- foreach ($list_ids as $list_id) {
170
- $p[$list_id] = $list_id;
171
- $status[$list_id] = 1;
172
- }
173
-
174
- $subscribers_ac_["p"] = $p;
175
- $subscribers_ac_["status"] = $status;
176
-
177
- //$this->dbg($subscribers_ac_);
178
-
179
- $subscribers_ac[] = $subscribers_ac_;
180
-
181
- }
182
-
183
- //$this->dbg($subscribers_ac);
184
-
185
- $subscribers_ac_serialized = serialize($subscribers_ac);
186
- //$this->dbg($subscribers_ac_serialized);
187
-
188
- $subscriber_request = $ac->api("subscriber/sync?service=magento", $subscribers_ac_serialized);
189
- //$this->dbg($subscriber_request);
190
-
191
- if ((int)$subscriber_request->success) {
192
- // successful request
193
- //$subscriber_id = (int)$subscriber_request->subscriber_id;
194
- }
195
- else {
196
- // request failed
197
- //print_r($subscriber_request->error);
198
- //exit();
199
- }
200
-
201
- }
202
-
203
- try {
204
- if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
205
- $model->setCreatedTime(now())
206
- ->setUpdateTime(now());
207
- } else {
208
- $model->setUpdateTime(now());
209
- }
210
-
211
- $model->save();
212
- Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('subscriptions')->__('Settings were successfully saved'));
213
- Mage::getSingleton('adminhtml/session')->setFormData(false);
214
-
215
- if ($this->getRequest()->getParam('back')) {
216
- $this->_redirect('*/*/edit', array('id' => $model->getId()));
217
- return;
218
- }
219
- $this->_redirect('*/*/');
220
- return;
221
- }
222
- catch (Exception $e) {
223
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
224
- Mage::getSingleton('adminhtml/session')->setFormData($data);
225
- $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
226
- return;
227
- }
228
-
229
- }
230
-
231
- }
232
-
233
- Mage::getSingleton('adminhtml/session')->addError(Mage::helper('subscriptions')->__('Unable to find item to save'));
234
- $this->_redirect('*/*/');
235
- }
236
-
237
- public function deleteAction() {
238
- if( $this->getRequest()->getParam('id') > 0 ) {
239
- try {
240
- $model = Mage::getModel('subscriptions/subscriptions');
241
-
242
- $model->setId($this->getRequest()->getParam('id'))
243
- ->delete();
244
-
245
- Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
246
- $this->_redirect('*/*/');
247
- } catch (Exception $e) {
248
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
249
- $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
250
- }
251
- }
252
- $this->_redirect('*/*/');
253
- }
254
-
255
- public function massDeleteAction() {
256
- $subscriptionsIds = $this->getRequest()->getParam('subscriptions');
257
- if(!is_array($subscriptionsIds)) {
258
- Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
259
- } else {
260
- try {
261
- foreach ($subscriptionsIds as $subscriptionsId) {
262
- $subscriptions = Mage::getModel('subscriptions/subscriptions')->load($subscriptionsId);
263
- $subscriptions->delete();
264
- }
265
- Mage::getSingleton('adminhtml/session')->addSuccess(
266
- Mage::helper('adminhtml')->__(
267
- 'Total of %d record(s) were successfully deleted', count($subscriptionsIds)
268
- )
269
- );
270
- } catch (Exception $e) {
271
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
272
- }
273
- }
274
- $this->_redirect('*/*/index');
275
- }
276
-
277
- public function massStatusAction()
278
- {
279
- $subscriptionsIds = $this->getRequest()->getParam('subscriptions');
280
- if(!is_array($subscriptionsIds)) {
281
- Mage::getSingleton('adminhtml/session')->addError($this->__('Please select item(s)'));
282
- } else {
283
- try {
284
- foreach ($subscriptionsIds as $subscriptionsId) {
285
- $subscriptions = Mage::getSingleton('subscriptions/subscriptions')
286
- ->load($subscriptionsId)
287
- ->setStatus($this->getRequest()->getParam('status'))
288
- ->setIsMassupdate(true)
289
- ->save();
290
- }
291
- $this->_getSession()->addSuccess(
292
- $this->__('Total of %d record(s) were successfully updated', count($subscriptionsIds))
293
- );
294
- } catch (Exception $e) {
295
- $this->_getSession()->addError($e->getMessage());
296
- }
297
- }
298
- $this->_redirect('*/*/index');
299
- }
300
-
301
- public function exportCsvAction()
302
- {
303
- $fileName = 'subscriptions.csv';
304
- $content = $this->getLayout()->createBlock('subscriptions/adminhtml_subscriptions_grid')
305
- ->getCsv();
306
-
307
- $this->_sendUploadResponse($fileName, $content);
308
- }
309
-
310
- public function exportXmlAction()
311
- {
312
- $fileName = 'subscriptions.xml';
313
- $content = $this->getLayout()->createBlock('subscriptions/adminhtml_subscriptions_grid')
314
- ->getXml();
315
-
316
- $this->_sendUploadResponse($fileName, $content);
317
- }
318
-
319
- protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
320
- {
321
- $response = $this->getResponse();
322
- $response->setHeader('HTTP/1.1 200 OK','');
323
- $response->setHeader('Pragma', 'public', true);
324
- $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
325
- $response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
326
- $response->setHeader('Last-Modified', date('r'));
327
- $response->setHeader('Accept-Ranges', 'bytes');
328
- $response->setHeader('Content-Length', strlen($content));
329
- $response->setHeader('Content-type', $contentType);
330
- $response->setBody($content);
331
- $response->sendResponse();
332
- die;
333
- }
334
  }
1
+ <?php
2
+
3
+ define("ACTIVECAMPAIGN_URL", "");
4
+ define("ACTIVECAMPAIGN_API_KEY", "");
5
+ require_once(Mage::getBaseDir() . "/app/code/community/ActiveCampaign/Subscriptions/activecampaign-api-php/ActiveCampaign.class.php");
6
+
7
+ class ActiveCampaign_Subscriptions_Adminhtml_SubscriptionsController extends Mage_Adminhtml_Controller_action
8
+ {
9
+
10
+ protected function _initAction() {
11
+ $this->loadLayout()
12
+ ->_setActiveMenu('subscriptions/items')
13
+ ->_addBreadcrumb(Mage::helper('adminhtml')->__('Connections Manager'), Mage::helper('adminhtml')->__('Connection Manager'));
14
+
15
+ return $this;
16
+ }
17
+
18
+ protected function dbg($var, $continue = 0, $element = "pre")
19
+ {
20
+ echo "<" . $element . ">";
21
+ echo "Vartype: " . gettype($var) . "\n";
22
+ if ( is_array($var) )
23
+ {
24
+ echo "Elements: " . count($var) . "\n\n";
25
+ }
26
+ elseif ( is_string($var) )
27
+ {
28
+ echo "Length: " . strlen($var) . "\n\n";
29
+ }
30
+ print_r($var);
31
+ echo "</" . $element . ">";
32
+ if (!$continue) exit();
33
+ }
34
+
35
+ public function indexAction() {
36
+ $this->_initAction()
37
+ ->renderLayout();
38
+ }
39
+
40
+ public function editAction() {
41
+ $id = $this->getRequest()->getParam('id');
42
+ $model = Mage::getModel('subscriptions/subscriptions')->load($id);
43
+
44
+ if ($model->getId() || $id == 0) {
45
+ $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
46
+
47
+ if (!empty($data)) {
48
+ $model->setData($data);
49
+ }
50
+
51
+ Mage::register('subscriptions_data', $model);
52
+
53
+ $this->loadLayout();
54
+ $this->_setActiveMenu('subscriptions/items');
55
+
56
+ //$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Connection Manager'), Mage::helper('adminhtml')->__('Connection Manager'));
57
+ //$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));
58
+
59
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
60
+
61
+ $this->_addContent($this->getLayout()->createBlock('subscriptions/adminhtml_subscriptions_edit'))
62
+ ->_addLeft($this->getLayout()->createBlock('subscriptions/adminhtml_subscriptions_edit_tabs'));
63
+
64
+ $this->renderLayout();
65
+ } else {
66
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('subscriptions')->__('Item does not exist'));
67
+ $this->_redirect('*/*/');
68
+ }
69
+ }
70
+
71
+ public function newAction() {
72
+ $this->_forward('edit');
73
+ }
74
+
75
+ public function saveAction() {
76
+
77
+ if ($data = $this->getRequest()->getPost()) {
78
+
79
+ //$this->dbg($data);
80
+
81
+ /*
82
+ if (isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
83
+ try {
84
+ // Starting upload
85
+ $uploader = new Varien_File_Uploader('filename');
86
+
87
+ // Any extention would work
88
+ $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
89
+ $uploader->setAllowRenameFiles(false);
90
+
91
+ // Set the file upload mode
92
+ // false -> get the file directly in the specified folder
93
+ // true -> get the file in the product like folders
94
+ // (file.jpg will go in something like /media/f/i/file.jpg)
95
+ $uploader->setFilesDispersion(false);
96
+
97
+ // We set media as the upload dir
98
+ $path = Mage::getBaseDir('media') . DS ;
99
+ $uploader->save($path, $_FILES['filename']['name'] );
100
+
101
+ } catch (Exception $e) {
102
+
103
+ }
104
+
105
+ //this way the name is saved in DB
106
+ $data['filename'] = $_FILES['filename']['name'];
107
+ }
108
+ */
109
+
110
+ $model = Mage::getModel('subscriptions/subscriptions');
111
+
112
+ $api_url = $data["api_url"];
113
+ $api_key = $data["api_key"];
114
+
115
+ $ac = new ActiveCampaign($api_url, $api_key);
116
+
117
+ $test_connection = $ac->credentials_test();
118
+
119
+ if (!$test_connection) {
120
+ Mage::getSingleton("adminhtml/session")->addError("Invalid API URL or Key. Please check to make sure both values are correct.");
121
+ Mage::getSingleton('adminhtml/session')->setFormData($data);
122
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
123
+ return;
124
+ }
125
+ else {
126
+ // get AC account details
127
+ $account = $ac->api("account/view");
128
+ $data["account_url"] = $account->account;
129
+
130
+ //$data["cdate"] = "NOW()";
131
+
132
+ $list_values = $data["list_value"];
133
+ $list_ids = array();
134
+
135
+ // example (converts to): ["mthommes6.activehosted.com-5","mthommes6.activehosted.com-13"]
136
+ $data["list_value"] = json_encode($data["list_value"]);
137
+ $data["form_value"] = json_encode($data["form_value"]);
138
+
139
+ //$this->dbg($data);
140
+
141
+ $model->setData($data)->setId($this->getRequest()->getParam('id'));
142
+
143
+ if (isset($data["export_confirm"]) && (int)$data["export_confirm"]) {
144
+
145
+ // exporting Newsletter contacts to ActiveCampaign
146
+
147
+ // Try a couple different ways to get the contact data.
148
+ // Some versions of Magento may only support one way or another.
149
+ $contacts_magento = Mage::getResourceModel('newsletter/contact_collection');
150
+ if ($contacts_magento) {
151
+ $contacts_magento = $contacts_magento->showStoreInfo()->showCustomerInfo()->getData();
152
+ } else {
153
+ $contacts_magento = Mage::getModel('newsletter/subscriber')->getCollection()->getData();
154
+ }
155
+
156
+ $contacts_ac = array();
157
+
158
+ foreach ($list_values as $acct_listid) {
159
+ // IE: mthommes6.activehosted.com-13
160
+ $acct_listid = explode("-", $acct_listid);
161
+ $list_ids[] = (int)$acct_listid[1];
162
+ }
163
+
164
+ foreach ($contacts_magento as $contact) {
165
+
166
+ $contacts_ac_ = array(
167
+ "email" => $contact["contact_email"],
168
+ "first_name" => $contact["customer_firstname"],
169
+ "last_name" => $contact["customer_lastname"],
170
+ );
171
+
172
+ // add lists
173
+ $p = array();
174
+ $status = array();
175
+ foreach ($list_ids as $list_id) {
176
+ $p[$list_id] = $list_id;
177
+ $status[$list_id] = 1;
178
+ }
179
+
180
+ $contacts_ac_["p"] = $p;
181
+ $contacts_ac_["status"] = $status;
182
+
183
+ //$this->dbg($contacts_ac_);
184
+
185
+ $contacts_ac[] = $contacts_ac_;
186
+
187
+ }
188
+
189
+ //$this->dbg($contacts_ac);
190
+
191
+ $contacts_ac_serialized = serialize($contacts_ac);
192
+
193
+ $contact_request = $ac->api("contact/sync?service=magento", $contacts_ac_serialized);
194
+
195
+ }
196
+
197
+ try {
198
+ if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
199
+ $model->setCreatedTime(now())
200
+ ->setUpdateTime(now());
201
+ } else {
202
+ $model->setUpdateTime(now());
203
+ }
204
+
205
+ $model->save();
206
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('subscriptions')->__('Settings were successfully saved'));
207
+ Mage::getSingleton('adminhtml/session')->setFormData(false);
208
+
209
+ if ($this->getRequest()->getParam('back')) {
210
+ $this->_redirect('*/*/edit', array('id' => $model->getId()));
211
+ return;
212
+ }
213
+ $this->_redirect('*/*/');
214
+ return;
215
+ }
216
+ catch (Exception $e) {
217
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
218
+ Mage::getSingleton('adminhtml/session')->setFormData($data);
219
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
220
+ return;
221
+ }
222
+
223
+ }
224
+
225
+ }
226
+
227
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('subscriptions')->__('Unable to find item to save'));
228
+ $this->_redirect('*/*/');
229
+ }
230
+
231
+ public function deleteAction() {
232
+ if( $this->getRequest()->getParam('id') > 0 ) {
233
+ try {
234
+ $model = Mage::getModel('subscriptions/subscriptions');
235
+
236
+ $model->setId($this->getRequest()->getParam('id'))
237
+ ->delete();
238
+
239
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
240
+ $this->_redirect('*/*/');
241
+ } catch (Exception $e) {
242
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
243
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
244
+ }
245
+ }
246
+ $this->_redirect('*/*/');
247
+ }
248
+
249
+ public function massDeleteAction() {
250
+ $subscriptionsIds = $this->getRequest()->getParam('subscriptions');
251
+ if(!is_array($subscriptionsIds)) {
252
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
253
+ } else {
254
+ try {
255
+ foreach ($subscriptionsIds as $subscriptionsId) {
256
+ $subscriptions = Mage::getModel('subscriptions/subscriptions')->load($subscriptionsId);
257
+ $subscriptions->delete();
258
+ }
259
+ Mage::getSingleton('adminhtml/session')->addSuccess(
260
+ Mage::helper('adminhtml')->__(
261
+ 'Total of %d record(s) were successfully deleted', count($subscriptionsIds)
262
+ )
263
+ );
264
+ } catch (Exception $e) {
265
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
266
+ }
267
+ }
268
+ $this->_redirect('*/*/index');
269
+ }
270
+
271
+ public function massStatusAction()
272
+ {
273
+ $subscriptionsIds = $this->getRequest()->getParam('subscriptions');
274
+ if(!is_array($subscriptionsIds)) {
275
+ Mage::getSingleton('adminhtml/session')->addError($this->__('Please select item(s)'));
276
+ } else {
277
+ try {
278
+ foreach ($subscriptionsIds as $subscriptionsId) {
279
+ $subscriptions = Mage::getSingleton('subscriptions/subscriptions')
280
+ ->load($subscriptionsId)
281
+ ->setStatus($this->getRequest()->getParam('status'))
282
+ ->setIsMassupdate(true)
283
+ ->save();
284
+ }
285
+ $this->_getSession()->addSuccess(
286
+ $this->__('Total of %d record(s) were successfully updated', count($subscriptionsIds))
287
+ );
288
+ } catch (Exception $e) {
289
+ $this->_getSession()->addError($e->getMessage());
290
+ }
291
+ }
292
+ $this->_redirect('*/*/index');
293
+ }
294
+
295
+ public function exportCsvAction()
296
+ {
297
+ $fileName = 'subscriptions.csv';
298
+ $content = $this->getLayout()->createBlock('subscriptions/adminhtml_subscriptions_grid')
299
+ ->getCsv();
300
+
301
+ $this->_sendUploadResponse($fileName, $content);
302
+ }
303
+
304
+ public function exportXmlAction()
305
+ {
306
+ $fileName = 'subscriptions.xml';
307
+ $content = $this->getLayout()->createBlock('subscriptions/adminhtml_subscriptions_grid')
308
+ ->getXml();
309
+
310
+ $this->_sendUploadResponse($fileName, $content);
311
+ }
312
+
313
+ protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
314
+ {
315
+ $response = $this->getResponse();
316
+ $response->setHeader('HTTP/1.1 200 OK','');
317
+ $response->setHeader('Pragma', 'public', true);
318
+ $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
319
+ $response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
320
+ $response->setHeader('Last-Modified', date('r'));
321
+ $response->setHeader('Accept-Ranges', 'bytes');
322
+ $response->setHeader('Content-Length', strlen($content));
323
+ $response->setHeader('Content-type', $contentType);
324
+ $response->setBody($content);
325
+ $response->sendResponse();
326
+ die;
327
+ }
 
 
 
 
 
 
328
  }
app/design/adminhtml/default/default/template/subscriptions/grid.phtml CHANGED
@@ -1,7 +1,7 @@
1
- <div>
2
- <?php
3
- echo $this->getGridHtml();
4
- ?>
5
- </div>
6
-
7
- <p style="color: gray; font-size: 0.9em; margin-top: 25px;">ActiveCampaign extension version 1.5.1. <a href="http://www.activecampaign.com/help/magento-integration/" target="_blank">Get Help</a></p>
1
+ <div>
2
+ <?php
3
+ echo $this->getGridHtml();
4
+ ?>
5
+ </div>
6
+
7
+ <p style="color: gray; font-size: 0.9em; margin-top: 25px;">ActiveCampaign extension version 1.5.5. <a href="http://www.activecampaign.com/help/magento-integration/" target="_blank">Get Help</a></p>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>ActiveCampaign_Subscriptions</name>
4
- <version>1.5.4</version>
5
  <stability>stable</stability>
6
  <license uri="https://www.activecampaign.com/hosted/terms.php">Commercial/Free</license>
7
  <channel>community</channel>
@@ -14,11 +14,11 @@
14
  3. Have existing customer account newsletter modifications updated in ActiveCampaign.&#xD;
15
  &#xD;
16
  4. Bulk export/sync all current newsletter contacts to ActiveCampaign in just two clicks!</description>
17
- <notes>Included missing PHP API library files.</notes>
18
  <authors><author><name>ActiveCampaign, Inc.</name><user>activecampaign</user><email>help@activecampaign.com</email></author></authors>
19
- <date>2016-08-02</date>
20
- <time>19:15:00</time>
21
- <contents><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="subscriptions.xml" hash="825b33cd139c693c88047584959f49ed"/></dir><dir name="template"><dir name="subscriptions"><file name="grid.phtml" hash="5d13aea3c7e678f80aa7e72d5337ae9d"/><file name="list.phtml" hash="70c40a80ee43596da6ae899f14191e91"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="subscriptions.xml" hash="d0a96f68db976ce1919a664228184e9c"/></dir><dir name="template"><dir name="subscriptions"><file name="subscriptions.phtml" hash="2025758bce03d7b9cfe99029050c7be4"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="ActiveCampaign_Subscriptions.xml" hash="14eb3a0c9c06bc847b4e8c6ff691c07d"/></dir></target><target name="magecommunity"><dir name="ActiveCampaign"><dir name="Subscriptions"><dir name="activecampaign-api-php"><file name="Account.class.php" hash="b6426c518978bbfb4ae032cb6ddcc29c"/><file name="ActiveCampaign.class.php" hash="900f5ef0acd4af4105471feda2917aae"/><file name="Auth.class.php" hash="affc478ccf1622400409d8b623230183"/><file name="Campaign.class.php" hash="229ec1cb98add26450f38aa283f40e5f"/><file name="Connector.class.php" hash="6c6ae2daf963e4b8e1f941e73f94b8f0"/><file name="Design.class.php" hash="53104c2ee4f4d54577f385188ba8c9af"/><file name="Form.class.php" hash="2fe24b9e11057e55bb79221fa59a38a7"/><file name="Group.class.php" hash="4712367081b6099bc88440c7ac4c35d0"/><file name="List.class.php" hash="c451709386aaebabeef2d85422e3cf3f"/><file name="Message.class.php" hash="8c072e28994283d0ff7b950df55a6655"/><file name="Contact.class.php" hash="d19e57f06044b5dc98b929b449521a19"/><file name="User.class.php" hash="5a213c94cc6d2a9545856982a38ad26b"/><file name="Webhook.class.php" hash="2933f75823679abd5d178774c8d61682"/><file name="Automation.class.php" hash="f58d2c9ed16fce6c838c50160484363e"/><file name="Subscriber.class.php" hash="94c6b4289e50ea4cf33e98b72e450528"/><file name="Deal.class.php" hash="39b1cacc347584517d4fb145d060082f"/><file name="Tracking.class.php" hash="f84aa5361c44203f90ef14bb08d90a9e"/><file name="Settings.class.php" hash="85a2ffea84086486f5fb9f4325fe701d"/></dir><dir name="Block"><file name="Subscriptions.php" hash="79b032b024a0593188258d4fef3fa733"/><dir name="Adminhtml"><file name="Subscriptions.php" hash="7f9fdec5858ef7a30c1fcd129f13fe67"/><dir name="Subscriptions"><file name="Edit.php" hash="3c464d71d1ad78ae035f810a1248f918"/><file name="Grid.php" hash="b51fc9698c21224488c41826489a8177"/><dir name="Edit"><file name="Form.php" hash="b1eda088b2adf03d69bc1aa3cfb2a00a"/><file name="Tabs.php" hash="4c94ebd27bb6bb0a572131d441afa945"/><dir name="Tab"><file name="Connection.php" hash="230d5a8f70b5de930864b25821290efb"/><file name="Export.php" hash="f65aa906629d6a1b4a17f16014488017"/><file name="List.php" hash="4f2cd4ca088cca5bb2ad1b598c9bc486"/><file name="Form.php" hash="8bf394482cf60f311b8610521888b0d8"/></dir></dir></dir></dir></dir><dir name="controllers"><file name="IndexController.php" hash="f6e27a764745bdb55f17fdca49a7fa81"/><dir name="Adminhtml"><file name="SubscriptionsController.php" hash="edd787979ac83ea735f8c4cd61340c89"/></dir></dir><dir name="etc"><file name="config.xml" hash="40947886dd3611ebeb717de55ef8c240"/></dir><dir name="Helper"><file name="Data.php" hash="4b35d91431328ee595132df575a60a2a"/></dir><dir name="Model"><file name="Observer.php" hash="91aead63e3b6e7d4674b20eb5c2efe96"/><file name="Status.php" hash="c35feda8164009341d289074be5612c0"/><file name="Subscriptions.php" hash="76818326ecfd635e574f704003184300"/><dir name="Mysql4"><file name="Subscriptions.php" hash="d112b3f1194a8bb7f329dacb34161941"/><dir name="Subscriptions"><file name="Collection.php" hash="457890390bd29e72dda81d3088ef5a50"/></dir></dir></dir><dir name="sql"><dir name="subscriptions_setup"><file name="mysql4-install-0.1.0.php" hash="9f756eb38486cc878134f07f22f661c0"/></dir></dir></dir></dir></target></contents>
22
  <compatible/>
23
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><extension><name>curl</name><min>7.19.7</min><max>7.28.0</max></extension></required></dependencies>
24
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>ActiveCampaign_Subscriptions</name>
4
+ <version>1.5.5</version>
5
  <stability>stable</stability>
6
  <license uri="https://www.activecampaign.com/hosted/terms.php">Commercial/Free</license>
7
  <channel>community</channel>
14
  3. Have existing customer account newsletter modifications updated in ActiveCampaign.&#xD;
15
  &#xD;
16
  4. Bulk export/sync all current newsletter contacts to ActiveCampaign in just two clicks!</description>
17
+ <notes>Fix for bulk export from Magento (import into ActiveCampaign) causing an issue when there is a lot of data. Also modified how we get Magento newsletter subscribers (some versions have it located in another variable).</notes>
18
  <authors><author><name>ActiveCampaign, Inc.</name><user>activecampaign</user><email>help@activecampaign.com</email></author></authors>
19
+ <date>2016-11-15</date>
20
+ <time>19:22:54</time>
21
+ <contents><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="subscriptions.xml" hash="825b33cd139c693c88047584959f49ed"/></dir><dir name="template"><dir name="subscriptions"><file name="grid.phtml" hash="7c8a5f92d5cad1c228f36b6113e3e25f"/><file name="list.phtml" hash="70c40a80ee43596da6ae899f14191e91"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="layout"><file name="subscriptions.xml" hash="d0a96f68db976ce1919a664228184e9c"/></dir><dir name="template"><dir name="subscriptions"><file name="subscriptions.phtml" hash="2025758bce03d7b9cfe99029050c7be4"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="ActiveCampaign_Subscriptions.xml" hash="14eb3a0c9c06bc847b4e8c6ff691c07d"/></dir></target><target name="magecommunity"><dir name="ActiveCampaign"><dir name="Subscriptions"><dir name="activecampaign-api-php"><file name="Account.class.php" hash="b6426c518978bbfb4ae032cb6ddcc29c"/><file name="ActiveCampaign.class.php" hash="900f5ef0acd4af4105471feda2917aae"/><file name="Auth.class.php" hash="affc478ccf1622400409d8b623230183"/><file name="Campaign.class.php" hash="229ec1cb98add26450f38aa283f40e5f"/><file name="Connector.class.php" hash="46d650cceec9128394255d050077cbf9"/><file name="Design.class.php" hash="53104c2ee4f4d54577f385188ba8c9af"/><file name="Form.class.php" hash="2fe24b9e11057e55bb79221fa59a38a7"/><file name="Group.class.php" hash="4712367081b6099bc88440c7ac4c35d0"/><file name="List.class.php" hash="c451709386aaebabeef2d85422e3cf3f"/><file name="Message.class.php" hash="8c072e28994283d0ff7b950df55a6655"/><file name="Contact.class.php" hash="d19e57f06044b5dc98b929b449521a19"/><file name="User.class.php" hash="5a213c94cc6d2a9545856982a38ad26b"/><file name="Webhook.class.php" hash="2933f75823679abd5d178774c8d61682"/><file name="Automation.class.php" hash="f58d2c9ed16fce6c838c50160484363e"/><file name="Subscriber.class.php" hash="94c6b4289e50ea4cf33e98b72e450528"/><file name="Deal.class.php" hash="39b1cacc347584517d4fb145d060082f"/><file name="Tracking.class.php" hash="f84aa5361c44203f90ef14bb08d90a9e"/><file name="Settings.class.php" hash="85a2ffea84086486f5fb9f4325fe701d"/></dir><dir name="Block"><file name="Subscriptions.php" hash="79b032b024a0593188258d4fef3fa733"/><dir name="Adminhtml"><file name="Subscriptions.php" hash="7f9fdec5858ef7a30c1fcd129f13fe67"/><dir name="Subscriptions"><file name="Edit.php" hash="3c464d71d1ad78ae035f810a1248f918"/><file name="Grid.php" hash="b51fc9698c21224488c41826489a8177"/><dir name="Edit"><file name="Form.php" hash="b1eda088b2adf03d69bc1aa3cfb2a00a"/><file name="Tabs.php" hash="4c94ebd27bb6bb0a572131d441afa945"/><dir name="Tab"><file name="Connection.php" hash="230d5a8f70b5de930864b25821290efb"/><file name="Export.php" hash="f65aa906629d6a1b4a17f16014488017"/><file name="List.php" hash="4f2cd4ca088cca5bb2ad1b598c9bc486"/><file name="Form.php" hash="8bf394482cf60f311b8610521888b0d8"/></dir></dir></dir></dir></dir><dir name="controllers"><file name="IndexController.php" hash="f6e27a764745bdb55f17fdca49a7fa81"/><dir name="Adminhtml"><file name="SubscriptionsController.php" hash="ccef738ef57683d4f88dab6d36a7b69b"/></dir></dir><dir name="etc"><file name="config.xml" hash="40947886dd3611ebeb717de55ef8c240"/></dir><dir name="Helper"><file name="Data.php" hash="4b35d91431328ee595132df575a60a2a"/></dir><dir name="Model"><file name="Observer.php" hash="91aead63e3b6e7d4674b20eb5c2efe96"/><file name="Status.php" hash="c35feda8164009341d289074be5612c0"/><file name="Subscriptions.php" hash="76818326ecfd635e574f704003184300"/><dir name="Mysql4"><file name="Subscriptions.php" hash="d112b3f1194a8bb7f329dacb34161941"/><dir name="Subscriptions"><file name="Collection.php" hash="457890390bd29e72dda81d3088ef5a50"/></dir></dir></dir><dir name="sql"><dir name="subscriptions_setup"><file name="mysql4-install-0.1.0.php" hash="9f756eb38486cc878134f07f22f661c0"/></dir></dir></dir></dir></target></contents>
22
  <compatible/>
23
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><extension><name>curl</name><min>7.19.7</min><max>7.28.0</max></extension></required></dependencies>
24
  </package>