MKMage_Exportcustomers - Version 0.1.0

Version Notes

This version allows the admin to export customer data of all customers, only guests or only registered customers. It exports the customer's email, first name, middle name, last name, suffix, prefix, date of birth, gender and group.

Download this release

Release Info

Developer MKMage
Extension MKMage_Exportcustomers
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/local/MKMage/Exportcustomers/Block/Exportcustomers.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class MKMage_Exportcustomers_Block_Exportcustomers extends Mage_Core_Block_Template
3
+ {
4
+
5
+ }
app/code/local/MKMage/Exportcustomers/Helper/Data.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+
3
+ class MKMage_Exportcustomers_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+ }
app/code/local/MKMage/Exportcustomers/controllers/Adminhtml/ExportcustomersController.php ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class MKMage_Exportcustomers_Adminhtml_ExportcustomersController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+
6
+ public function indexAction()
7
+ {
8
+ $this->loadLayout()->renderLayout();
9
+ }
10
+
11
+ public function exportcustomersAction() {
12
+ $data = $this->getRequest()->getPost();
13
+ try{
14
+ if(isset($data['filename'])){
15
+ $filename=$data['filename'];
16
+ }
17
+ else{
18
+ $filename="exportcustomers";
19
+ }
20
+ $resource = Mage::getSingleton('core/resource');
21
+ $readConnection = $resource->getConnection('core_read');
22
+ if($data['customers_type']=="all"){
23
+ $query = 'SELECT * FROM ' . $resource->getTableName('sales/order');
24
+ $results = $readConnection->fetchAll($query);
25
+ $email_arr=array();
26
+ $i=0;$j=0;
27
+ $filename=$_POST['filename'];
28
+
29
+ foreach($results as $r){
30
+ $email_arr[$i]=array($r['customer_email'],$r['customer_firstname'],$r['customer_middlename'],$r['customer_lastname'],$r['customer_suffix'],$r['customer_prefix'],$r['customer_dob'],$r['customer_gender'],Mage::getModel('customer/group')->load($r['customer_group_id'])->getCustomerGroupCode());
31
+ $i++;
32
+ }
33
+ $query2 = 'SELECT * FROM customer_entity';
34
+ $email_arr2=array();
35
+ $results2 = $readConnection->fetchAll($query2);
36
+ foreach($results2 as $r2){
37
+
38
+ $customer = Mage::getModel("customer/customer");
39
+ $customer->setWebsiteId(Mage::app()->getWebsite('admin')->getId());
40
+ $customer->load($r2['entity_id']);
41
+ $email_arr2[$j]=array($customer->getEmail(),$customer->getFirstname(),$customer->getMiddlename(),$customer->getLastname(),$customer->getSuffix(),$customer->getPrefix(),$customer->getDob(),$customer->getResource()->getAttribute('gender')->getSource()->getOptionText($customer->getData('gender')),Mage::getModel('customer/group')->load($customer->getGroupId())->getCustomerGroupCode());
42
+ $j++;
43
+
44
+ }
45
+ $array_both = array_merge($email_arr,$email_arr2);
46
+ $array_both = array_map("unserialize", array_unique(array_map("serialize", $array_both)));
47
+ $content="Email,First name,Middle name,Last name,Suffix,Prefix,Date of birth,Gender,Group"."\n";
48
+ foreach($array_both as $em){
49
+ $content.=$em[0];
50
+ $content.=",";
51
+ $content.=$em[1];
52
+ $content.=",";
53
+ $content.=$em[2];
54
+ $content.=",";
55
+ $content.=$em[3];
56
+ $content.=",";
57
+ $content.=$em[4];
58
+ $content.=",";
59
+ $content.=$em[5];
60
+ $content.=",";
61
+ $content.=$em[6];
62
+ $content.=",";
63
+ $content.=$em[7];
64
+ $content.=",";
65
+ $content.=$em[8];
66
+ $content.=",";
67
+ $content.=$em[9];
68
+ $content.="\n";
69
+ }
70
+ }
71
+ echo $content;
72
+ if($data['customers_type']=="registered"){
73
+ $query2 = 'SELECT * FROM customer_entity';
74
+ $email_arr2=array();
75
+ $j=0;
76
+ $results2 = $readConnection->fetchAll($query2);
77
+ foreach($results2 as $r2){
78
+ $customer = Mage::getModel("customer/customer");
79
+ $customer->setWebsiteId(Mage::app()->getWebsite('admin')->getId());
80
+ $customer->load($r2['entity_id']);
81
+ $email_arr2[$j]=array($customer->getEmail(),$customer->getFirstname(),$customer->getMiddlename(),$customer->getLastname(),$customer->getSuffix(),$customer->getPrefix(),$customer->getDob(),$customer->getResource()->getAttribute('gender')->getSource()->getOptionText($customer->getData('gender')),Mage::getModel('customer/group')->load($customer->getGroupId())->getCustomerGroupCode());
82
+ $j++;
83
+ }
84
+ $content="Email,First name,Middle name,Last name,Suffix,Prefix,Date of birth,Gender,Group"."\n";
85
+ foreach($email_arr2 as $em){
86
+ $content.=$em[0];
87
+ $content.=",";
88
+ $content.=$em[1];
89
+ $content.=",";
90
+ $content.=$em[2];
91
+ $content.=",";
92
+ $content.=$em[3];
93
+ $content.=",";
94
+ $content.=$em[4];
95
+ $content.=",";
96
+ $content.=$em[5];
97
+ $content.=",";
98
+ $content.=$em[6];
99
+ $content.=",";
100
+ $content.=$em[7];
101
+ $content.=",";
102
+ $content.=$em[8];
103
+ $content.=",";
104
+ $content.=$em[9];
105
+ $content.="\n";
106
+ }
107
+ }
108
+ if($data['customers_type']=="guests"){
109
+ $query = 'SELECT * FROM ' . $resource->getTableName('sales/order');
110
+ $results = $readConnection->fetchAll($query);
111
+ $email_arr=array();
112
+ $i=0;
113
+ $filename=$_POST['filename'];
114
+ foreach($results as $r){
115
+ $email_arr[$i]=array($r['customer_email'],$r['customer_firstname'],$r['customer_middlename'],$r['customer_lastname'],$r['customer_suffix'],$r['customer_prefix'],$r['customer_dob'],$r['customer_gender'],Mage::getModel('customer/group')->load($r['customer_group_id'])->getCustomerGroupCode());
116
+ $i++;
117
+ }
118
+ $email_unique = array_map("unserialize", array_unique(array_map("serialize", $email_arr)));
119
+ $content="Email,First name,Middle name,Last name,Suffix,Prefix,Date of birth,Gender,Group"."\n";
120
+ foreach($email_unique as $em){
121
+ $customer = Mage::getModel('customer/customer');
122
+ $customer->setWebsiteId(Mage::app()->getWebsite('admin')->getId());
123
+ $customer->loadByEmail(trim($em));
124
+ if (!$customer->getId()) {
125
+ $content.=$em[0];
126
+ $content.=",";
127
+ $content.=$em[1];
128
+ $content.=",";
129
+ $content.=$em[2];
130
+ $content.=",";
131
+ $content.=$em[3];
132
+ $content.=",";
133
+ $content.=$em[4];
134
+ $content.=",";
135
+ $content.=$em[5];
136
+ $content.=",";
137
+ $content.=$em[6];
138
+ $content.=",";
139
+ $content.=$em[7];
140
+ $content.=",";
141
+ $content.=$em[8];
142
+ $content.=",";
143
+ $content.=$em[9];
144
+ $content.="\n";
145
+ }
146
+ }
147
+ }
148
+ $fp = fopen(Mage::getBaseDir('media'). "/exportcustomers/".$filename.".csv","wb");
149
+ fwrite($fp,$content);
150
+ fclose($fp);
151
+ Mage::getSingleton('adminhtml/session')->addSuccess('Customers are successfully exported. Click <a href="'.Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).'media/exportcustomers/'.$filename.'.csv" download>here</a> to download');
152
+ }catch (Exception $e) {
153
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
154
+ }
155
+ $this->_redirect('*/*/');
156
+ }
157
+ }
app/code/local/MKMage/Exportcustomers/etc/config.xml ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <MKMage_Exportcustomers>
5
+ <version>0.1.0</version>
6
+ </MKMage_Exportcustomers>
7
+ </modules>
8
+ <admin>
9
+ <routers>
10
+ <exportcustomers>
11
+ <use>admin</use>
12
+ <args>
13
+ <module>MKMage_Exportcustomers</module>
14
+ <frontName>exportcustomers</frontName>
15
+ </args>
16
+ </exportcustomers>
17
+ </routers>
18
+ </admin>
19
+ <adminhtml>
20
+ <menu>
21
+ <main_menu translate="title" module="exportcustomers">
22
+ <title>MKMage</title>
23
+ <sort_order>70</sort_order>
24
+ <children>
25
+ <exportcustomers translate="title" module="exportcustomers">
26
+ <title>Export Customers</title>
27
+ <sort_order>100</sort_order>
28
+ <action>exportcustomers/adminhtml_exportcustomers</action>
29
+ </exportcustomers>
30
+ </children>
31
+ </main_menu>
32
+ </menu>
33
+ <acl>
34
+ <resources>
35
+ <all>
36
+ <title>Allow Everything</title>
37
+ </all>
38
+ <admin>
39
+ <children>
40
+ <system>
41
+ <children>
42
+ <config>
43
+ <children>
44
+ <exportcustomers>
45
+ <title>MKMage - All</title>
46
+ </exportcustomers>
47
+ </children>
48
+ </config>
49
+ </children>
50
+ </system>
51
+ </children>
52
+ </admin>
53
+ </resources>
54
+ </acl>
55
+ <layout>
56
+ <updates>
57
+ <exportcustomers>
58
+ <file>exportcustomers.xml</file>
59
+ </exportcustomers>
60
+ </updates>
61
+ </layout>
62
+ </adminhtml>
63
+ <global>
64
+ <models>
65
+ <exportcustomers>
66
+ <class>MKMage_Exportcustomers_Model</class>
67
+ </exportcustomers>
68
+ </models>
69
+ <blocks>
70
+ <exportcustomers>
71
+ <class>MKMage_Exportcustomers_Block</class>
72
+ </exportcustomers>
73
+ </blocks>
74
+ <helpers>
75
+ <exportcustomers>
76
+ <class>MKMage_Exportcustomers_Helper</class>
77
+ </exportcustomers>
78
+ </helpers>
79
+ </global>
80
+ </config>
app/design/adminhtml/default/default/layout/exportcustomers.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <exportcustomers_adminhtml_exportcustomers_index>
4
+ <update handle="exportcustomers_index"/>
5
+ <reference name="content">
6
+ <block type="adminhtml/template" name="exportcustomers" template="exportcustomers/exportcustomers.phtml"/>
7
+ </reference>
8
+ </exportcustomers_adminhtml_exportcustomers_index>
9
+ </layout>
app/design/adminhtml/default/default/template/exportcustomers/exportcustomers.phtml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="content-header">
2
+ <table cellspacing="0" class="grid-header">
3
+ <tr>
4
+ <td><h3>Export All Customers Now</h3></td>
5
+ <td class="a-right">&emsp;
6
+ </td>
7
+ </tr>
8
+ </table>
9
+ </div>
10
+ <div class="entry-edit">
11
+ <form id="edit_form" name="edit_form" method="post" action="<?php echo $this->getUrl('*/*/exportcustomers')?>">
12
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
13
+ <h4 class="icon-head head-edit-form fieldset-legend">Export Customers Form</h4>
14
+ <fieldset id="my-fieldset">
15
+ <table cellspacing="0" class="form-list">
16
+ <tr><td>Filename: <input type="text" name="filename"></td></tr>
17
+ <tr><td><input type="radio" name="customers_type" value="all" selected="selected"> All Customers</td></tr>
18
+ <tr><td><input type="radio" name="customers_type" value="guests"> Guest customers only</td></tr>
19
+ <tr><td><input type="radio" name="customers_type" value="registered"> Registered customers only</td></tr>
20
+ <tr><td><button onclick="editForm.submit()" class="scalable save" type="button"><span>Export Customers</span></button></td></tr>
21
+ </table>
22
+ </fieldset>
23
+ </form>
24
+ </div>
25
+ <script type="text/javascript">
26
+ var editForm = new varienForm('edit_form');
27
+ </script>
28
+ <style>
29
+ #my-fieldset td{padding:5px}
30
+ #my-fieldset select{min-height:150px;}
31
+ </style>
app/etc/modules/MKMage_Exportcustomers.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+ <MKMage_Exportcustomers>
4
+ <active>true</active>
5
+ <codePool>local</codePool>
6
+ </MKMage_Exportcustomers>
7
+ </modules>
8
+ </config>
media/exportcustomers/.DS_Store ADDED
Binary file
media/exportcustomers/.csv ADDED
@@ -0,0 +1 @@
 
