1

I need to add new or update the customer db. I must to synchronize the customer db of magento with a another db.

I need make this each 24h.

I think this:

  • if entity_id exist into db magento i update all fields

  • if entity id not exist into db magento i insert the new customer

it's correct?

there is a script for update or add new customers?

1
  • ` thanks a lot. i have tried the script but Fatal error: Call to a member function getModelInstance() on a non-object in /srv/www/vhosts/domain-com/app/Mage.php on line 463 ` comment by @Alessandro Gnola
    – Amit Bera
    Commented Oct 13, 2015 at 17:25

1 Answer 1

1

Depends how the correlation is made between magento customer and your other db. You can create a new customer attribute, let's say otherdb_customer_id. If the ids are the same, then you don't need this attribute.

And, to import you can use this extension: http://avstudnitz.github.io/AvS_FastSimpleImport/customers.html

This is how you use it:

    $rowData = array(
        array(
           'otherdb_customer_id'       => $arrCustomer['customer_id'],
           '_website'                  => 'YOUR_WEBSITE_NAME',
           '_store'                    => 'YOUR_STORE_NAME',
           'email'                     => $arrCustomer['email_address'],
           'group_id'                  => '1', //PRIVAT (must have the id of the group not the string value)
           'disable_auto_group_change' => 0,
           'firstname'                 => $arrCustomer['firstname'],
           'middlename'                => '',
           'lastname'                  => $arrCustomer['lastname'],
           'password_hash'             => $arrCustomer['password'],
           'taxvat'                    => '',
           'gender'                    => $arrCustomer['gender'],
           'customer_activated'        => 'yes',
           'is_subscribed'             => 0,
           'prefix'                    => $arrCustomer['prefix'],
           '_address_prefix'           => $arrCustomer['prefix'],
           '_address_firstname'        => $arrCustomer['firstname'],
           '_address_middlename'       => '',
           '_address_lastname'         => $arrCustomer['lastname'],
           '_address_street'           => $arrCustomer['street'],
           '_address_city'             => $arrCustomer['city'],
           '_address_country_id'       => $arrCustomer['iso_code'],
           '_address_postcode'         => $arrCustomer['postcode'],
           '_address_telephone'        => $arrCustomer['telephone'],
           '_address_company'          => $arrCustomer['company'],
           '_address_fax'              => $arrCustomer['fax'],
           '_address_house_number'     => $arrCustomer['house_nr'],
           '_address_default_billing_' => 1,
           '_address_default_shipping_'=> 0,
    ),
    array(
           '_website'                  => null,
           'email'                     => null,
           '_address_prefix'           => $arrCustomer['prefix'],
           '_address_firstname'        => $arrCustomer['firstname'],
           '_address_middlename'       => '',
           '_address_lastname'         => $arrCustomer['lastname'],
           '_address_street'           => $arrCustomer['street'],
           '_address_city'             => $arrCustomer['city'],
           '_address_country_id'       => $arrCustomer['iso_code'],
           '_address_postcode'         => $arrCustomer['postcode'],
           '_address_telephone'        => $arrCustomer['telephone'],
           '_address_company'          => $arrCustomer['company'],
           '_address_fax'              => $arrCustomer['fax'],
           '_address_house_number'     => $arrCustomer['house_nr'],
           '_address_default_billing_' => 0,
           '_address_default_shipping_'=> 1,
    )
);

    try {
        $import = Mage::getModel('fastsimpleimport/import');
        $import->setIgnoreDuplicates(false);
        $import->processCustomerImport($rowData);
    } catch (Exception $e) {                    
        print_r($e->getMessage());
    }

If you need to update a customer, you can maybe change the code a bit, in that extension to handle updates, if it does not allready.

2
  • thanks a lot. i have tried the script but Fatal error: Call to a member function getModelInstance() on a non-object in /srv/www/vhosts/domain-com/app/Mage.php on line 463 Commented Oct 14, 2015 at 7:14
  • Have you copied the extension in your app folder ? Is it enabled ? Where you run your script, you included Mage.php and then Mage::app(); that if its not inside magento environment..
    – raduparvan
    Commented Oct 14, 2015 at 8:56

Your Answer

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

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