Originally Posted by
millsii
I was having the same issue in getting the "1062 Duplicate entry" error when a newsletter subscriber then tried to create an account. This has resolved the issue for me. It does shorten the section of code a fair amount, so hopefully no side effects.
Should this fix by @kamelion0927 be updated in the plugin release?
I've been using this mod for some time, but during one of my upgrades the create account side wasn't working to catch existing subscriptions. I tried adding your code and no luck on that ether. Going back to what I needed it to do, I came up with this change.
Code:
// BEGIN newsletter_subscribe mod 1/1
// If a newsletter only account exists we update the info,
// If not and the new user selected subscribe we add them to the list
if(defined('NEWSONLY_SUBSCRIPTION_ENABLED') && (NEWSONLY_SUBSCRIPTION_ENABLED=='true')) {
$check_subscribers_sql = "select email_address from " . TABLE_SUBSCRIBERS . " where email_address = :email:";
$check_subscribers_query = $db->bindVars($check_subscribers_sql, ':email:', $email_address, 'string');
$check_subscribers = $db->Execute($check_subscribers_query);
if ($check_subscribers->fields['email_address'] != '') {
// update Subscriber with new customer ID
$sql = "UPDATE " . TABLE_SUBSCRIBERS . "
SET customers_id = :customer_id:
WHERE email_address = :email_address:";
$sql = $db->bindVars($sql, ':customer_id:', (int)$_SESSION['customer_id'], 'integer');
$sql = $db->bindVars($sql, ':email_address:', $email_address, 'string');
$db->Execute($sql);
// update the new customer with an active subscription
$news_query = "UPDATE " . TABLE_CUSTOMERS . "
SET customers_newsletter = 1
WHERE customers_id = :customer_id:";
$news_query = $db->bindVars($news_query, ':customer_id:', (int)$_SESSION['customer_id'], 'integer');
$db->Execute($news_query);
} else {
if ($newsletter == 1) {
// new customer subscription we need to add them to our subscription database too
$sql = "INSERT INTO " . TABLE_SUBSCRIBERS . " (customers_id, email_address, email_format, confirmed, subscribed_date)
VALUES ('" . (int)$_SESSION['customer_id'] . "', '" . zen_db_input($email_address) . "', '" . zen_db_input($email_format) . "', '1', now())";
$db->Execute($sql);
}
}
}
/* END newsletter_subscribe mod 1/1 */
I removed count for matching email address, should only be one and I'm not in a loop. Removed the empty test, it's never empty and I need to know if its a 1. Tested in ZC 1.5.5f and working.
Bookmarks