Question

I need to import a load of customers to a third party email company but need to only import those that are currently subscribed to newsletters. The import itself has to be a file of customer details which I need to generate. I know I could load up all customers into a collection and iterate through them, only inserting those that are subscribed into the import file but as we have 90000 plus customers I would rather just load the ones that are subscribed into the collection. The import itself uses an API but it needs to have the import file added as an attachment (fine doing that, just including it for information).

Any ideas?

Was it helpful?

Solution

You have to join EAV collection with regular table. It is achievable with joinTable method of Mage_Eav_Model_Entity_Collection_Abstract class. The forth parameter defines the WHERE condition because apparently you can't use addAttributeToFilter method here.

$collection = Mage::getModel('customer/customer')->getCollection();
$collection->addNameToSelect()
    ->joinTable('newsletter_subscriber', 'customer_id=entity_id', array('subscriber_status'), '{{table}}.subscriber_status=1');

Please let me know if something is unclear.

OTHER TIPS

You can try one thing, this is the way I had do such thing previously.

Query against newsletter_subscriber table and get customer_id, so you have customer id then load customer data with this id.

This is an easy, fairly performant way to do it.

$newsletterSubscribers = Mage::getResourceModel('newsletter/subscriber_collection')
        ->addFieldToFilter('subscriber_status', array ('eq' => 1)); // 1 is subscribed

You can then iterate through the subscribers.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top