NL2go_Sync - Version 1.1.0

Version Notes

Added support for 2- way synchronisation of unsubscribes over Magento accounts and the Newsletter2Go unsubscribe link

Download this release

Release Info

Developer Magento Core Team
Extension NL2go_Sync
Version 1.1.0
Comparing to
See all releases


Code changes from version 1.0.4 to 1.1.0

app/code/local/NL2go/Sync/Model/Newsletter/Api.php CHANGED
@@ -13,4 +13,6 @@ class NL2go_Sync_Model_Newsletter_Api extends Mage_Api_Model_Resource_Abstract
13
  public function getSubscribers()
14
  {
15
  }
 
 
16
  }
13
  public function getSubscribers()
14
  {
15
  }
16
+ public function setSubscriptionStatus($mail, $status){
17
+ }
18
  }
app/code/local/NL2go/Sync/Model/Newsletter/Api/V2.php CHANGED
@@ -10,7 +10,67 @@
10
 
11
  class Nl2go_Sync_Model_Newsletter_Api_V2 extends Mage_Api_Model_Resource_Abstract
12
  {
13
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  /**
15
  * Return subscriber list with the customer info
16
  *
@@ -98,10 +158,14 @@ class Nl2go_Sync_Model_Newsletter_Api_V2 extends Mage_Api_Model_Resource_Abstrac
98
  // it is impossible to filter subscribers by date, because there are cases when the dates are NULL
99
  // get all subscribers
100
 
 
 
 
 
 
101
  $query = "SELECT * FROM newsletter_subscriber ".
102
- // " WHERE subscriber_status=".Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED.
103
- // " AND customer_id=0 AND (change_status_at IS NULL OR change_status_at BETWEEN TIMESTAMP(DATE_SUB(NOW(), INTERVAL ".$hours." HOUR)) AND TIMESTAMP(NOW()))";
104
  " WHERE customer_id=0 AND (change_status_at IS NULL OR change_status_at BETWEEN TIMESTAMP(DATE_SUB(NOW(), INTERVAL ".$hours." HOUR)) AND TIMESTAMP(NOW()))";
 
105
 
106
  /* Execute the query and store the results in $results */
107
  $results = $readConnection->fetchAll($query);
@@ -129,9 +193,6 @@ class Nl2go_Sync_Model_Newsletter_Api_V2 extends Mage_Api_Model_Resource_Abstrac
129
  " AND customer_id!=0";
130
  } else {
131
  $query = "SELECT * FROM newsletter_subscriber ".
132
- // " WHERE subscriber_status=".Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED.
133
- // " AND customer_id IN(".
134
- // Unsubscribes over Magento user accounts are being synchronized - changes
135
  " WHERE customer_id IN(".
136
  "SELECT entity_id FROM customer_entity ".
137
  " WHERE created_at BETWEEN TIMESTAMP(DATE_SUB(NOW(), INTERVAL ".$hours." HOUR)) AND TIMESTAMP(NOW()) OR ".
10
 
11
  class Nl2go_Sync_Model_Newsletter_Api_V2 extends Mage_Api_Model_Resource_Abstract
12
  {
13
+ /**
14
+ * Update subsciber's status
15
+ *
16
+ * @param string $email
17
+ * @param int $status
18
+ * @return int
19
+ */
20
+ public function setSubscriptionStatus($mail, $status){
21
+
22
+ switch ($status) {
23
+ case 1:
24
+ $status = Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED;
25
+ break;
26
+ case 2:
27
+ $status = Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE;
28
+ break;
29
+ case 3:
30
+ $status = Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED;
31
+ break;
32
+ case 4:
33
+ $status = Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED;
34
+ break;
35
+ default:
36
+ $res = 400;
37
+ return $res;
38
+ }
39
+
40
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($mail);
41
+
42
+ $subscrId = $subscriber->getId();
43
+ if(empty($subscrId)){
44
+ $res = 204;
45
+ return $res;
46
+ }
47
+
48
+ # change status and save
49
+ // $subscriber->setStatus($status);
50
+ // $subscriber->save();
51
+
52
+ // I decided to use direct sql requests, for the cases, when somebody want to create and intercept
53
+ // event for changes of sucscribers
54
+ /**
55
+ * Get the resource model/write connection/table name
56
+ */
57
+ $resource = Mage::getSingleton('core/resource');
58
+
59
+ $writeConnection = $resource->getConnection('core_write');
60
+
61
+ $table = $resource->getTableName('newsletter/subscriber');
62
+
63
+ $query = "UPDATE {$table} SET subscriber_status = ".$status.",change_status_at=NOW() ".
64
+ " WHERE "."subscriber_email = '".$mail."'";
65
+
66
+ /**
67
+ * Execute the query
68
+ */
69
+ $writeConnection->query($query);
70
+
71
+ $res = 200;
72
+ return $res;
73
+ }
74
  /**
75
  * Return subscriber list with the customer info
76
  *
158
  // it is impossible to filter subscribers by date, because there are cases when the dates are NULL
159
  // get all subscribers
160
 
161
+ if($hours==0){
162
+ $query = "SELECT * FROM newsletter_subscriber ".
163
+ " WHERE subscriber_status=".Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED.
164
+ " AND customer_id=0";
165
+ } else {
166
  $query = "SELECT * FROM newsletter_subscriber ".
 
 
167
  " WHERE customer_id=0 AND (change_status_at IS NULL OR change_status_at BETWEEN TIMESTAMP(DATE_SUB(NOW(), INTERVAL ".$hours." HOUR)) AND TIMESTAMP(NOW()))";
168
+ }
169
 
170
  /* Execute the query and store the results in $results */
171
  $results = $readConnection->fetchAll($query);
193
  " AND customer_id!=0";
194
  } else {
195
  $query = "SELECT * FROM newsletter_subscriber ".
 
 
 
196
  " WHERE customer_id IN(".
197
  "SELECT entity_id FROM customer_entity ".
198
  " WHERE created_at BETWEEN TIMESTAMP(DATE_SUB(NOW(), INTERVAL ".$hours." HOUR)) AND TIMESTAMP(NOW()) OR ".
app/code/local/NL2go/Sync/etc/api.xml CHANGED
@@ -26,6 +26,10 @@
26
  <title>Return subscribers list with the customer info</title>
27
  <method>getSubscribers</method>
28
  </getSubscribers>
 
 
 
 
29
  </methods>
30
  <faults module="sync">
31
  <store_not_exists>
26
  <title>Return subscribers list with the customer info</title>
27
  <method>getSubscribers</method>
28
  </getSubscribers>
29
+ <setSubscriptionStatus translate="title" module="sync">
30
+ <title>Update subscriper status</title>
31
+ <method>setSubscriptionStatus</method>
32
+ </setSubscriptionStatus>
33
  </methods>
34
  <faults module="sync">
35
  <store_not_exists>
app/code/local/NL2go/Sync/etc/wsdl.xml CHANGED
@@ -62,6 +62,15 @@
62
  <part name="result" type="typens:ArrayOfNewsletterSubscriberEntity"/>
63
  </message>
64
 
 
 
 
 
 
 
 
 
 
65
  <portType name="{{var wsdl.handler}}PortType">
66
 
67
  <operation name="syncNewsletterGetSubscribers">
@@ -69,6 +78,12 @@
69
  <input message="typens:syncNewsletterGetSubscribersRequest"/>
70
  <output message="typens:syncNewsletterGetSubscribersResponse"/>
71
  </operation>
 
 
 
 
 
 
72
 
73
  </portType>
74
  <binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
@@ -85,6 +100,18 @@
85
  encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
86
  </output>
87
  </operation>
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
  </binding>
90
 
62
  <part name="result" type="typens:ArrayOfNewsletterSubscriberEntity"/>
63
  </message>
64
 
65
+ <message name="syncNewsletterSetSubscriptionStatusRequest">
66
+ <part name="sessionId" type="xsd:string"/>
67
+ <part name="email" type="xsd:string"/>
68
+ <part name="status" type="xsd:int"/>
69
+ </message>
70
+ <message name="syncNewsletterSetSubscriptionStatusResponse">
71
+ <part name="result" type="xsd:int"/>
72
+ </message>
73
+
74
  <portType name="{{var wsdl.handler}}PortType">
75
 
76
  <operation name="syncNewsletterGetSubscribers">
78
  <input message="typens:syncNewsletterGetSubscribersRequest"/>
79
  <output message="typens:syncNewsletterGetSubscribersResponse"/>
80
  </operation>
81
+
82
+ <operation name="syncNewsletterSetSubscriptionStatus">
83
+ <documentation>Update subscriper status</documentation>
84
+ <input message="typens:syncNewsletterSetSubscriptionStatusRequest"/>
85
+ <output message="typens:syncNewsletterSetSubscriptionStatusResponse"/>
86
+ </operation>
87
 
88
  </portType>
89
  <binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
100
  encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
101
  </output>
102
  </operation>
103
+
104
+ <operation name="syncNewsletterSetSubscriptionStatus">
105
+ <soap:operation soapAction="urn:{{var wsdl.handler}}Action"/>
106
+ <input>
107
+ <soap:body namespace="urn:{{var wsdl.name}}" use="encoded"
108
+ encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
109
+ </input>
110
+ <output>
111
+ <soap:body namespace="urn:{{var wsdl.name}}" use="encoded"
112
+ encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
113
+ </output>
114
+ </operation>
115
 
116
  </binding>
117
 
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>NL2go_Sync</name>
4
- <version>1.0.4</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
@@ -15,11 +15,11 @@ On top you can easily retrieve all item data including description, price info,
15
  &lt;p&gt;Get the extension key on this site and install the Newsletter2Go Magento Extension in your Magento shop. &lt;br /&gt;&#xD;
16
  Set up a new API user and insert the information under settings on the Newsletter2Go web site.&#xD;
17
  &lt;/p&gt;</description>
18
- <notes>The same with 1.0.3, repack because incompatible with the older channel</notes>
19
  <authors><author><name>Steffen</name><user>auto-converted</user><email>info@newsletter2go.de</email></author></authors>
20
- <date>2013-08-01</date>
21
- <time>09:21:34</time>
22
- <contents><target name="magelocal"><dir name="NL2go"><dir name="Sync"><dir name="Model"><dir name="Newsletter"><dir name="Api"><file name="V2.php" hash="2f07484c9730e0a7f77c14083fc7ec43"/></dir><file name="Api.php" hash="c26ea29af9b050074560193228047842"/></dir></dir><dir name="etc"><file name="api.xml" hash="f1d83f4b3ce370e72285745611ae9aee"/><file name="config.xml" hash="534eb47f4db745e8b5210c1dfb5ca40a"/><file name="wsdl.xml" hash="31e15e210a20be3dcbdbee7de454793e"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="NL2go_Sync.xml" hash="93aca69e7ba45a5664e4bcd277aa775b"/></dir></target></contents>
23
  <compatible/>
24
  <dependencies/>
25
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>NL2go_Sync</name>
4
+ <version>1.1.0</version>
5
  <stability>stable</stability>
6
  <license>GPL</license>
7
  <channel>community</channel>
15
  &lt;p&gt;Get the extension key on this site and install the Newsletter2Go Magento Extension in your Magento shop. &lt;br /&gt;&#xD;
16
  Set up a new API user and insert the information under settings on the Newsletter2Go web site.&#xD;
17
  &lt;/p&gt;</description>
18
+ <notes>Added support for 2- way synchronisation of unsubscribes over Magento accounts and the Newsletter2Go unsubscribe link</notes>
19
  <authors><author><name>Steffen</name><user>auto-converted</user><email>info@newsletter2go.de</email></author></authors>
20
+ <date>2013-08-05</date>
21
+ <time>15:59:44</time>
22
+ <contents><target name="magelocal"><dir name="NL2go"><dir name="Sync"><dir name="Model"><dir name="Newsletter"><dir name="Api"><file name="V2.php" hash="1ab6a64a5b115839a1541e3763f89efe"/></dir><file name="Api.php" hash="0139d3b2ef2ed98a10b3d7a14b6f7959"/></dir></dir><dir name="etc"><file name="api.xml" hash="7e11289db23d52088f15c1654b35f3a8"/><file name="config.xml" hash="534eb47f4db745e8b5210c1dfb5ca40a"/><file name="wsdl.xml" hash="20bbaaea37e858a3f07f597f4fae41b2"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="NL2go_Sync.xml" hash="93aca69e7ba45a5664e4bcd277aa775b"/></dir></target></contents>
23
  <compatible/>
24
  <dependencies/>
25
  </package>