Version Notes
The plugin is more robust to different configurations and does not depend on Class 'Mage_Sync_Helper_Data' anymore
Download this release
Release Info
Developer | Newsletter2Go |
Extension | NL2go_Sync |
Version | 1.3.0 |
Comparing to | |
See all releases |
Code changes from version 1.2.1 to 1.3.0
app/code/local/NL2go/Sync/Helper/Data.php
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento Module developed by cyb // www.cyb.gr
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to mage@cyb.gr so we can send you a copy.
|
14 |
+
*
|
15 |
+
* @copyright Copyright � 2012 cyb (http://www.cyb.gr)
|
16 |
+
*
|
17 |
+
*
|
18 |
+
* DISCLAIMER
|
19 |
+
*
|
20 |
+
* Do not edit or add to this file if you wish to upgrade the extension
|
21 |
+
* to newer versions in the future. If you wish to customize the extension
|
22 |
+
* for your needs please refer to http://www.cyb.gr/ for more information
|
23 |
+
* or send an email to mage@cyb.gr
|
24 |
+
*/
|
25 |
+
|
26 |
+
/**
|
27 |
+
* @category cyb
|
28 |
+
* @package cyb_StoreReviews
|
29 |
+
* @author Koval Anatoly
|
30 |
+
**/
|
31 |
+
class NL2go_Sync_Helper_Data extends Mage_Core_Helper_Abstract{
|
32 |
+
}
|
33 |
+
?>
|
app/code/local/NL2go/Sync/Model/Newsletter/Api/V2.php
CHANGED
@@ -77,35 +77,44 @@ class Nl2go_Sync_Model_Newsletter_Api_V2 extends Mage_Api_Model_Resource_Abstrac
|
|
77 |
* @param string $file
|
78 |
* @return String
|
79 |
*/
|
80 |
-
public function getSubscribers($for_last_hours=0
|
81 |
-
|
82 |
$res = array();
|
83 |
|
84 |
$customer = Mage::getModel('customer/customer');
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
$customersList = $this->getCustomersList($for_last_hours, $subscribed_only);
|
89 |
|
90 |
// get subscribers as registered customer
|
91 |
foreach ($customersList as $k=>$v){
|
|
|
92 |
|
93 |
-
$customerInfo =
|
94 |
|
95 |
$customer = Mage::getModel('customer/customer')->load($v["customer_id"]);
|
|
|
96 |
$gender_code = $customer->getGender();
|
97 |
if(!is_null($gender_code))
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
-
$subscriber->load($v["subscriber_id"]);
|
109 |
|
110 |
$res[] = array(
|
111 |
"subscriber_id"=>$v["subscriber_id"],
|
@@ -118,19 +127,20 @@ class Nl2go_Sync_Model_Newsletter_Api_V2 extends Mage_Api_Model_Resource_Abstrac
|
|
118 |
"total_orders"=>$customerNumberOfOrders,
|
119 |
"customer_info"=>$customerInfo
|
120 |
);
|
121 |
-
|
122 |
if(method_exists($customer, "clearInstance"))
|
123 |
$customer->clearInstance();
|
124 |
-
|
125 |
-
|
126 |
-
|
|
|
127 |
}
|
128 |
-
|
129 |
// get simple subscribers, as unregistered customers
|
130 |
|
131 |
$subscribersList = $this->getSimpleSubscribers($for_last_hours);
|
132 |
foreach ($subscribersList as $k=>$v){
|
133 |
-
$subscriber->load($v["subscriber_id"]);
|
134 |
$res[] = array(
|
135 |
"subscriber_id"=>$v["subscriber_id"],
|
136 |
"subscriber_status"=>$v["subscriber_status"],
|
@@ -142,6 +152,58 @@ class Nl2go_Sync_Model_Newsletter_Api_V2 extends Mage_Api_Model_Resource_Abstrac
|
|
142 |
"total_orders"=>0,
|
143 |
"customer_info"=>null
|
144 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
}
|
146 |
return $res;
|
147 |
}
|
@@ -154,18 +216,16 @@ class Nl2go_Sync_Model_Newsletter_Api_V2 extends Mage_Api_Model_Resource_Abstrac
|
|
154 |
$resource = Mage::getSingleton('core/resource');
|
155 |
/* Retrieve the read connection */
|
156 |
$readConnection = $resource->getConnection('core_read');
|
157 |
-
|
158 |
-
|
159 |
// it is impossible to filter subscribers by date, because there are cases when the dates are NULL
|
160 |
// get all subscribers
|
161 |
|
162 |
-
|
163 |
if($hours==0){
|
164 |
-
$query = "SELECT * FROM
|
165 |
" WHERE subscriber_status=".Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED.
|
166 |
" AND customer_id=0";
|
167 |
} else {
|
168 |
-
$query = "SELECT * FROM
|
169 |
" 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()))";
|
170 |
}
|
171 |
|
@@ -183,23 +243,20 @@ class Nl2go_Sync_Model_Newsletter_Api_V2 extends Mage_Api_Model_Resource_Abstrac
|
|
183 |
*
|
184 |
* @param int $hours
|
185 |
*/
|
186 |
-
private function getCustomersList($hours
|
187 |
$resource = Mage::getSingleton('core/resource');
|
188 |
/* Retrieve the read connection */
|
189 |
$readConnection = $resource->getConnection('core_read');
|
190 |
-
$table = $resource->getTableName('newsletter/subscriber');
|
191 |
-
$tableCustomer = $resource->getTableName('customer/entity');
|
192 |
|
193 |
/* Retrieve our data for customers */
|
194 |
if($hours==0){
|
195 |
-
$query = "SELECT * FROM
|
196 |
-
|
197 |
-
|
198 |
-
}
|
199 |
} else {
|
200 |
-
$query = "SELECT * FROM
|
201 |
" WHERE customer_id IN(".
|
202 |
-
"SELECT entity_id FROM
|
203 |
" WHERE created_at BETWEEN TIMESTAMP(DATE_SUB(NOW(), INTERVAL ".$hours." HOUR)) AND TIMESTAMP(NOW()) OR ".
|
204 |
" updated_at BETWEEN TIMESTAMP(DATE_SUB(NOW(), INTERVAL ".$hours." HOUR)) AND TIMESTAMP(NOW())".
|
205 |
")";
|
77 |
* @param string $file
|
78 |
* @return String
|
79 |
*/
|
80 |
+
public function getSubscribers($for_last_hours=0) {
|
81 |
+
try{
|
82 |
$res = array();
|
83 |
|
84 |
$customer = Mage::getModel('customer/customer');
|
85 |
|
86 |
+
|
87 |
+
$customersList = $this->getCustomersList($for_last_hours);
|
|
|
88 |
|
89 |
// get subscribers as registered customer
|
90 |
foreach ($customersList as $k=>$v){
|
91 |
+
if(!$this->customerExists($v["customer_id"])) continue; // in some magento's store subscriber has non existing customer id
|
92 |
|
93 |
+
$customerInfo = array();
|
94 |
|
95 |
$customer = Mage::getModel('customer/customer')->load($v["customer_id"]);
|
96 |
+
|
97 |
$gender_code = $customer->getGender();
|
98 |
if(!is_null($gender_code))
|
99 |
+
$customerInfo['gender'] = $customer->getAttribute("gender")->getSource()->getOptionText($gender_code);
|
100 |
+
|
101 |
+
$customerInfo['customer_id'] = $customer->getId();
|
102 |
+
$customerInfo['created_at'] = $customer->getCreatedAt();
|
103 |
+
$customerInfo['updated_at'] = $customer->getUpdatedAt();
|
104 |
+
$customerInfo['store_id'] = $customer->getStoreId();
|
105 |
+
$customerInfo['website_id'] = $customer->getWebsiteId();
|
106 |
+
$customerInfo['created_in'] = $customer->getCreatedIn();
|
107 |
+
$customerInfo['email'] = $customer->getEmail();
|
108 |
+
$customerInfo['firstname'] = $customer->getFirstname();
|
109 |
+
$customerInfo['lastname'] = $customer->getLastname();
|
110 |
+
$customerInfo['group_id'] = $customer->getGroupId();
|
111 |
+
|
112 |
+
$customerTotals = $this->getCustomerTotals($v["customer_id"]);
|
113 |
+
|
114 |
+
$customerLifetimeSales = $customerTotals['lifetime'];//->getLifetime();
|
115 |
+
$customerNumberOfOrders = $customerTotals['num_orders'];//->getNumOrders();
|
116 |
|
117 |
+
$subscriber = Mage::getModel('newsletter/subscriber')->load($v["subscriber_id"]);
|
118 |
|
119 |
$res[] = array(
|
120 |
"subscriber_id"=>$v["subscriber_id"],
|
127 |
"total_orders"=>$customerNumberOfOrders,
|
128 |
"customer_info"=>$customerInfo
|
129 |
);
|
130 |
+
|
131 |
if(method_exists($customer, "clearInstance"))
|
132 |
$customer->clearInstance();
|
133 |
+
unset($customer);
|
134 |
+
if(method_exists($subscriber, "clearInstance"))
|
135 |
+
$subscriber->clearInstance();
|
136 |
+
unset($subscriber);
|
137 |
}
|
138 |
+
|
139 |
// get simple subscribers, as unregistered customers
|
140 |
|
141 |
$subscribersList = $this->getSimpleSubscribers($for_last_hours);
|
142 |
foreach ($subscribersList as $k=>$v){
|
143 |
+
$subscriber = Mage::getModel('newsletter/subscriber')->load($v["subscriber_id"]);
|
144 |
$res[] = array(
|
145 |
"subscriber_id"=>$v["subscriber_id"],
|
146 |
"subscriber_status"=>$v["subscriber_status"],
|
152 |
"total_orders"=>0,
|
153 |
"customer_info"=>null
|
154 |
);
|
155 |
+
|
156 |
+
if(method_exists($subscriber, "clearInstance"))
|
157 |
+
$subscriber->clearInstance();
|
158 |
+
unset($subscriber);
|
159 |
+
}
|
160 |
+
|
161 |
+
}catch(Exception $e){
|
162 |
+
Mage::log("Exception:\n".$e->getTraceAsString(), null, "mem.log");
|
163 |
+
}
|
164 |
+
return $res;
|
165 |
+
}
|
166 |
+
/*
|
167 |
+
* return true, if customer with the given id exists in the store
|
168 |
+
*/
|
169 |
+
private function customerExists($cid){
|
170 |
+
$resource = Mage::getSingleton('core/resource');
|
171 |
+
/* Retrieve the read connection */
|
172 |
+
$readConnection = $resource->getConnection('core_read');
|
173 |
+
|
174 |
+
$query = "SELECT * FROM `".$resource->getTableName('customer/entity')."` ".
|
175 |
+
" WHERE entity_id=".$cid;
|
176 |
+
/* Execute the query and store the results in $results */
|
177 |
+
$results = $readConnection->fetchAll($query);
|
178 |
+
if(count($results)>0) return true;
|
179 |
+
return false;
|
180 |
+
}
|
181 |
+
/*
|
182 |
+
* Return customer totals info
|
183 |
+
*/
|
184 |
+
private function getCustomerTotals($cid){
|
185 |
+
$resource = Mage::getSingleton('core/resource');
|
186 |
+
/* Retrieve the read connection */
|
187 |
+
$readConnection = $resource->getConnection('core_read');
|
188 |
+
|
189 |
+
$query = "SELECT `sales`.`store_id`, SUM(sales.base_grand_total) AS `lifetime`, SUM(sales.base_grand_total * sales.base_to_global_rate) AS `base_lifetime`, AVG(sales.base_grand_total) AS `avgsale`, AVG(sales.base_grand_total * sales.base_to_global_rate) AS `base_avgsale`, COUNT(sales.base_grand_total) AS `num_orders` ".
|
190 |
+
// "FROM `".$resource->getTableName('sales_flat_order')."` AS `sales` ".
|
191 |
+
"FROM `sales_flat_order` AS `sales` ".
|
192 |
+
"WHERE (sales.customer_id = '".$cid."') AND (state NOT IN('canceled')) ".
|
193 |
+
"GROUP BY `sales`.`store_id`";
|
194 |
+
/* Execute the query and store the results in $results */
|
195 |
+
$results = $readConnection->fetchAll($query);
|
196 |
+
|
197 |
+
$res = array(
|
198 |
+
'lifetime' => 0, 'base_lifetime' => 0, 'base_avgsale' => 0, 'num_orders' => 0, 'avgsale'=>0);
|
199 |
+
|
200 |
+
foreach ($results as $k=>$v){
|
201 |
+
foreach($res as $key=>$val){
|
202 |
+
$res[$key] = $res[$key] + $v[$key];
|
203 |
+
}
|
204 |
+
}
|
205 |
+
if ($res['num_orders']) {
|
206 |
+
$res['avgsale'] = $res['base_lifetime'] / $res['num_orders'];
|
207 |
}
|
208 |
return $res;
|
209 |
}
|
216 |
$resource = Mage::getSingleton('core/resource');
|
217 |
/* Retrieve the read connection */
|
218 |
$readConnection = $resource->getConnection('core_read');
|
219 |
+
|
|
|
220 |
// it is impossible to filter subscribers by date, because there are cases when the dates are NULL
|
221 |
// get all subscribers
|
222 |
|
|
|
223 |
if($hours==0){
|
224 |
+
$query = "SELECT * FROM newsletter_subscriber ".
|
225 |
" WHERE subscriber_status=".Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED.
|
226 |
" AND customer_id=0";
|
227 |
} else {
|
228 |
+
$query = "SELECT * FROM newsletter_subscriber ".
|
229 |
" 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()))";
|
230 |
}
|
231 |
|
243 |
*
|
244 |
* @param int $hours
|
245 |
*/
|
246 |
+
private function getCustomersList($hours){
|
247 |
$resource = Mage::getSingleton('core/resource');
|
248 |
/* Retrieve the read connection */
|
249 |
$readConnection = $resource->getConnection('core_read');
|
|
|
|
|
250 |
|
251 |
/* Retrieve our data for customers */
|
252 |
if($hours==0){
|
253 |
+
$query = "SELECT * FROM ".$resource->getTableName('newsletter/subscriber')." ".
|
254 |
+
" WHERE subscriber_status=".Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED.
|
255 |
+
" AND customer_id!=0";
|
|
|
256 |
} else {
|
257 |
+
$query = "SELECT * FROM newsletter_subscriber ".
|
258 |
" WHERE customer_id IN(".
|
259 |
+
"SELECT entity_id FROM customer_entity ".
|
260 |
" WHERE created_at BETWEEN TIMESTAMP(DATE_SUB(NOW(), INTERVAL ".$hours." HOUR)) AND TIMESTAMP(NOW()) OR ".
|
261 |
" updated_at BETWEEN TIMESTAMP(DATE_SUB(NOW(), INTERVAL ".$hours." HOUR)) AND TIMESTAMP(NOW())".
|
262 |
")";
|
app/code/local/NL2go/Sync/etc/config.xml
CHANGED
@@ -24,5 +24,10 @@
|
|
24 |
</rewrite>
|
25 |
</sync>
|
26 |
</models>
|
|
|
|
|
|
|
|
|
|
|
27 |
</global>
|
28 |
</config>
|
24 |
</rewrite>
|
25 |
</sync>
|
26 |
</models>
|
27 |
+
<helpers>
|
28 |
+
<sync>
|
29 |
+
<class>NL2go_Sync_Helper</class>
|
30 |
+
</sync>
|
31 |
+
</helpers>
|
32 |
</global>
|
33 |
</config>
|
app/code/local/NL2go/Sync/etc/wsdl.xml
CHANGED
@@ -57,7 +57,6 @@
|
|
57 |
<message name="syncNewsletterGetSubscribersRequest">
|
58 |
<part name="sessionId" type="xsd:string"/>
|
59 |
<part name="for_hours" type="xsd:int"/>
|
60 |
-
<part name="subscribed_only" type="xsd:boolean"/>
|
61 |
</message>
|
62 |
<message name="syncNewsletterGetSubscribersResponse">
|
63 |
<part name="result" type="typens:ArrayOfNewsletterSubscriberEntity"/>
|
57 |
<message name="syncNewsletterGetSubscribersRequest">
|
58 |
<part name="sessionId" type="xsd:string"/>
|
59 |
<part name="for_hours" type="xsd:int"/>
|
|
|
60 |
</message>
|
61 |
<message name="syncNewsletterGetSubscribersResponse">
|
62 |
<part name="result" type="typens:ArrayOfNewsletterSubscriberEntity"/>
|
package.xml
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>NL2go_Sync</name>
|
4 |
-
<version>1.
|
5 |
<stability>stable</stability>
|
6 |
-
<license
|
7 |
<channel>community</channel>
|
8 |
<extends/>
|
9 |
<summary>Synchronizes your Magento newsletter subscribers, sales figures and shop items with Newsletter2Go.</summary>
|
@@ -15,11 +15,11 @@ On top you can easily retrieve all item data including description, price info,
|
|
15 |
<p>Get the extension key on this site and install the Newsletter2Go Magento Extension in your Magento shop. <br />
|
16 |
Set up a new API user and insert the information under settings on the Newsletter2Go web site.
|
17 |
</p></description>
|
18 |
-
<notes>
|
19 |
-
<authors><author><name>Steffen</name><user>
|
20 |
-
<date>2014-
|
21 |
-
<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="
|
23 |
<compatible/>
|
24 |
-
<dependencies
|
25 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>NL2go_Sync</name>
|
4 |
+
<version>1.3.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>
|
15 |
<p>Get the extension key on this site and install the Newsletter2Go Magento Extension in your Magento shop. <br />
|
16 |
Set up a new API user and insert the information under settings on the Newsletter2Go web site.
|
17 |
</p></description>
|
18 |
+
<notes>The plugin is more robust to different configurations and does not depend on Class 'Mage_Sync_Helper_Data' anymore</notes>
|
19 |
+
<authors><author><name>Steffen</name><user>Newsletter2Go</user><email>info@newsletter2go.de</email></author></authors>
|
20 |
+
<date>2014-11-21</date>
|
21 |
+
<time>15:24:49</time>
|
22 |
+
<contents><target name="magelocal"><dir name="NL2go"><dir name="Sync"><dir name="Helper"><file name="Data.php" hash="70d1fd7b2bb9ef63002d47a56e0ea66c"/></dir><dir name="Model"><dir name="Newsletter"><dir name="Api"><file name="V2.php" hash="720deb12cd47b1866c7a8bdd9e90c415"/></dir><file name="Api.php" hash="0139d3b2ef2ed98a10b3d7a14b6f7959"/></dir></dir><dir name="etc"><file name="api.xml" hash="7e11289db23d52088f15c1654b35f3a8"/><file name="config.xml" hash="8803e6d9ecbc3167cfa67089426bea66"/><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><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
25 |
</package>
|