From 55843f2a24ad6c9b494f76450d688366ebc1b34b Mon Sep 17 00:00:00 2001 From: R Date: Wed, 15 Sep 2021 09:58:15 +0200 Subject: [PATCH] OXAP-348 Link newsletter subscription from old account to new account --- CHANGELOG.md | 1 + .../bestitamazonpay4oxidloginclient.php | 41 +++++++++++++++++++ ext/bestitamazonpay4oxid_oxcmp_user.php | 6 +++ 3 files changed, 48 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c44ed3..55a787f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec2.0.0.h ## [3.6.9] - 2021-09-14 ### Changed - Amazon login activated permanently, removed from module settings +- Link existing newsletter subscription to new created accounts, when guest/newsletter accounts get deleted ## [3.6.8] - 2020-02-09 ### Fixed diff --git a/application/models/bestitamazonpay4oxidloginclient.php b/application/models/bestitamazonpay4oxidloginclient.php index 228bd4c..21c1743 100755 --- a/application/models/bestitamazonpay4oxidloginclient.php +++ b/application/models/bestitamazonpay4oxidloginclient.php @@ -175,6 +175,47 @@ public function oxidUserExists($oUserData) return $this->getDatabase()->getRow($sSql); } + /** + * Check if user with Email from Amazon exists + * + * @param string $sId The id of the user + * + * @return boolean + * @throws oxConnectionException + */ + public function oxidNewsletterSubscriptionExists($sId) + { + $sSql = "SELECT OXUSERID + FROM oxnewssubscribed + WHERE OXUSERID = {$this->getDatabase()->quote($sId)}"; + + return $this->getDatabase()->getOne($sSql); + } + + /** + * Delete OXID user by ID + * + * @param string $sOldId The id of the old user + * @param string $sNewId The id of the new user + * + * @return object + * @throws oxConnectionException + */ + public function linkNewsletterToNewUser($sOldId, $sNewId) + { + $this->getLogger()->debug( + 'Link newsletter subscription from old oxuser to new oxuser', + array('oldOxId' => $sOldId, + 'newOxId' => $sNewId) + ); + + $sSql = "UPDATE oxnewssubscribed + SET OXUSERID = {$this->getDatabase()->quote($sNewId)} + WHERE OXUSERID = {$this->getDatabase()->quote($sOldId)}"; + + return $this->getDatabase()->execute($sSql); + } + /** * Create new oxid user with details from Amazon * diff --git a/ext/bestitamazonpay4oxid_oxcmp_user.php b/ext/bestitamazonpay4oxid_oxcmp_user.php index e5a8e4d..1d8ae1d 100755 --- a/ext/bestitamazonpay4oxid_oxcmp_user.php +++ b/ext/bestitamazonpay4oxid_oxcmp_user.php @@ -184,6 +184,12 @@ public function amazonLogin() array('oxId' => $sUserId) ); + // Check if a newsletter subscription existed on the old account + $aNewsletterId = $oLoginClient->oxidNewsletterSubscriptionExists($aUserData['OXID']); + if ($aNewsletterId) { + $oLoginClient->linkNewsletterToNewUser($aUserData['OXID'], $sUserId); + } + $oSession->setVariable('usr', $sUserId); $oUtils->redirect($sRedirectUrl, false); return;