1

Help! Can someone please tell me how to delete unsent newsletters out of the admin panel in Magento? I want to get rid of all of these except the one that is sent. Thanks much.

enter image description here

1 Answer 1

1

Try this code. You need to create a new php file in the root directory of magento. Let it me NLqueueResetter.php.

<?php
//some settings
define('MAGENTO_ROOT', getcwd()); 
$mageFilename = MAGENTO_ROOT . '/app/Mage.php'; 
require_once $mageFilename; 
Mage::setIsDeveloperMode(true); 
ini_set('display_errors', 1); 
umask(0);
//instantiate the app model
Mage::app('admin'); 

// get newsletter queue collection
$collection = Mage::getResourceModel('newsletter/queue_collection')
            ->addSubscribersInfo();

//go through every one look the status
foreach ($collection->getItems() as $item) {

    //need to delete all unsent items
    if($item->getStatus() == Mage_Newsletter_Model_Queue::STATUS_NEVER) {
        $item->delete();    
        continue;
        }

    //need to delete all canceled items
    if($item->getStatus() == Mage_Newsletter_Model_Queue::STATUS_CANCEL) {
        $item->delete();
        continue;   
        }

    //need to delete all canceled items
    if($item->getStatus() == Mage_Newsletter_Model_Queue::STATUS_PAUSE) {
        $item->delete();
        continue;   
        }
 }

By default script will delete all queue items except that are already sent. If you need to keep any other type queue, just comment corresponding if statement.

Now load this file by requesting www.domain.com/NLqueueResetter.php. I didnt try this code before. But it would work I think.

[This answer is a part of #mageStackDay. It is an event conducted by Magento Community members as part of increasing the question-answer ratio. For more information http://www.magestackday.com/]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.