我正在尝试获取所有未取消订阅的客户的列表。那就是我不希望订阅后取消订阅的客户。我可以得到这样的客户名单:
$collection = Mage::getModel('customer/customer')->getCollection()
->addAttributeToSelect('firstname')
->addAttributeToSelect('lastname')
->addAttributeToSelect('email');
我应该对此$系列应用什么来过滤掉未订阅的客户。
提前致谢
答案 0 :(得分:1)
试试这段代码:
$collectionSub = Mage::getModel('newsletter/subscriber')->getCollection()
->addAttributeToSelect('email')
->addFieldToFilter('subscriber_status'. array('eq' => 0)) // 0 not subscribed
->load();
$array = array();
foreach($collectionSub as $sub) {
$array[] = $sub['subscriber_email'];
}
$collection = Mage::getModel('customer/customer')->getCollection()
->addAttributeToSelect('firstname')
->addAttributeToSelect('lastname')
->addAttributeToSelect('email')
->addFieldToFilter('email', array('in', $array);
阅读Magento Wiki。
答案 1 :(得分:0)
最后我这样做了:
$array = array();
$collectionSub = Mage::getResourceModel ('newsletter/subscriber_collection')
-> AddFieldToFilter ('subscriber_status', array ('eq' => 3)); // unsubscribed
foreach($collectionSub as $sub) {
$array[] = $sub['subscriber_email'];
}
$collection = Mage::getModel('customer/customer')->getCollection()
->addAttributeToSelect('firstname')
->addAttributeToSelect('lastname')
->addAttributeToSelect('email')
->addFieldToFilter('email', array('nin', $array)); // all others that have not unsubscribed