Created
June 20, 2014 10:22
-
-
Save fballiano/1698d2a5da4ea6d57ae7 to your computer and use it in GitHub Desktop.
Import newsletter subscribers (without sending any emails) into Magento
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$store_id = 5; | |
$csv_filepath = "newsletter.csv"; | |
$email_csv_column_index = 2; | |
$csv_delimiter = ','; | |
$csv_enclosure = '"'; | |
$magento_path = __DIR__; | |
require "{$magento_path}/app/Mage.php"; | |
Mage::app()->setCurrentStore($store_id); | |
$fp = fopen($csv_filepath, "r"); | |
if (!$fp) die("{$csv_filepath} not found\n"); | |
while (($row = fgetcsv($fp, 0, $csv_delimiter, $csv_enclosure)) !== false) { | |
$email = trim($row[$email_csv_column_index]); | |
if (strlen($email) == 0) continue; | |
echo "$email"; | |
$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email); | |
if ($subscriber->getId()) { | |
echo " already subscribed\n"; | |
continue; | |
} | |
Mage::getModel('newsletter/subscriber')->setImportMode(true)->subscribe($email); | |
echo " ok\n"; | |
} | |
echo "Import finished\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment