基本上,我需要獲取我的客戶的CSV文件,每天在腳本中自動生成。 我嘗試了幾種方法,但它們太慢或實際上已經耗盡內存。如何循環Magento集合?
* 1)通過收集資源*
$collection = Mage::getResourceModel('customer/customer_collection')
->addAttributeToSelect('email')
->addAttributeToSelect('created_at')
->joinAttribute('billing_company', 'customer_address/company', 'default_billing', null, 'left')
->joinAttribute('billing_street', 'customer_address/street', 'default_billing', null, 'left')
->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');
foreach($collection as $customer) {
echo $customer->getFirstname() . ",";
}
2)的foreach和負載客戶
$collection = Mage::getResourceModel('customer/customer_collection');
foreach($collection as $customer) {
$fullcustomer = Mage::getModel("customer/customer")->load($customer->getId());
echo $fullcustomer->getFirstname() . ",";
}
任何想法的foreach?
謝謝!
這兩項解決方案似乎可行,但雙方似乎特別優化。你能否用這兩種方法解決問題,以便我們可以告訴你在找什麼? – 2010-09-24 13:35:55
嘗試在Magento中使用資源迭代器。看到這個職位:http://stackoverflow.com/questions/7419886/using-magentos-resource-iterator-model-on-a-product-collection – awaage 2012-09-15 02:27:06