3

Is there a way to import customer entity_id? I found solution how to export customer entity_id but when I try to import its not working. Still there is same number in ascending order. so 1,2,3,4,5,....

http://dltr.org/blog/magento/146/Magento-How-to-Export-Customer-ID-with-ImportExport-Profile

2 Answers 2

2

Why do you need the entity_id? This seems like a really bad approach since that id is used to connect the address_ book table and other things to the customer records. On a system that already has data in it this could cause a lot of problems. You would need to do it using direct mysql queries by first turning off foreign key checks SET foreign_key_checks = 0; That will allow you to save the entity_id.

If you need to do this for some other reason then I suggest adding a new customer attribute called old_id or something similar and import that information there. You could use the customer e-mail address to look up the record then reference that old_id field.

3
  • the thing is that i need new attribute for customer "customer account number" . but its better to create new attribute rather to change entity_id
    – Webjuice
    Feb 9, 2015 at 15:25
  • For sure. Creating a new attribute and storing the old info there will ensure that you don't break anything by disabling foreign keys or trying to mess around with changing entity_ids Feb 9, 2015 at 15:26
  • so i would like to change state/province to customer account number coz state/province i dont need. where i can change the title. or can you see better option? I beginner in magento . thanks
    – Webjuice
    Feb 9, 2015 at 15:36
2

With a few code changes, you can use the Dataflow Import Customers profile to import customer data including the entity_id. There are two places in the Magento Core (version 1.9) code that prevent the entity_id from being stored during an Dataflow import:

  1. 'entity_id' is one of the fields that have been set to be ignored during import.
  2. 'entity_id' is skipped during the import because it does not have an attribute model associated with it.

The first problem is easily solved: In app\code\core\Mage\Customer\etc\config.xml change the value from 1 to 0 on line 45. That is:

    <config>
        <admin>
            <fieldsets>
                <customer_dataflow>
                    <entity_id>
                        <system>1</system>
                        <ignore>0</ignore>
                    </entity_id>

To solve the second problem, you should extend the saveRow($importData) function in app\code\core\Mage\Customer\Model\Convert\Adapter\Customer. (line numbers conform to the original Core file.) Lines 496 to 529 should be put within the following conditional statement:

    if ($field != 'entity_id') {
        {{lines 496-529}}
    } else { 
        $setValue = $value; 
    }

Then you need to save the customer model before adding the addresses. So on line 537 insert:

    if (isset($importData['entity_id']) {
        $customer->save();
    }

I haven't tested what happens if you try to save the customer model with an entity_id that already exists. My guess is that a MySQL error will be thrown.

I hope this is helpful!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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