magento客户/客户返回错误的值

I'm trying to import a bunch of customer information from Magento into an external application. The external application already knows their entity_ids, and I basically want to get their customer objects and modify some entries.

Here's the code (Thank you StackOverflow for helping me get set up!)

$collection = Mage::getModel('customer/customer');
/* each $key is an entity ID */
foreach (array_keys($concatresult) as $key) {
   $collection->load($key);
   Zend_Debug::Dump("Key: " . $key . " Forum username:" . $collection->getForumUsername() . " Name: " .  $collection->getName());
}

Heres the output. Entities 38, 48, 131 have "Forum Username" empty (which is a custom field):

string(53) "Key: 10955 Forum username:user1 Name: F1 L1"
string(47) "Key: 38 Forum username:user1 Name: F2 L2"
string(51) "Key: 48 Forum username:user1 Name: F3 L3"
string(50) "Key: 131 Forum username:user1 Name: F4 L4"

Yet the last value returned is repeated.

I have checked:

  • just returning forum_username entries for 38, 48, 131 returns NULL as expected.

What might be going wrong?

Solved it. I needed to load the customer object inside the loop!

/* each $key is an entity ID */
foreach (array_keys($concatresult) as $key) {
    $collection = Mage::getModel('customer/customer');
    $collection->load($key);
    Zend_Debug::Dump("Key: " . $key . " Forum username:" . $collection->getForumUsername() . " Name: " .  $collection->getName());
}