Search code examples
phpsqlmagentoentity-attribute-value

Adding Customers to Magento in raw SQL


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?


Solution

  • 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