NL2go_Sync - Version 3.1.08

Version Notes

- compability to enterprise version
- bugifxes

Download this release

Release Info

Developer Newsletter2Go
Extension NL2go_Sync
Version 3.1.08
Comparing to
See all releases


Code changes from version 3.1.05 to 3.1.08

app/code/community/Newsletter2go/Apiextension/Model/Api2/Subscriber.php CHANGED
@@ -1,6 +1,6 @@
1
- <?php
2
-
3
- class Newsletter2go_Apiextension_Model_Api2_Subscriber extends Mage_Api2_Model_Resource
4
- {
5
-
6
  }
1
+ <?php
2
+
3
+ class Newsletter2go_Apiextension_Model_Api2_Subscriber extends Mage_Api2_Model_Resource
4
+ {
5
+
6
  }
app/code/community/Newsletter2go/Apiextension/Model/Api2/Subscriber/Fields.php CHANGED
@@ -1,6 +1,6 @@
1
- <?php
2
-
3
- class Newsletter2go_Apiextension_Model_Api2_Subscriber_Fields extends Mage_Api2_Model_Resource
4
- {
5
-
6
  }
1
+ <?php
2
+
3
+ class Newsletter2go_Apiextension_Model_Api2_Subscriber_Fields extends Mage_Api2_Model_Resource
4
+ {
5
+
6
  }
