2014-09-05 11 views
5

Tôi có csv in which have lot of email is exit, muốn assign those email to newsleter subscription list. Ai tôi sẽ làm ....Cách nhập người đăng ký bản tin người dùng csv trong magento

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

+0

là nó không làm việc –

+0

Thêm tập tin import.php trong thư mục gốc cũng csv tập tin và csv tên tập tin là users.csv và mã bên trong là cùng một kiểm tra –

+0

là bạn có cửa hàng duy nhất ya đa cửa hàng –

Trả lời

7

Như krupal patel không có đủ uy tín cho bài trả lời như vậy, thay vì anh ấy tôi đã đưa câu trả lời.

Thực hiện theo bước này

Bước 1 Thêm import.php file in Magento root directory mã này nên

 <?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"; 

Bước 2Add subscribers.csv tập tin trong Magento root directory

Bước 3:Run import.php file trong thư mục gốc như (http://domainname.com/import.php)

Bước 4: Tới menu quản trị Newsletter > Newsletter Subscribers and finally you subscriber user CSV file import

Visit link cho mã = ​​http://krupalpatel92.blogspot.com/2014/09/magento-newsletter-subscriber-csv-file.html

Cheer up krupal patel

+0

patrup krupal, vui lòng chấp nhận câu trả lời này. –

+0

Tôi đã cập nhật mã này để nhập email người dùng có trạng thái. cũng cập nhật định dạng tệp CSV –

+0

Goood .. krupal .... –

Các vấn đề liên quan