Just another WordPress.com weblog

-Make new module
-add this action

public function saveAction() {
if ($data = $this->getRequest()->getPost()) {
if(isset($_FILES[‘filename’][‘name’]) && $_FILES[‘filename’][‘name’] != ”) {
try {
$uploader = new Varien_File_Uploader(‘filename’);
$uploader->setFilesDispersion(false);
$path = Mage::getBaseDir(‘var’) . DS .”import” . DS;
$uploader->save($path, date(‘Y-m-d’).$_FILES[‘filename’][‘name’] );
} catch (Exception $e) {
}
$data[‘filename’] = $_FILES[‘filename’][‘name’];
$rows = array();
$handle = fopen($path.date(‘Y-m-d’).$data[‘filename’],’r’);
$row_count = 0;
while (($data = fgetcsv($handle, 1000, “,”)) !== FALSE) {
$email = trim($data[1]);
if (Zend_Validate::is($email, ‘EmailAddress’))
{
$row_count++;
$status = Mage::getModel(‘newsletter/subscriber’)->subscribe($email);
}
}
}
}
Mage::getSingleton(‘adminhtml/session’)->addSuccess(Mage::helper(‘adminhtml’)->__($row_count.’ Records Imported Sucessfully’));
$this->_redirect(‘*/*/’);
}

give csv to this code , it will put all d records in newsletter_subscriber table

-Bijal Bhavsar

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: