2

I need to export the following customer information from our Magento site:

  • First name
  • Last name
  • Email
  • Store ID

Trying to do so via System > Import/Export > Dataflow - Profiles just times out, despite several attempts at increasing various PHP memory and timeout limits on the server.

Please can someone help?

Thanks in advance.

Mark

4

For this you can create your php script, create one php file on root directory of your website and use following code.for ex: if file name is exportCustomer.php and your url is like http://magentowebsite.com then after placing this file in root you need to visit url like http://magentowebsite.com/exportCustomer.php then you will get a csv in your root directory with name as customers.csv

<?php
require_once('app/Mage.php');
umask(0);
if (!Mage::isInstalled()) {
    echo "Application is not installed yet, please complete install wizard first.";
    exit;
}
// Only for urls // Don't remove this
$_SERVER['SCRIPT_NAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_NAME']);
$_SERVER['SCRIPT_FILENAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_FILENAME']);
Mage::app('admin')->setUseSessionInUrl(false);
Mage::setIsDeveloperMode(true); ini_set('display_errors', 1); error_reporting(E_ALL);
try {
    Mage::getConfig()->init();
    Mage::app();   
} catch (Exception $e) {
    Mage::printException($e);
}
ini_set('memory_limit','500M');
$customerCount = 0;
try{
    //configure the collection filters.
    $collection = Mage::getResourceModel('customer/customer_collection')
    ->addAttributeToSelect('firstname')
    ->addAttributeToSelect('lastname')
    ->addAttributeToSelect('email')
    ->addAttributeToSelect('store_id');
    //Add a page size to the result set.
    $collection->setPageSize(50);
    //discover how many page the result will be.
    $pages = $collection->getLastPageNumber();
    $currentPage = 1;
    //This is the file to append the output to.
    $fp = fopen('customers.csv', 'w');
    $addedKeys = false;
    do{
         //Tell the collection which page to load.
         $collection->setCurPage($currentPage);
         $collection->load();
         foreach ($collection as $customer){
            //write the collection array as a CSV.
            $customerArray = $customer->toArray();
            $customerREquiredArray['First name'] = $customerArray['firstname'];
            $customerREquiredArray['Last name'] = $customerArray['lastname'];
            $customerREquiredArray['Email'] = $customerArray['email'];
            $customerREquiredArray['Store ID'] = $customerArray['store_id'];
            if($addedKeys == false){
                $keys = array_keys($customerREquiredArray);
                fputcsv($fp, $keys);
                $addedKeys = true;
            }
            //var_dump($customerArray); echo "\n\n";
            fputcsv($fp, $customerREquiredArray);
            //fwrite($fp,print_r($customerArray,true) . chr(10) );
            $customerCount++;
         }
         $currentPage++;
         //make the collection unload the data in memory so it will pick up the next page when load() is called.
         $collection->clear();
         //break; //DEBUG
         echo "Finished page $currentPage of $pages \n"; 
    } while ($currentPage <= $pages);
    fclose($fp);
} catch (Exception $e) {
    //$response['error'] = $e->getMessage();
    Mage::printException($e);
}
echo "Saved $customerCount customers to csv file \n";

Hope this will help you.

  • Thanks for your suggestion! This works perfectly on Magento CE v1.9.2.4 but when I try it on v1.7.0.2 I get the following error: Notice: Undefined index: lastname in exportCustomer.php on line 44 – user9539 May 31 '16 at 9:38
  • i don't have knowledge of v1.7.0.2 but i think in this version field lastname not used edit the code and place this code echo '<pre>'; print_r($customerArray); exit; on line no 43-46 you under foreach loop you will got to know what are the fields available their. – Ashish Madankar M2 Professiona May 31 '16 at 9:55
  • These are the fields are being displayed. lastname looks to be in the same format? Array ( [entity_id] => [entity_type_id] => [attribute_set_id] => [website_id] => [email] => [group_id] => [increment_id] => [store_id] => [created_at] => [updated_at] => [is_active] => [disable_auto_group_change] => [firstname] => [lastname] => ) – user9539 May 31 '16 at 10:05
  • can you pls come for a chat @ chat.stackexchange.com/rooms/40538/chat-with-user9539 – Ashish Madankar M2 Professiona May 31 '16 at 10:16
  • comment code form line no 43-46 and on line no 48 and 53creplace $customerREquiredArray with $customerArray and check if it works or not. – Ashish Madankar M2 Professiona May 31 '16 at 11:05
0

Overwrite app\code\local\Mage\ImportExport\Model\Export\Entity\Customer.php

And in line 200 modify code like this:

if ($addressAttribute) {
                    if ($addressAttribute->getFrontendInput() == 'multiselect') {
                        $optionIds   = explode(',', $value);
                        $optionTexts = array();
                        foreach ($optionIds as $optionId) {
                            $optionText             = $addressAttribute->getSource()->getOptionText($optionId);
                            $optionTexts[$optionId] = $optionText;
                        }
                        $addrAttributeMultiSelect[$address['parent_id']][$address->getId()][$column] = $optionTexts;
                    } elseif ($attrValues) {
                        $value = $attrValues[$value];
                    }
                }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.