本文整理汇总了PHP中Mage_Newsletter_Model_Queue::getTemplate方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Newsletter_Model_Queue::getTemplate方法的具体用法?PHP Mage_Newsletter_Model_Queue::getTemplate怎么用?PHP Mage_Newsletter_Model_Queue::getTemplate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Newsletter_Model_Queue
的用法示例。
在下文中一共展示了Mage_Newsletter_Model_Queue::getTemplate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addSubscribersToQueue
public function addSubscribersToQueue(Mage_Newsletter_Model_Queue $queue, array $subscriberIds)
{
$queueData = $queue->getTemplate()->getData();
if ($queue->getUserGroup()) {
$subscriberIds = array();
$groupSubscribers = Mage::getModel("ngroups/ngroups")->getGroupSubscribers($queue->getUserGroup());
$subscriberIds = Mage::helper("ngroups")->getSubscribersAsArray($groupSubscribers);
$newsletterGroup = Mage::getModel("ngroups/ngroups")->load($queue->getUserGroup());
if ($customerGroups = $newsletterGroup->getCustomerGroups()) {
$customerGroups = explode(",", $customerGroups);
foreach ($customerGroups as $customerGroup) {
$customersCollection = Mage::getResourceModel('newsletter/subscriber_collection');
$customersCollection->showCustomerInfo(true)->addSubscriberTypeField()->showStoreInfo();
$customersCollection->getSelect()->joinLeft(array('c' => Mage::getConfig()->getTablePrefix() . 'customer_entity'), 'c.entity_id = main_table.customer_id', array("gid" => "group_id"));
if ($customerGroup > 0) {
$customersCollection->addFieldToFilter("c.group_id", $customerGroup);
} else {
$customersCollection->addFieldToFilter("main_table.group_id", 0);
}
foreach ($customersCollection as $subscribers) {
if (!in_array($subscribers->getSubscriberId(), $subscriberIds)) {
$subscriberIds[] = $subscribers->getSubscriberId();
}
}
}
}
}
if (!$queue->getId() && $queue->getQueueStatus() != Mage_Newsletter_Model_Queue::STATUS_NEVER) {
Mage::throwException(Mage::helper('newsletter')->__('Invalid queue selected'));
}
$select = $this->_getWriteAdapter()->select();
$select->from($this->getTable('queue_link'), 'subscriber_id')->where('queue_id = ?', $queue->getId())->where('subscriber_id in (?)', $subscriberIds);
$usedIds = $this->_getWriteAdapter()->fetchCol($select);
$this->_getWriteAdapter()->beginTransaction();
foreach ($subscriberIds as $subscriberId) {
if (trim($subscriberId) == '0' || trim($subscriberId) == '') {
continue;
}
if (in_array($subscriberId, $usedIds)) {
continue;
}
$data = array();
$data['queue_id'] = $queue->getId();
$data['subscriber_id'] = $subscriberId;
$data['group_id'] = $queue->getUserGroup();
try {
$this->_getWriteAdapter()->insert($this->getTable('queue_link'), $data);
} catch (Exception $e) {
}
}
$this->_getWriteAdapter()->commit();
}