How to import newsletter subscribers user csv in magento
Asked Answered
F

1

5

I have csv in which have lot of email is exit,it want to assign those email to newsleter subscription list. Who i will do....

And check how skip for exiting customer because there are already list in newsleter

Followthrough answered 5/9, 2014 at 5:35 Comment(7)
Add import.php file in root directory also csv file and csv filename is subscribers.csv and inside code is same checkFollowthrough
are you have single store ya multi storePaxwax
this code only import email and statusFollowthrough
you can managed store from csv file and import.php file codeFollowthrough
you can not put answer on question section.Please put it in answer section.Paxwax
i have edit and update question and put you code in answer.As you did not get privilege for answer so, i have put your code instead of youPaxwax
Go attempt... if you get above 10 reputation at stackoverflow then you can put answer.I have up vote your question for getting 5 reputation to you.Please accept my answer and you get 2 pint more.Paxwax
P
7

As krupal patel did not have enough reputation for post answer so , instead of him i have put answer.

Follow this step

Step 1 Add import.php file in Magento root directory this code should be

     <?php
    $store_id = 1;
    $csv_filepath = "subscribers.csv";
    $csv_delimiter = ',';
    $csv_enclosure = '"';
    $magento_path = __DIR__;
    require "{$magento_path}/app/Mage.php";

    Mage::app()->setCurrentStore($store_id);
    echo "<pre>";
    $fp = fopen($csv_filepath, "r");

    if (!$fp) die("{$csv_filepath} not found\n");
    $count = 0;

    while (($row = fgetcsv($fp, 0, $csv_delimiter, $csv_enclosure)) !== false){
        if ($count != 0){

            $email = trim($row[1]);
            $type = trim($row[2]);
            $fname = trim($row[3]);
            $lname = trim($row[4]);
            $status = trim($row[5]);
            $website = trim($row[6]);
            $store = trim($row[7]);
            $store_view = trim($row[8]);

            if (strlen($email) == 0) continue;
            echo "$email";
            $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
            if ($subscriber->getId()){
                echo $email . " <b>already subscribed</b>\n";
                continue;
                }

            Mage::getModel('newsletter/subscriber')->setImportMode(true)->subscribe($email);
            $subscriber_status = Mage::getModel('newsletter/subscriber')->loadByEmail($email);

            if ($status == 1){
                  $subscriber_status->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
                  $subscriber_status->save();
                }else if($status == 2){
                  $subscriber_status->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE);
                  $subscriber_status->save();
                }else if($status == 3){
                  $subscriber_status->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED);
                  $subscriber_status->save();
                }else if($status == 4){
                  $subscriber_status->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED);
                  $subscriber_status->save();
                }
                echo $email . " <b>ok</b>\n";
            }

        $count++;

        }

echo "Import finished\n";

Step 2 Add subscribers.csv file in Magento root directory

Step 3: Run import.php file in root directory like ( http://domainname.com/import.php )

Step 4: Go to admin menu Newsletter > Newsletter Subscribers and finally you subscriber user CSV file import

Visit link for code = http://krupalpatel92.blogspot.com/2014/09/magento-newsletter-subscriber-csv-file.html

Cheer up krupal patel

Paxwax answered 5/9, 2014 at 7:21 Comment(2)
I have update this code for import user email with status. also update CSV file formatFollowthrough
Thaks Amit bera you can visit updated code here krupalpatel92.blogspot.in/2014/09/…Followthrough

© 2022 - 2024 — McMap. All rights reserved.