app/code/community/Newsletter2go/Apiextension/Model/Api2/Subscriber/Fields/Rest/Admin/V1.php CHANGED
@@ -1,59 +1,59 @@
1
- <?php
2
-
3
- class Newsletter2go_Apiextension_Model_Api2_Subscriber_Fields_Rest_Admin_V1 extends Newsletter2go_Apiextension_Model_Api2_Subscriber_Fields
4
- {
5
-
6
- public function getFields()
7
- {
8
- $result = array();
9
-
10
- // $result[] = $this->createArray('totalorders', 'Count of total orders by customer', 'Count of total orders by customer', 'Integer');
11
- // $result[] = $this->createArray('totalrevenue', 'Total revenue of customer', 'Total revenue of customer', 'Float');
12
- // $result[] = $this->createArray('averagecartsize', 'Average cart size', 'Average cart size', 'Float');
13
- // $result[] = $this->createArray('lastorder', 'Last order', 'Last order', 'Date');
14
- $result[] = $this->createArray('entity_id', 'Customer Id.', 'Unique customer number', 'Integer');
15
- $result[] = $this->createArray('website_id', 'Website Id.', 'Unique website number', 'Integer');
16
- $result[] = $this->createArray('email', 'E-mail', 'E-mail address', 'String');
17
- $result[] = $this->createArray('group_id', 'Group Id.', 'Unique group number', 'Integer');
18
- $result[] = $this->createArray('created_at', 'Created at', 'Timestamp of creation', 'Date');
19
- $result[] = $this->createArray('updated_at', 'Updated at', 'Timestamp of last update', 'Date');
20
- $result[] = $this->createArray('dob', 'Date of birth', 'Date of birth', 'Date');
21
- $result[] = $this->createArray('disable_auto_group_change', 'Disable auto group change', 'Disable auto group change', 'Boolean');
22
- $result[] = $this->createArray('created_in', 'Created in', 'Place it was created admin side or by registration', 'String');
23
- $result[] = $this->createArray('suffix', 'Suffix', 'suffix', 'String');
24
- $result[] = $this->createArray('prefix', 'Prefix', 'Prefix', 'String');
25
- $result[] = $this->createArray('firstname', 'Firstname', 'Firstname', 'String');
26
- $result[] = $this->createArray('middlename', 'Middlename', 'middlename', 'String');
27
- $result[] = $this->createArray('lastname', 'Lastname', 'lastname', 'String');
28
- $result[] = $this->createArray('taxvat', 'Tax VAT', 'Tax VAT', 'String');
29
- $result[] = $this->createArray('store_id', 'Store Id.', 'Unique store number', 'Integer');
30
- $result[] = $this->createArray('gender', 'Gender', 'Gender', 'Integer');
31
- $result[] = $this->createArray('is_active', 'Is active', 'Is Active', 'Boolean');
32
- $result[] = $this->createArray('subscriber_status', 'Subscriber status', 'Subscriber status', 'Integer');
33
- $result[] = $this->createArray('default_billing', 'Default billing address', 'Default billing address', 'Object');
34
- $result[] = $this->createArray('default_shipping', 'Default shipping address', 'Default shipping address', 'Object');
35
-
36
- return $result;
37
- }
38
-
39
- protected function createArray($id, $name, $description, $type)
40
- {
41
- return array(
42
- 'id' => $id,
43
- 'name' => $name,
44
- 'description' => $description,
45
- 'type' => $type,
46
- );
47
- }
48
-
49
- /**
50
- * Retrieve list of customers.
51
- *
52
- * @return array
53
- */
54
- protected function _retrieveCollection()
55
- {
56
- return $this->getFields();
57
- }
58
-
59
- }
1
+ <?php
2
+
3
+ class Newsletter2go_Apiextension_Model_Api2_Subscriber_Fields_Rest_Admin_V1 extends Newsletter2go_Apiextension_Model_Api2_Subscriber_Fields
4
+ {
5
+
6
+ public function getFields()
7
+ {
8
+ $result = array();
9
+
10
+ // $result[] = $this->createArray('totalorders', 'Count of total orders by customer', 'Count of total orders by customer', 'Integer');
11
+ // $result[] = $this->createArray('totalrevenue', 'Total revenue of customer', 'Total revenue of customer', 'Float');
12
+ // $result[] = $this->createArray('averagecartsize', 'Average cart size', 'Average cart size', 'Float');
13
+ // $result[] = $this->createArray('lastorder', 'Last order', 'Last order', 'Date');
14
+ $result[] = $this->createArray('entity_id', 'Customer Id.', 'Unique customer number', 'Integer');
15
+ $result[] = $this->createArray('website_id', 'Website Id.', 'Unique website number', 'Integer');
16
+ $result[] = $this->createArray('email', 'E-mail', 'E-mail address', 'String');
17
+ $result[] = $this->createArray('group_id', 'Group Id.', 'Unique group number', 'Integer');
18
+ $result[] = $this->createArray('created_at', 'Created at', 'Timestamp of creation', 'Date');
19
+ $result[] = $this->createArray('updated_at', 'Updated at', 'Timestamp of last update', 'Date');
20
+ $result[] = $this->createArray('dob', 'Date of birth', 'Date of birth', 'Date');
21
+ $result[] = $this->createArray('disable_auto_group_change', 'Disable auto group change', 'Disable auto group change', 'Boolean');
22
+ $result[] = $this->createArray('created_in', 'Created in', 'Place it was created admin side or by registration', 'String');
23
+ $result[] = $this->createArray('suffix', 'Suffix', 'suffix', 'String');
24
+ $result[] = $this->createArray('prefix', 'Prefix', 'Prefix', 'String');
25
+ $result[] = $this->createArray('firstname', 'Firstname', 'Firstname', 'String');
26
+ $result[] = $this->createArray('middlename', 'Middlename', 'middlename', 'String');
27
+ $result[] = $this->createArray('lastname', 'Lastname', 'lastname', 'String');
28
+ $result[] = $this->createArray('taxvat', 'Tax VAT', 'Tax VAT', 'String');
29
+ $result[] = $this->createArray('store_id', 'Store Id.', 'Unique store number', 'Integer');
30
+ $result[] = $this->createArray('gender', 'Gender', 'Gender', 'Integer');
31
+ $result[] = $this->createArray('is_active', 'Is active', 'Is Active', 'Boolean');
32
+ $result[] = $this->createArray('subscriber_status', 'Subscriber status', 'Subscriber status', 'Integer');
33
+ $result[] = $this->createArray('default_billing', 'Default billing address', 'Default billing address', 'Object');
34
+ $result[] = $this->createArray('default_shipping', 'Default shipping address', 'Default shipping address', 'Object');
35
+
36
+ return $result;
37
+ }
38
+
39
+ protected function createArray($id, $name, $description, $type)
40
+ {
41
+ return array(
42
+ 'id' => $id,
43
+ 'name' => $name,
44
+ 'description' => $description,
45
+ 'type' => $type,
46
+ );
47
+ }
48
+
49
+ /**
50
+ * Retrieve list of customers.
51
+ *
52
+ * @return array
53
+ */
54
+ protected function _retrieveCollection()
55
+ {
56
+ return $this->getFields();
57
+ }
58
+
59
+ }
app/code/community/Newsletter2go/Apiextension/Model/Api2/Subscriber/Group.php CHANGED
@@ -1,6 +1,6 @@
1
- <?php
2
-
3
- class Newsletter2go_Apiextension_Model_Api2_Subscriber_Group extends Mage_Api2_Model_Resource
4
- {
5
-
6
  }
1
+ <?php
2
+
3
+ class Newsletter2go_Apiextension_Model_Api2_Subscriber_Group extends Mage_Api2_Model_Resource
4
+ {
5
+
6
  }
app/code/community/Newsletter2go/Apiextension/Model/Api2/Subscriber/Group/Rest/Admin/V1.php CHANGED
@@ -1,37 +1,44 @@
1
- <?php
2
-
3
- class Newsletter2go_Apiextension_Model_Api2_Subscriber_Group_Rest_Admin_V1 extends Newsletter2go_Apiextension_Model_Api2_Subscriber_Group
4
- {
5
-
6
- public function getGroups()
7
- {
8
- return $this->_retrieveCollection();
9
- }
10
-
11
- /**
12
- * Retrieve list of customers.
13
- *
14
- * @return array
15
- */
16
- protected function _retrieveCollection()
17
- {
18
- $result = array();
19
- $groups = Mage::getModel('customer/group')->getCollection()->toArray();
20
-
21
- foreach ($groups['items'] as $group) {
22
- $customersCount = $collection = Mage::getResourceModel('customer/customer_collection')
23
- ->addAttributeToSelect('entity_id')
24
- ->addAttributeToFilter('group_id', $group['customer_group_id'])
25
- ->load()->toArray();
26
-
27
- $result[] = array(
28
- 'id' => $group['customer_group_id'],
29
- 'name' => $group['customer_group_code'],
30
- 'description' => '',
31
- 'count' => count($customersCount),
32
- );
33
- }
34
-
35
- return $result;
36
- }
 
 
 
 
 
 
 
37
  }
1
+ <?php
2
+
3
+ class Newsletter2go_Apiextension_Model_Api2_Subscriber_Group_Rest_Admin_V1 extends Newsletter2go_Apiextension_Model_Api2_Subscriber_Group
4
+ {
5
+
6
+ public function getGroups()
7
+ {
8
+ return $this->_retrieveCollection();
9
+ }
10
+
11
+ /**
12
+ * Retrieve list of customers.
13
+ *
14
+ * @return array
15
+ */
16
+ protected function _retrieveCollection()
17
+ {
18
+ $result = array();
19
+ $groups = Mage::getModel('customer/group')->getCollection()->toArray();
20
+
21
+ foreach ($groups['items'] as $group) {
22
+ $customersCount = $collection = Mage::getResourceModel('customer/customer_collection')
23
+ ->addAttributeToSelect('entity_id')
24
+ ->addAttributeToFilter('group_id', $group['customer_group_id'])
25
+ ->load()->toArray();
26
+
27
+ $result[] = array(
28
+ 'id' => $group['customer_group_id'],
29
+ 'name' => $group['customer_group_code'],
30
+ 'description' => '',
31
+ 'count' => count($customersCount),
32
+ );
33
+ }
34
+
35
+ $result[] = array(
36
+ 'id' => 'subscribers-only',
37
+ 'name' => 'Subscribers only',
38
+ 'description' => 'Customers that are subscribed for newsletter but are not registered.',
39
+ 'count' => 0,
40
+ );
41
+
42
+ return $result;
43
+ }
44
  }
