How to export customers list as Google Spreadsheet document.
Please download the attached file as upload to your Google Docs.
<?php
require_once 'app/Mage.php';
umask ( 0 );
$currentStore = Mage::app ()->getStore ()->getId ();
Mage::app ()->setCurrentStore ( Mage_Core_Model_App::ADMIN_STORE_ID );
require_once 'lib/Zend/Loader.php';
Zend_Loader::loadClass ( 'Zend_Http_Client' );
Zend_Loader::loadClass ( 'Zend_Gdata' );
Zend_Loader::loadClass ( 'Zend_Gdata_ClientLogin' );
Zend_Loader::loadClass ( 'Zend_Gdata_Spreadsheets' );
$u = "Google Username";
$p = "Google Password";
$spreadsheetKey = 'Your Google Spreadsheet Key';
$worksheetId = 'od6';
$authService = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
$httpClient = Zend_Gdata_ClientLogin::getHttpClient ( $u, $p, $authService );
$spreadsheetService = new Zend_Gdata_Spreadsheets ( $httpClient );
$query = new Zend_Gdata_Spreadsheets_DocumentQuery ( );
$query->setSpreadsheetKey ( $spreadsheetKey );
$feed = $spreadsheetService->getWorksheetFeed ( $query );
$customers = Mage::getResourceModel ( 'customer/customer_collection' );
$customerIds = $customers->getAllIds ();
foreach ( $customerIds as $customerId ) {
$customer = Mage::getModel ( 'customer/customer' )->load ( $customerId );
$email = $customer->getEmail();
foreach ( $customer->getAddresses () as $address ) {
$data = $address->toArray ();
$rowData = array ('email'=> $email, 'firstname' => $data ['firstname'], 'middlename' => $data ['middlename'], 'lastname' => $data ['lastname'], 'company' => $data ['company'], 'city' => $data ['city'], 'country' => $data ['country_id'], 'region' => $data ['region'], 'postcode' => $data ['postcode'], 'telephone' => $data ['telephone'], 'fax' => $data ['fax'], 'region' => $data ['region_id'], 'street' => $data ['street'] );
$insertedListEntry = $spreadsheetService->insertRow ( $rowData, $spreadsheetKey, $worksheetId );
}
}
?>
| Attachment | Size |
|---|---|
| Magento - Mailing List.xls | 12 KB |