Export Newsletter Subscribers To Email Marketing Subscriber

Hi,

I want to export Subscribers from Newsletter Addon to Email Marketing Addon. Before i was using Newsletter addon but now as i want to use Mad mini so i have shifted to Email marketing addon.

Kindly help me.

Thanks

Anyone reply Please

Hello!

For CS-Cart 4.3 we recommend the following solution:

1. Create the PHP file in the root directory of your store, for example, subscribers_to_em.php, with the following content:

require(dirname(FILE) . ‘/init.php’);

fn_load_addon(‘email_marketing’);
use Tygh\Registry;

$page = 0;
$limit = 20;
while (true) {
$subscribers = db_get_array(“SELECT * FROM ?:subscribers ORDER BY subscriber_id LIMIT ?i, ?i”, $page, $limit);
if (empty($subscribers)) {
break;
}
$page += 1;

foreach ($subscribers as $subscriber) {
    $user_id = db_get_field("SELECT user_id FROM ?:users WHERE email = ?s", $subscriber['email']);
    $user_name = fn_get_user_name($user_id);
    $data = array(
        'email' => $subscriber['email'],
        'timestamp' => $subscriber['timestamp'],
        'name' => empty($user_name) ? ' - ' : $user_name,
        'ip_address' => '',
        'lang_code' => db_get_field("SELECT lang_code FROM ?:users WHERE user_id = ?i", $user_id) ?: CART_LANGUAGE,
        'unsubscribe_key' => md5(uniqid()),
        'company_id' => db_get_field("SELECT company_id FROM ?:users WHERE user_id = ?i", $user_id) ?: Registry::get('runtime.company_id'),
    );
    $subscriber_id = db_query("REPLACE INTO ?:em_subscribers ?e", $data);
        }

}

2. Run this script in the storefront, for example: www.your_domain.com/subscribers_to_em.php

Do not forget to make the backup of the em_subscribers database table before running the script.

The information about subscribers will be copied into the specified table called em_subscribers of your database.

If you face any issues, feel free to contact us by e-mail: sales@cart-power.com

Best regards,

Hi Cart-Power,

Thanks for the script. I did exactly as you told and the email seems to be transferred. When i open the database It shows 2095 entries but when i open the admin panel it is showing 346 total ( before it was only 81 ), and when i try to export the subscriber from the drop down the excel file shows correct entry which is 2095. I am confused why it is showing 346?

Difficult to say without detailed examination. Most possibly it is doubled e-mails.

As an option, try to reinstall the Email Marketing add-on or just truncate the cscart_em_subscribers database table.

After that change the created before subscribers_to_em.php script - replace its content with the following code:

require(dirname(FILE) . ‘/init.php’);

fn_load_addon(‘email_marketing’);
use Tygh\Registry;

$page = 0;
$limit = 20;
while (true) {
$subscribers = db_get_array(“SELECT * FROM ?:subscribers ORDER BY subscriber_id LIMIT ?i, ?i”, $page, $limit);
if (empty($subscribers)) {
break;
}
$page += 1;

foreach ($subscribers as $subscriber) {
    $user_id = db_get_field("SELECT user_id FROM ?:users WHERE email = ?s", $subscriber['email']);
    $user_name = fn_get_user_name($user_id);
    $data = array(
        'email' => $subscriber['email'],
        'timestamp' => $subscriber['timestamp'],
        'name' => empty($user_name) ? ' - ' : $user_name,
        'ip_address' => '',
        'lang_code' => db_get_field("SELECT lang_code FROM ?:users WHERE user_id = ?i", $user_id) ?: CART_LANGUAGE,
        'unsubscribe_key' => md5(uniqid()),
        'company_id' => db_get_field("SELECT company_id FROM ?:users WHERE user_id = ?i", $user_id) ?: Registry::get('runtime.company_id'),
    );
    $em_subscriber_id = db_get_field("SELECT subscriber_id FROM ?:em_subscriber WHERE email = ?s", $subscriber['email']);
    if (!empty($em_subscriber_id)) {
        $data['subscriber_id'] = $em_subscriber_id;
    }
    $subscriber_id = db_query("REPLACE INTO ?:em_subscribers ?e", $data);
    fn_em_update_subscriber($data, $subscriber_id);
}

}

And run the script again. It should fix the issue.

The previous data will be deleted, new ones will be added. All doubles will be ignored.

Best regards,

Hi,

I did same as you told me but i am unable to run this new script. It is giving HTTP ERROR 500

Hi,

I did same as you told me but i am unable to run this new script. It is giving HTTP ERROR 500

Try to disable the Newsletters module and enable the E-mail marketing one before running the script

Hi,

Already the E-mail marketing addon is enable and the previous script which was provided it running but the new script is not running.

Try to comment this line:

fn_em_update_subscriber($data, $subscriber_id);

I removed the line still same error.

Try to comment this line:

fn_em_update_subscriber($data, $subscriber_id);

I removed the line still same error.

Please, send us the FTP access credentials to your server, so that we could check it in more details. Our e-mail is sales@cart-power.com

I sent you ftp details to your email.

Thanks for your help.

Please, send us the FTP access credentials to your server, so that we could check it in more details. Our e-mail is sales@cart-power.com