1
+ Email,First name,Middle name,Last name,Suffix,Prefix,Date of birth,Gender,Group
media/exportcustomers/export_all.csv ADDED
@@ -0,0 +1,2 @@
 
 
1
+ Email,First name,Middle name,Last name,Suffix,Prefix,Date of birth,Gender,Group
2
+ jon.smith@example.com,Jon,,Smith,,,1990-07-22 00:00:00,Male,General,
media/exportcustomers/export_all12.csv ADDED
@@ -0,0 +1 @@
 
1
+ Email,First name,Middle name,Last name,Suffix,Prefix,Date of birth,Gender,Group
media/exportcustomers/export_customers.csv ADDED
@@ -0,0 +1,2 @@
 
 
1
+ Email,First name,Middle name,Last name,Suffix,Prefix,Date of birth,Gender,Group
2
+ jon.smith@example.com,Jon,,Smith,,,1990-07-22 00:00:00,Male,General,
media/exportcustomers/test.csv ADDED
@@ -0,0 +1 @@
 
1
+ Email,First name,Middle name,Last name,Suffix,Prefix,Date of birth,Gender,Group
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>MKMage_Exportcustomers</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license>Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Module that exports all type of customers.</summary>
10
+ <description>Module that exports all type of customers. Easily export customer data. Choose if you want to export all Magento customers, only the registered one or the guest customers. A CSV file is generated and saved and you can download it immediately from the success message in the Magento backend. This module is supported by Magento version 1.5.0.0 and all later versions, including 1.9.1.1</description>
11
+ <notes>This version allows the admin to export customer data of all customers, only guests or only registered customers. It exports the customer's email, first name, middle name, last name, suffix, prefix, date of birth, gender and group.</notes>
12
+ <authors><author><name>MKMage</name><user>mkmage</user><email>igor@mkmage.com</email></author></authors>
13
+ <date>2015-06-02</date>
14
+ <time>20:53:42</time>
15
+ <contents><target name="magelocal"><dir name="MKMage"><dir name="Exportcustomers"><dir name="Block"><file name="Exportcustomers.php" hash="0966b4bb80974b5c91ef6d5ba93d3147"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="ExportcustomersController.php" hash="6320375bf5e04d33efce9f1229bcbcc8"/></dir></dir><dir name="etc"><file name="config.xml" hash="17a01d2a5572ac3accb619b8306084b9"/></dir><dir name="Helper"><file name="Data.php" hash="147ba7b4a38efe59b6c7fe3c70dfa2ce"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="exportcustomers.xml" hash="0654d037492a0980498c04701e1e007b"/></dir><dir name="template"><dir name="exportcustomers"><file name="exportcustomers.phtml" hash="df3be56ce1c5dee9baf6e60268139f74"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="MKMage_Exportcustomers.xml" hash="754d9593ca78da639376f26bfe3fd335"/></dir></target><target name="magemedia"><dir name="exportcustomers"><file name="export_all.csv" hash="15197c6d8eeca479084769ad587da384"/><file name="export_all12.csv" hash="7134fa0fca18944b211d328e3c38035c"/><file name="export_customers.csv" hash="15197c6d8eeca479084769ad587da384"/><file name="test.csv" hash="7134fa0fca18944b211d328e3c38035c"/><file name=".DS_Store" hash="194577a7e20bdcc7afbb718f502c134c"/><file name=".csv" hash="7134fa0fca18944b211d328e3c38035c"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.5.0.0</min><max>1.9.0.0</max></package><extension><name>gd</name><min>2.0.28</min><max>3.0</max></extension></required></dependencies>
18
+ </package>