NL2go_Sync - Version 1.0.0

Version Notes

The 1st release

Download this release

Release Info

Developer Newsletter2Go
Extension NL2go_Sync
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/NL2go/Sync/Model/Newsletter/Api.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * NL2go newsletters subscribers list API extension
5
+ *
6
+ * @category NL2go
7
+ * @package NL2go_Sync
8
+ * @author Anatoly V Koval
9
+ */
10
+
11
+ class NL2go_Sync_Model_Newsletter_Api extends Mage_Api_Model_Resource_Abstract
12
+ {
13
+ public function getSubscribers()
14
+ {
15
+ }
16
+ }
app/code/local/NL2go/Sync/Model/Newsletter/Api/V2.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * NL2go newsletters subscribers list API extension
5
+ *
6
+ * @category NL2go
7
+ * @package NL2go_Sync
8
+ * @author Anatoly V Koval
9
+ */
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
+ *
17
+ * @param string $file
18
+ * @return String
19
+ */
20
+ public function getSubscribers($for_last_hours=0) {
21
+
22
+ $res = array();
23
+
24
+ $customer = Mage::getModel('customer/customer');
25
+
26
+ $subscriber = Mage::getModel('newsletter/subscriber');
27
+
28
+ $customersList = $this->getCustomersList($for_last_hours);
29
+
30
+ // get subscribers as registered customer
31
+ foreach ($customersList as $k=>$v){
32
+
33
+ $customerInfo = Mage::getModel('customer/customer_api')->info($v["customer_id"]);
34
+
35
+ $customer = Mage::getModel('customer/customer')->load($v["customer_id"]);
36
+
37
+ $customerTotals = Mage::getResourceModel('sales/sale_collection')
38
+ ->setOrderStateFilter(Mage_Sales_Model_Order::STATE_CANCELED, true)
39
+ ->setCustomerFilter($customer)
40
+ ->load()
41
+ ->getTotals();
42
+ $customerLifetimeSales = $customerTotals->getLifetime();
43
+ $customerNumberOfOrders = $customerTotals->getNumOrders();
44
+
45
+ $subscriber->load($v["subscriber_id"]);
46
+
47
+ $res[] = array(
48
+ "subscriber_id"=>$v["subscriber_id"],
49
+ "store_id"=>$subscriber->getData("store_id"),
50
+ "change_status_at"=>$subscriber->getData("change_status_at"),
51
+ "subscriber_email"=>$subscriber->getData("subscriber_email"),
52
+ "total_sales"=>$customerLifetimeSales,
53
+ "avg_sales"=>$customerNumberOfOrders!=0?$customerLifetimeSales/$customerNumberOfOrders:0,
54
+ "total_orders"=>$customerNumberOfOrders,
55
+ "customer_info"=>$customerInfo
56
+ );
57
+ unset($customerTotals);
58
+ if(method_exists($customer, "clearInstance"))
59
+ $customer->clearInstance();
60
+ }
61
+
62
+ // get simple subscribers, as unregistered customers
63
+
64
+ $subscribersList = $this->getSimpleSubscribers($for_last_hours);
65
+ foreach ($subscribersList as $k=>$v){
66
+ $subscriber->load($v["subscriber_id"]);
67
+ $res[] = array(
68
+ "subscriber_id"=>$v["subscriber_id"],
69
+ "store_id"=>$subscriber->getData("store_id"),
70
+ "change_status_at"=>$subscriber->getData("change_status_at"),
71
+ "subscriber_email"=>$subscriber->getData("subscriber_email"),
72
+ "total_sales"=>0,
73
+ "avg_sales"=>0,
74
+ "total_orders"=>0,
75
+ "customer_info"=>null
76
+ );
77
+ }
78
+ return $res;
79
+ }
80
+ /**
81
+ * Return simple subscribers list
82
+ *
83
+ * @param int $hours
84
+ */
85
+ private function getSimpleSubscribers($hours){
86
+ $resource = Mage::getSingleton('core/resource');
87
+ /* Retrieve the read connection */
88
+ $readConnection = $resource->getConnection('core_read');
89
+
90
+ // it is impossible to filter subscribers by date, because there are cases when the dates are NULL
91
+ // get all subscribers
92
+
93
+ $query = "SELECT * FROM newsletter_subscriber ".
94
+ " WHERE subscriber_status=".Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED.
95
+ " 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()))";
96
+
97
+ /* Execute the query and store the results in $results */
98
+ $results = $readConnection->fetchAll($query);
99
+
100
+ $res = array();
101
+ foreach ($results as $k=>$v){
102
+ $res[] = array("subscriber_id"=>$v["subscriber_id"]);
103
+ }
104
+ return $res;
105
+ }
106
+ /**
107
+ * Return subscribers (customer) list for selected time interval
108
+ *
109
+ * @param int $hours
110
+ */
111
+ private function getCustomersList($hours){
112
+ $resource = Mage::getSingleton('core/resource');
113
+ /* Retrieve the read connection */
114
+ $readConnection = $resource->getConnection('core_read');
115
+
116
+ /* Retrieve our data for customers */
117
+ if($hours==0){
118
+ $query = "SELECT * FROM newsletter_subscriber ".
119
+ " WHERE subscriber_status=".Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED.
120
+ " AND customer_id!=0";
121
+ } else {
122
+ $query = "SELECT * FROM newsletter_subscriber ".
123
+ " WHERE subscriber_status=".Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED.
124
+ " AND customer_id IN(".
125
+ "SELECT entity_id FROM customer_entity ".
126
+ " WHERE created_at BETWEEN TIMESTAMP(DATE_SUB(NOW(), INTERVAL ".$hours." HOUR)) AND TIMESTAMP(NOW()) OR ".
127
+ " updated_at BETWEEN TIMESTAMP(DATE_SUB(NOW(), INTERVAL ".$hours." HOUR)) AND TIMESTAMP(NOW())".
128
+ ")";
129
+ }
130
+
131
+ /* Execute the query and store the results in $results */
132
+ $results = $readConnection->fetchAll($query);
133
+
134
+ $res = array();
135
+ foreach ($results as $k=>$v){
136
+ $res[] = array("subscriber_id"=>$v["subscriber_id"], "customer_id"=>$v["customer_id"]);
137
+ }
138
+ return $res;
139
+ }
140
+ }
141
+ ?>
app/code/local/NL2go/Sync/etc/api.xml ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+
4
+ /**
5
+ * NL2go newsletters subscribers list API extension
6
+ *
7
+ * @category NL2go
8
+ * @package NL2go_Sync
9
+ * @author Anatoly V Koval
10
+ */
11
+
12
+ -->
13
+ <config>
14
+ <modules>
15
+ <NL2go_Sync>
16
+ <version>1.0.0</version>
17
+ </NL2go_Sync>
18
+ </modules>
19
+ <api>
20
+ <resources>
21
+ <sync_newsletter translate="title" module="sync">
22
+ <model>sync/newsletter_api</model>
23
+ <title>Newsletter API Extension</title>
24
+ <methods>
25
+ <getSubscribers translate="title" module="sync">
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>
32
+ <code>100</code>
33
+ <message>Requested store view not found.</message>
34
+ </store_not_exists>
35
+ </faults>
36
+ </sync_newsletter>
37
+ </resources>
38
+
39
+ <resources_alias>
40
+ <sync_newsletter>sync_newsletter</sync_newsletter>
41
+ </resources_alias>
42
+ <v2>
43
+ <resources_function_prefix>
44
+ <sync_newsletter>syncNewsletter</sync_newsletter>
45
+ </resources_function_prefix>
46
+ </v2>
47
+
48
+ <acl>
49
+ <resources>
50
+ <all>
51
+ </all>
52
+ </resources>
53
+ </acl>
54
+
55
+ </api>
56
+ </config>
app/code/local/NL2go/Sync/etc/config.xml ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+
4
+ /**
5
+ * NL2go newsletters subscribers list API extension
6
+ *
7
+ * @category NL2go
8
+ * @package NL2go_Sync
9
+ * @author Anatoly V Koval
10
+ */
11
+
12
+ -->
13
+ <config>
14
+ <modules>
15
+ <NL2go_Sync>
16
+ <version>1.0.0</version>
17
+ </NL2go_Sync>
18
+ </modules>
19
+ <global>
20
+ <models>
21
+ <sync>
22
+ <rewrite>
23
+ <newsletter_api_v2>NL2go_Sync_Model_Newsletter_Api_V2</newsletter_api_v2>
24
+ </rewrite>
25
+ </sync>
26
+ </models>
27
+ </global>
28
+ </config>
29
+ <!--
30
+ <config>
31
+ <modules>
32
+ <NL2go_Sync>
33
+ <version>0.1.0</version>
34
+ </NL2go_Sync>
35
+ </modules>
36
+ <global>
37
+ <helpers>
38
+ <sync>
39
+ <class>NL2go_Sync_Helper</class>
40
+ </sync>
41
+ </helpers>
42
+ <models>
43
+ <sync>
44
+ <class>NL2go_Sync_Model</class>
45
+ <resourceModel>sync_mysql4</resourceModel>
46
+ </sync>
47
+ </models>
48
+ </global>
49
+ </config>
50
+ -->
app/code/local/NL2go/Sync/etc/wsdl.xml ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <definitions xmlns:typens="urn:{{var wsdl.name}}" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
3
+ xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
4
+ xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
5
+ xmlns="http://schemas.xmlsoap.org/wsdl/"
6
+ name="{{var wsdl.name}}" targetNamespace="urn:{{var wsdl.name}}">
7
+ <types>
8
+ <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Magento">
9
+ <import namespace="http://schemas.xmlsoap.org/soap/encoding/"
10
+ schemaLocation="http://schemas.xmlsoap.org/soap/encoding/"/>
11
+ <complexType name="newsletterSubscriberEntity">
12
+ <all>
13
+ <element name="subscriber_id" type="xsd:int" minOccurs="0"/>
14
+ <element name="store_id" type="xsd:int" minOccurs="0"/>
15
+ <element name="change_status_at" type="xsd:string" minOccurs="0"/>
16
+ <element name="subscriber_email" type="xsd:string" minOccurs="0"/>
17
+ <element name="total_sales" type="xsd:float" minOccurs="0"/>
18
+ <element name="avg_sales" type="xsd:float" minOccurs="0"/>
19
+ <element name="total_orders" type="xsd:int" minOccurs="0"/>
20
+ <element name="customer_info" type="typens:customerCustomerEntity" minOccurs="0"/>
21
+ </all>
22
+ </complexType>
23
+ <complexType name="ArrayOfNewsletterSubscriberEntity">
24
+ <complexContent>
25
+ <restriction base="soapenc:Array">
26
+ <attribute ref="soapenc:arrayType" wsdl:arrayType="typens:newsletterSubscriberEntity[]"/>
27
+ </restriction>
28
+ </complexContent>
29
+ </complexType>
30
+ </schema>
31
+ </types>
32
+
33
+ <message name="syncNewsletterGetSubscribersRequest">
34
+ <part name="sessionId" type="xsd:string"/>
35
+ <part name="for_hours" type="xsd:int"/>
36
+ </message>
37
+ <message name="syncNewsletterGetSubscribersResponse">
38
+ <part name="result" type="typens:ArrayOfNewsletterSubscriberEntity"/>
39
+ </message>
40
+
41
+ <portType name="{{var wsdl.handler}}PortType">
42
+
43
+ <operation name="syncNewsletterGetSubscribers">
44
+ <documentation>Return the customer info for newsletter subscibers</documentation>
45
+ <input message="typens:syncNewsletterGetSubscribersRequest"/>
46
+ <output message="typens:syncNewsletterGetSubscribersResponse"/>
47
+ </operation>
48
+
49
+ </portType>
50
+ <binding name="{{var wsdl.handler}}Binding" type="typens:{{var wsdl.handler}}PortType">
51
+ <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
52
+
53
+ <operation name="syncNewsletterGetSubscribers">
54
+ <soap:operation soapAction="urn:{{var wsdl.handler}}Action"/>
55
+ <input>
56
+ <soap:body namespace="urn:{{var wsdl.name}}" use="encoded"
57
+ encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
58
+ </input>
59
+ <output>
60
+ <soap:body namespace="urn:{{var wsdl.name}}" use="encoded"
61
+ encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
62
+ </output>
63
+ </operation>
64
+
65
+ </binding>
66
+
67
+ <service name="{{var wsdl.name}}Service">
68
+ <port name="{{var wsdl.handler}}Port" binding="typens:{{var wsdl.handler}}Binding">
69
+ <soap:address location="{{var wsdl.url}}"/>
70
+ </port>
71
+ </service>
72
+ </definitions>
app/etc/modules/NL2go_Sync.xml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <!--
4
+ /**
5
+ * NL2go newsletters subscribers list API extension
6
+ *
7
+ * @category NL2go
8
+ * @package NL2go_Sync
9
+ * @author Anatoly V Koval
10
+ */
11
+
12
+ -->
13
+ <config>
14
+ <modules>
15
+ <NL2go_Sync>
16
+ <active>true</active>
17
+ <codePool>local</codePool>
18
+ <depends>
19
+ <Mage_Api />
20
+ </depends>
21
+ <version>1.0.0</version>
22
+ </NL2go_Sync>
23
+ </modules>
24
+ </config>
package.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>NL2go_Sync</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>GPL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Synchronizes your Magento newsletter subscribers, sales figures and shop items with Newsletter2Go.</summary>
10
+ <description>&lt;h2&gt;Newsletter2Go Magento Extension&lt;/h2&gt;&#xD;
11
+ &#xD;
12
+ &lt;p&gt;The Magento Extension for the &lt;a href=https://www.newsletter2go.de&gt;Newsletter2Go email marketing software&lt;/a&gt; automatically synchronizes all newsletter subscribers, including basic data like name and gender as well as the total amount of sales and average sale.&lt;br /&gt;</description>
13
+ <notes>The 1st release</notes>
14
+ <authors><author><name>Steffen</name><user>Newsletter2Go</user><email>info@newsletter2go.de</email></author></authors>
15
+ <date>2013-04-02</date>
16
+ <time>12:24:55</time>
17
+ <contents><target name="magelocal"><dir name="NL2go"><dir name="Sync"><dir name="Model"><dir name="Newsletter"><dir name="Api"><file name="V2.php" hash="f64bc30f9c25c93264a74011009eeb55"/></dir><file name="Api.php" hash="c26ea29af9b050074560193228047842"/></dir></dir><dir name="etc"><file name="api.xml" hash="f1d83f4b3ce370e72285745611ae9aee"/><file name="config.xml" hash="709d285e83a05f3167752a4f3088e419"/><file name="wsdl.xml" hash="62c691a80a8b0d2fd17c4d057f843c85"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="NL2go_Sync.xml" hash="93aca69e7ba45a5664e4bcd277aa775b"/></dir></target></contents>
18
+ <compatible/>
19
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
20
+ </package>