0

I'm new to Magento, and I want to add customer details to the customer_entity table of Magento. My question is, if I run the following query (via PHP):

INSERT INTO 
    `customer_entity` ('entity_type_id', attribute_set_id, foo, bar, baz)
    values ('some', 'placeholder', 'values')"
);

Is that enough to create a proper Customer record? When I look at the databse, I see a lot of tables related to customers, such as

  • customer_entity_datetime
  • customer_entity_decimal
  • customer_entity_int
  • customer_entity_text
  • customer_entity_varchar
  • customer_group

I'm trying to produce a script which is not connected to the Magento code. It should be independent, but I want it to be able to insert customers in the Magento tables.

How I can do this?

2 Answers 2

3

In addition to clockworkgeek's point about later upgrades to the system, you also avoid much of the complexity of Magento's EAV system by using the framework.

User data in Magento is strung out between the customer_entity_* tables that you mentioned, and adding new data to the system will require you to grab each of the column definitions (from eav_attribute) and place the data appropriately. This is even more of a pain than it seems.

In summary, no, your update statement is not enough to save user data. Magento executes dozens of queries to add customers to the system, and you'll need do the same.

Hope that helps!

Thanks, Joe

2

You will save yourself a lot of bother by using the Magento structure.

require PATH_TO_MAGENTO_FOLDER . '/app/Mage.php';
Mage::app();

$newCustomer = Mage::getModel('customer/customer');
$newCustomer->setFirstname('Foo')
            ->setLastname('Bar')
            ... // Set all the various details here
            ->save();

Trying to handle the assorted entity tables is a recipe for disaster as they might be altered significantly by upgrading/adding new extensions to Magento which would then break your script.

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.