app/code/community/Newsletter2go/Apiextension/Model/Api2/Subscriber/Item.php CHANGED
@@ -1,7 +1,7 @@
1
- <?php
2
-
3
- class Newsletter2go_Apiextension_Model_Api2_Subscriber_Item extends Mage_Api2_Model_Resource
4
- {
5
-
6
- }
7
-
1
+ <?php
2
+
3
+ class Newsletter2go_Apiextension_Model_Api2_Subscriber_Item extends Mage_Api2_Model_Resource
4
+ {
5
+
6
+ }
7
+
app/code/community/Newsletter2go/Apiextension/Model/Api2/Subscriber/Item/Rest/Admin/V1.php CHANGED
File without changes
app/code/community/Newsletter2go/Apiextension/Model/Api2/Subscriber/Rest/Admin/V1.php CHANGED
@@ -1,181 +1,227 @@
1
- <?php
2
-
3
- class Newsletter2go_Apiextension_Model_Api2_Subscriber_Rest_Admin_V1 extends Newsletter2go_Apiextension_Model_Api2_Subscriber
4
- {
5
-
6
- /**
7
- * Retrieve list of customers.
8
- *
9
- * @return array
10
- */
11
- protected function _retrieveCollection()
12
- {
13
- $prefix = Mage::getConfig()->getTablePrefix();
14
-
15
- $group = $this->getRequest()->getParam('group');
16
- $hours = $this->getRequest()->getParam('hours');
17
- $subscribed = $this->getRequest()->getParam('subscribed');
18
- $fields = $this->getRequest()->getParam('fields');
19
- $limit = $this->getRequest()->getParam('limit');
20
- $offset = $this->getRequest()->getParam('offset');
21
- $email_str = $this->getRequest()->getParam('emails');
22
- $debug = $this->getRequest()->getParam('debug');
23
- $emails = null;
24
- try {
25
- if (strlen($email_str) > 0) {
26
- $emails = explode(',', $email_str);
27
- }
28
-
29
-
30
- if ($subscribed) {
31
- $subscribedCond = $prefix . 'newsletter_subscriber.subscriber_status = ' .
32
- Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED;
33
- } else {
34
- $subscribedCond = 1;
35
- }
36
-
37
- $fieldsCond = $this->arrangeFields($fields);
38
- $collection = Mage::getResourceModel('customer/customer_collection');
39
- $collection->getSelect()->reset(Zend_Db_Select::COLUMNS);
40
- $collection->getSelect()->columns($fieldsCond['select']);
41
-
42
- //Join with subscribers
43
- if ($subscribed || !empty($fieldsCond['subs'])) {
44
- $collection->getSelect()
45
- ->joinLeft($prefix . 'newsletter_subscriber',
46
- 'e.entity_id =' . $prefix . 'newsletter_subscriber.customer_id', $fieldsCond['subs'])
47
- ->where($subscribedCond);
48
- }
49
-
50
- //Join with order
51
- // if (!empty($fieldsCond['order'])) {
52
- // $collection->getSelect()
53
- // ->joinLeft($prefix . 'sales_flat_order', 'e.entity_id =' . $prefix . 'sales_flat_order.customer_id',
54
- // $fieldsCond['order']);
55
- // }
56
-
57
- if ($group !== null) {
58
- $collection->addAttributeToFilter('group_id', $group);
59
- }
60
- if ($emails !== null) {
61
- $collection->addAttributeToFilter('email', array('in' => $emails));
62
- }
63
-
64
- if ($hours && is_numeric($hours)) {
65
- $ts = date('Y-m-d H:i:s', time() - 3600 * $hours);
66
- $collection->addAttributeToFilter('updated_at', array('gteq' => $ts));
67
- }
68
-
69
- $collection->addAttributeToSelect($fieldsCond['custom']);
70
- $collection->getSelect()->group('e.entity_id');
71
- if ($limit) {
72
- $offset = $offset ?: 0;
73
- $collection->getSelect()->limit($limit, $offset);
74
- }
75
-
76
- $customers = $collection->load()->toArray($fields);
77
-
78
- foreach ($customers as &$customer) {
79
- if (isset($customer['default_shipping'])) {
80
- $customer['default_shipping'] =
81
- json_encode(Mage::getModel('customer/address')->load($customer['default_shipping'])->toArray());
82
- }
83
-
84
- if (isset($customer['default_billing'])) {
85
- $customer['default_billing'] =
86
- json_encode(Mage::getModel('customer/address')->load($customer['default_billing'])->toArray());
87
- }
88
- }
89
-
90
- return array('items' => array($customers));
91
- }catch(Exception $e){
92
- if($debug == 1){
93
- echo $e->getMessage();
94
- echo $e->getTraceAsString();
95
- die();
96
- }else{
97
- return array('errorcode'=> 'int-0-600', 'message' => 'an error occurred: '. $e->getMessage() );
98
- }
99
- }
100
- }
101
-
102
- /**
103
- * @param array $someArray
104
- * @return string
105
- */
106
- protected function _update($someArray)
107
- {
108
- $subs = Mage::getModel('newsletter/subscriber')->loadByEmail($this->getRequest()->getParam('email'));
109
- try {
110
- if ($subs !== false && $subs->getData() != null) {
111
- $subs->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED);
112
- $subs->save();
113
- }
114
- } catch (Mage_Core_Exception $e) {
115
- $this->_critical($e->getMessage(), Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR);
116
- } catch (Exception $e) {
117
- $this->_critical(self::RESOURCE_INTERNAL_ERROR);
118
- }
119
- }
120
-
121
- private function arrangeFields(&$fields)
122
- {
123
- $prefix = Mage::getConfig()->getTablePrefix();
124
- $result = array(
125
- 'subs' => array(),
126
- 'custom' => array(),
127
- 'order' => array(),
128
- 'select' => array('e.entity_id'),
129
- );
130
- if (!$fields) {
131
- $fields = Mage::getModel('apiextension/api2_subscriber_fields_rest_admin_v1')->getFields();
132
- $fieldsArray = array();
133
- foreach ($fields as $field) {
134
- $fieldsArray[] = $field['id'];
135
- }
136
- } else {
137
- $fieldsArray = explode(',', $fields);
138
- }
139
-
140
- $fields = $fieldsArray;
141
- foreach ($fieldsArray as $field) {
142
- switch ($field) {
143
- case 'subscriber_status':
144
- $result['subs'][] = $prefix . 'newsletter_subscriber.' . $field;
145
- break;
146
- // case 'totalorders':
147
- // $result['order'][] = 'count(' . $prefix . 'sales_flat_order.base_grand_total) as totalorders';
148
- // break;
149
- // case 'totalrevenue':
150
- // $result['order'][] = 'sum(' . $prefix . 'sales_flat_order.base_grand_total) as totalrevenue';
151
- // break;
152
- // case 'averagecartsize':
153
- // $result['order'][] = 'avg(' . $prefix . 'sales_flat_order.base_grand_total) as averagecartsize';
154
- // break;
155
- // case 'lastorder':
156
- // $result['order'][] = 'max(' . $prefix . 'sales_flat_order.created_at) as lastorder';
157
- // break;
158
- case 'entity_type_id':
159
- case 'attribute_set_id':
160
- case 'website_id':
161
- case 'email':
162
- case 'group_id':
163
- case 'increment_id':
164
- case 'store_id':
165
- case 'created_at':
166
- case 'updated_at':
167
- case 'is_active':
168
- case 'disable_auto_group_change':
169
- $result['select'][] = 'e.' . $field;
170
- break;
171
- case 'entity_id':
172
- break;
173
- default:
174
- $result['custom'][] = $field;
175
- }
176
- }
177
-
178
- return $result;
179
- }
180
-
181
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Newsletter2go_Apiextension_Model_Api2_Subscriber_Rest_Admin_V1 extends Newsletter2go_Apiextension_Model_Api2_Subscriber
4
+ {
5
+
6
+ /**
7
+ * Retrieve list of customers.
8
+ *
9
+ * @return array
10
+ */
11
+ protected function _retrieveCollection()
12
+ {
13
+ $prefix = Mage::getConfig()->getTablePrefix();
14
+
15
+ $group = $this->getRequest()->getParam('group');
16
+ $hours = $this->getRequest()->getParam('hours');
17
+ $subscribed = $this->getRequest()->getParam('subscribed');
18
+ $fields = $this->getRequest()->getParam('fields');
19
+ $limit = $this->getRequest()->getParam('limit');
20
+ $offset = $this->getRequest()->getParam('offset');
21
+ $email_str = $this->getRequest()->getParam('emails');
22
+ $debug = $this->getRequest()->getParam('debug');
23
+ $emails = null;
24
+
25
+ try {
26
+ if (strlen($email_str) > 0) {
27
+ $emails = explode(',', $email_str);
28
+ }
29
+
30
+ if ($group == 'subscribers-only') {
31
+ $subscribers = $this->getSubscribersOnly($subscribed, $limit, $offset, $fields, $emails);
32
+ return array('items' => array($subscribers['items']));
33
+ }
34
+
35
+ $subscribedCond = 1;
36
+ if ($subscribed) {
37
+ $subscribedCond = $prefix . 'newsletter_subscriber.subscriber_status = ' .
38
+ Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED;
39
+ }
40
+
41
+ $fieldsCond = $this->arrangeFields($fields);
42
+ $collection = Mage::getResourceModel('customer/customer_collection');
43
+ $collection->getSelect()->reset(Zend_Db_Select::COLUMNS);
44
+ $collection->getSelect()->columns($fieldsCond['select']);
45
+
46
+ //Join with subscribers
47
+ if ($subscribed || !empty($fieldsCond['subs'])) {
48
+ $collection->getSelect()
49
+ ->joinLeft($prefix . 'newsletter_subscriber',
50
+ 'e.entity_id =' . $prefix . 'newsletter_subscriber.customer_id', $fieldsCond['subs'])
51
+ ->where($subscribedCond);
52
+ }
53
+
54
+ //Join with order
55
+ // if (!empty($fieldsCond['order'])) {
56
+ // $collection->getSelect()
57
+ // ->joinLeft($prefix . 'sales_flat_order', 'e.entity_id =' . $prefix . 'sales_flat_order.customer_id',
58
+ // $fieldsCond['order']);
59
+ // }
60
+
61
+ if ($group !== null) {
62
+ $collection->addAttributeToFilter('group_id', $group);
63
+ }
64
+ if ($emails !== null) {
65
+ $collection->addAttributeToFilter('email', array('in' => $emails));
66
+ }
67
+
68
+ if ($hours && is_numeric($hours)) {
69
+ $ts = date('Y-m-d H:i:s', time() - 3600 * $hours);
70
+ $collection->addAttributeToFilter('updated_at', array('gteq' => $ts));
71
+ }
72
+
73
+ $collection->addAttributeToSelect($fieldsCond['custom']);
74
+ $collection->getSelect()->group('e.entity_id');
75
+ if ($limit) {
76
+ $offset = $offset ? $offset : 0;
77
+ $collection->getSelect()->limit($limit, $offset);
78
+ }
79
+
80
+ $customers = $collection->load()->toArray($fields);
81
+
82
+ foreach ($customers as &$customer) {
83
+ if (isset($customer['default_shipping'])) {
84
+ $customer['default_shipping'] =
85
+ json_encode(Mage::getModel('customer/address')->load($customer['default_shipping'])->toArray());
86
+ }
87
+
88
+ if (isset($customer['default_billing'])) {
89
+ $customer['default_billing'] =
90
+ json_encode(Mage::getModel('customer/address')->load($customer['default_billing'])->toArray());
91
+ }
92
+ }
93
+
94
+ return array('items' => array($customers));
95
+ }catch(Exception $e){
96
+ if($debug == 1){
97
+ echo $e->getMessage();
98
+ echo $e->getTraceAsString();
99
+ die();
100
+ }else{
101
+ return array('errorcode'=> 'int-0-600', 'message' => 'an error occurred: '. $e->getMessage() );
102
+ }
103
+ }
104
+ }
105
+
106
+ /**
107
+ * @param array $data
108
+ * @return string
109
+ */
110
+ protected function _update($data)
111
+ {
112
+ $email = $this->getRequest()->getParam('email');
113
+ $status = $this->getRequest()->getParam('status');
114
+ /** @var Mage_Newsletter_Model_Subscriber $subs */
115
+ $subs = Mage::getModel('newsletter/subscriber');
116
+ $subs = $subs->loadByEmail($email);
117
+ try {
118
+ if ($subs !== false && $subs->getData() != null) {
119
+ $status = $status == 0 ? Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED :
120
+ Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED;
121
+ $subs->setStatus($status);
122
+ $subs->save();
123
+ } else {
124
+ $this->getResponse()->setHttpResponseCode(400);
125
+ }
126
+ } catch (Mage_Core_Exception $e) {
127
+ $this->_critical($e->getMessage(), Mage_Api2_Model_Server::HTTP_INTERNAL_ERROR);
128
+ } catch (Exception $e) {
129
+ $this->_critical(self::RESOURCE_INTERNAL_ERROR);
130
+ }
131
+ }
132
+
133
+ private function arrangeFields(&$fields)
134
+ {
135
+ $prefix = Mage::getConfig()->getTablePrefix();
136
+ $result = array(
137
+ 'subs' => array(),
138
+ 'custom' => array(),
139
+ 'order' => array(),
140
+ 'select' => array('e.entity_id'),
141
+ );
142
+ if (!$fields) {
143
+ $fields = Mage::getModel('apiextension/api2_subscriber_fields_rest_admin_v1')->getFields();
144
+ $fieldsArray = array();
145
+ foreach ($fields as $field) {
146
+ $fieldsArray[] = $field['id'];
147
+ }
148
+ } else {
149
+ $fieldsArray = explode(',', $fields);
150
+ }
151
+
152
+ $fields = $fieldsArray;
153
+ foreach ($fieldsArray as $field) {
154
+ switch ($field) {
155
+ case 'subscriber_status':
156
+ $result['subs'][] = $prefix . 'newsletter_subscriber.' . $field;
157
+ break;
158
+ // case 'totalorders':
159
+ // $result['order'][] = 'count(' . $prefix . 'sales_flat_order.base_grand_total) as totalorders';
160
+ // break;
161
+ // case 'totalrevenue':
162
+ // $result['order'][] = 'sum(' . $prefix . 'sales_flat_order.base_grand_total) as totalrevenue';
163
+ // break;
164
+ // case 'averagecartsize':
165
+ // $result['order'][] = 'avg(' . $prefix . 'sales_flat_order.base_grand_total) as averagecartsize';
166
+ // break;
167
+ // case 'lastorder':
168
+ // $result['order'][] = 'max(' . $prefix . 'sales_flat_order.created_at) as lastorder';
169
+ // break;
170
+ case 'entity_type_id':
171
+ case 'attribute_set_id':
172
+ case 'website_id':
173
+ case 'email':
174
+ case 'group_id':
175
+ case 'increment_id':
176
+ case 'store_id':
177
+ case 'created_at':
178
+ case 'updated_at':
179
+ case 'is_active':
180
+ case 'disable_auto_group_change':
181
+ $result['select'][] = 'e.' . $field;
182
+ break;
183
+ case 'entity_id':
184
+ break;
185
+ default:
186
+ $result['custom'][] = $field;
187
+ }
188
+ }
189
+
190
+ return $result;
191
+ }
192
+
193
+ /**
194
+ * @param $subscribed
195
+ * @param $limit
196
+ * @param $offset
197
+ * @param $fields
198
+ * @param $emails
199
+ * @return array
200
+ */
201
+ private function getSubscribersOnly($subscribed, $limit, $offset, $fields, $emails)
202
+ {
203
+ /** @var Mage_Newsletter_Model_Resource_Subscriber_Collection $collection */
204
+ $collection = Mage::getResourceModel('newsletter/subscriber_collection');
205
+ $collection->addFieldToFilter('main_table.customer_id', 0);
206
+ $collection->addFieldToSelect('subscriber_email', 'email');
207
+ $collection->addFieldToSelect('store_id');
208
+ $collection->addFieldToSelect('subscriber_status');
209
+
210
+ if ($subscribed) {
211
+ $collection->addFieldToFilter('main_table.subscriber_status', Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
212
+ }
213
+
214
+ if (!empty($emails)) {
215
+ $collection->addFieldToFilter('main_table.subscriber_email', array('in' => $emails));
216
+ }
217
+
218
+ if ($limit) {
219
+ $offset = $offset ? $offset : 0;
220
+ $collection->getSelect()->limit($limit, $offset);
221
+ }
222
+
223
+ $customers = $collection->load()->toArray(strlen($fields) > 0 ? explode(',', $fields) : $fields);
224
+
225
+ return $customers;
226
+ }
227
+ }
app/code/community/Newsletter2go/Apiextension/Model/Api2/Subscriber/Store.php CHANGED
@@ -1,6 +1,6 @@
1
- <?php
2
-
3
- class Newsletter2go_Apiextension_Model_Api2_Subscriber_Store extends Mage_Api2_Model_Resource
4
- {
5
-
6
  }
1
+ <?php
2
+
3
+ class Newsletter2go_Apiextension_Model_Api2_Subscriber_Store extends Mage_Api2_Model_Resource
4
+ {
5
+
6
  }
app/code/community/Newsletter2go/Apiextension/Model/Api2/Subscriber/Store/Rest/Admin/V1.php CHANGED
@@ -1,29 +1,29 @@
1
- <?php
2
-
3
- class Newsletter2go_Apiextension_Model_Api2_Subscriber_Store_Rest_Admin_V1 extends Newsletter2go_Apiextension_Model_Api2_Subscriber_Store
4
- {
5
- /**
6
- * Retrieve list of customers.
7
- *
8
- * @return mixed
9
- */
10
- protected function _retrieveCollection()
11
- {
12
- $iDefaultStoreId = Mage::app()
13
- ->getWebsite(true)
14
- ->getDefaultGroup()
15
- ->getDefaultStoreId();
16
- $result = array();
17
- $stores = Mage::app()->getStores();
18
- foreach ($stores as $store) {
19
-
20
- $tmp = $store->toArray();
21
-
22
- $tmp['id'] = $tmp['store_id'];
23
- $tmp['default'] = ($tmp['store_id'] == $iDefaultStoreId ? 1 : 0);
24
-
25
- $result[] = $tmp;
26
- }
27
- return $result;
28
- }
29
  }
1
+ <?php
2
+
3
+ class Newsletter2go_Apiextension_Model_Api2_Subscriber_Store_Rest_Admin_V1 extends Newsletter2go_Apiextension_Model_Api2_Subscriber_Store
4
+ {
5
+ /**
6
+ * Retrieve list of customers.
7
+ *
8
+ * @return mixed
9
+ */
10
+ protected function _retrieveCollection()
11
+ {
12
+ $iDefaultStoreId = Mage::app()
13
+ ->getWebsite(true)
14
+ ->getDefaultGroup()
15
+ ->getDefaultStoreId();
16
+ $result = array();
17
+ $stores = Mage::app()->getStores();
18
+ foreach ($stores as $store) {
19
+
20
+ $tmp = $store->toArray();
21
+
22
+ $tmp['id'] = $tmp['store_id'];
23
+ $tmp['default'] = ($tmp['store_id'] == $iDefaultStoreId ? 1 : 0);
24
+
25
+ $result[] = $tmp;
26
+ }
27
+ return $result;
28
+ }
29
  }
app/code/community/Newsletter2go/Apiextension/Model/Api2/Subscriber/Version.php CHANGED
@@ -1,7 +1,7 @@
1
- <?php
2
-
3
- class Newsletter2go_Apiextension_Model_Api2_Subscriber_Version extends Mage_Api2_Model_Resource
4
- {
5
-
6
- }
7
-
1
+ <?php
2
+
3
+ class Newsletter2go_Apiextension_Model_Api2_Subscriber_Version extends Mage_Api2_Model_Resource
4
+ {
5
+
6
+ }
7
+
app/code/community/Newsletter2go/Apiextension/Model/Api2/Subscriber/Version/Rest/Admin/V1.php CHANGED
File without changes
app/code/community/Newsletter2go/Apiextension/etc/api2.xml CHANGED
@@ -29,7 +29,7 @@
29
  <action_type>collection</action_type>
30
  </route_collection>
31
  <route_entity>
32
- <route>/n2go/subscribers/:email</route>
33
  <action_type>entity</action_type>
34
  </route_entity>
35
  </routes>
29
  <action_type>collection</action_type>
30
  </route_collection>
31
  <route_entity>
32
+ <route>/n2go/subscribers/:email/status/:status</route>
33
  <action_type>entity</action_type>
34
  </route_entity>
35
  </routes>
app/code/community/Newsletter2go/Apiextension/etc/config.xml CHANGED
@@ -3,7 +3,7 @@
3
  <config>
4
  <modules>
5
  <Newsletter2go_Apiextension>
6
- <version>0.1.0</version>
7
  </Newsletter2go_Apiextension>
8
  </modules>
9
  <global>
3
  <config>
4
  <modules>
5
  <Newsletter2go_Apiextension>
6
+ <version>3.1.07</version>
7
  </Newsletter2go_Apiextension>
8
  </modules>
9
  <global>
app/etc/modules/Newsletter2go_Apiextension.xml CHANGED
@@ -1,10 +1,10 @@
1
- <?xml version="1.0"?>
2
-
3
- <config>
4
- <modules>
5
- <Newsletter2go_Apiextension>
6
- <active>true</active>
7
- <codePool>community</codePool>
8
- </Newsletter2go_Apiextension>
9
- </modules>
10
  </config>
1
+ <?xml version="1.0"?>
2
+
3
+ <config>
4
+ <modules>
5
+ <Newsletter2go_Apiextension>
6
+ <active>true</active>
7
+ <codePool>community</codePool>
8
+ </Newsletter2go_Apiextension>
9
+ </modules>
10
  </config>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>NL2go_Sync</name>
4
- <version>3.1.05</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
@@ -13,8 +13,8 @@ Additionally, you can easily retrieve all item data including description, price
13
  <notes>- compability to enterprise version&#xD;
14
  - bugifxes</notes>
15
  <authors><author><name>Newsletter2Go</name><user>Newsletter2Go</user><email>info@newsletter2go.de</email></author></authors>
16
- <date>2015-09-21</date>
17
- <time>12:18:01</time>
18
  <contents><target name="magecommunity"><dir name="Newsletter2go"><dir name="Apiextension"><dir name="Model"><dir name="Api2"><dir name="Subscriber"><dir name="Fields"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="82f9a23f674b0cf49907e36962a95e22"/></dir></dir></dir><file name="Fields.php" hash="13050c3aebf6e555d3d7b3abfb89e1ca"/><dir name="Group"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="3e193c7f5dfdc41ad1fbc7685598894e"/></dir></dir></dir><file name="Group.php" hash="d974f58986cf34c6dbc78240a8806187"/><dir name="Item"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="24d460f494dd7c8bb560178d09e60872"/></dir></dir></dir><file name="Item.php" hash="2511179aaf3bb819d905ea25842e4f7a"/><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="b92fc116b731ae54104e29bea321e247"/></dir></dir><dir name="Store"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="280c881d20d84db8842b644740122bc7"/></dir></dir></dir><file name="Store.php" hash="a98c4f907188f0debc8c560926d7e3b2"/><dir name="Version"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="107e7425338eca6c95a4980556cf08b0"/></dir></dir></dir><file name="Version.php" hash="28480d5fe6b8ff8ddb3512340d922c44"/></dir><file name="Subscriber.php" hash="fa4e32b55be186db846f21b59a03e0c2"/></dir></dir><dir name="etc"><file name="api2.xml" hash="e817575cad28cb1b240ec598a0e51d17"/><file name="config.xml" hash="44da06f11a3c22784b81e38884c87153"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Newsletter2go_Apiextension.xml" hash="712b9170d5970e2d7c9f46b8c1cd6569"/></dir></target></contents>
19
  <compatible/>
20
  <dependencies><required><php><min>5.3.00</min><max>6.0.00</max></php></required></dependencies>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>NL2go_Sync</name>
4
+ <version>3.1.07</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
13
  <notes>- compability to enterprise version&#xD;
14
  - bugifxes</notes>
15
  <authors><author><name>Newsletter2Go</name><user>Newsletter2Go</user><email>info@newsletter2go.de</email></author></authors>
16
+ <date>2016-02-29</date>
17
+ <time>10:00:00</time>
18
  <contents><target name="magecommunity"><dir name="Newsletter2go"><dir name="Apiextension"><dir name="Model"><dir name="Api2"><dir name="Subscriber"><dir name="Fields"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="82f9a23f674b0cf49907e36962a95e22"/></dir></dir></dir><file name="Fields.php" hash="13050c3aebf6e555d3d7b3abfb89e1ca"/><dir name="Group"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="3e193c7f5dfdc41ad1fbc7685598894e"/></dir></dir></dir><file name="Group.php" hash="d974f58986cf34c6dbc78240a8806187"/><dir name="Item"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="24d460f494dd7c8bb560178d09e60872"/></dir></dir></dir><file name="Item.php" hash="2511179aaf3bb819d905ea25842e4f7a"/><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="b92fc116b731ae54104e29bea321e247"/></dir></dir><dir name="Store"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="280c881d20d84db8842b644740122bc7"/></dir></dir></dir><file name="Store.php" hash="a98c4f907188f0debc8c560926d7e3b2"/><dir name="Version"><dir name="Rest"><dir name="Admin"><file name="V1.php" hash="107e7425338eca6c95a4980556cf08b0"/></dir></dir></dir><file name="Version.php" hash="28480d5fe6b8ff8ddb3512340d922c44"/></dir><file name="Subscriber.php" hash="fa4e32b55be186db846f21b59a03e0c2"/></dir></dir><dir name="etc"><file name="api2.xml" hash="e817575cad28cb1b240ec598a0e51d17"/><file name="config.xml" hash="44da06f11a3c22784b81e38884c87153"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Newsletter2go_Apiextension.xml" hash="712b9170d5970e2d7c9f46b8c1cd6569"/></dir></target></contents>
19
  <compatible/>
20
  <dependencies><required><php><min>5.3.00</min><max>6.0.00</max></php></required></dependencies>