开发者

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_d开发者_开发百科atetime
  • 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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