From 3d9e4b4c6cd3b024cfe422354720dd523efbf433 Mon Sep 17 00:00:00 2001 From: "Fabien \"egg\" O'Carroll" Date: Sun, 30 Jan 2022 17:05:09 +0200 Subject: [PATCH] Synced Tiers welcome_page_urls with Settings refs https://github.com/TryGhost/Team/issues/1168 Because Tiers is still behind a flag - any users which are not using Tiers will still be editing their settings, and when they switch to Tiers - the redirects will not necessarily be correct, unless we keep the Tier columns up to date with any settings changes. --- core/server/services/members/service.js | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/core/server/services/members/service.js b/core/server/services/members/service.js index 0e7cbe6c73..699e21785d 100644 --- a/core/server/services/members/service.js +++ b/core/server/services/members/service.js @@ -16,6 +16,7 @@ const models = require('../../models'); const {GhostMailer} = require('../mail'); const jobsService = require('../jobs'); const VerificationTrigger = require('@tryghost/verification-trigger'); +const events = require('../../lib/common/events'); const messages = { noLiveKeysInDevelopment: 'Cannot use live stripe keys in development. Please restart in production mode.', @@ -76,6 +77,32 @@ module.exports = { const createMembersApiInstance = require('./api'); const env = config.get('env'); + events.on('settings.edited', async function (settingModel) { + if (labsService.isSet('multipleProducts')) { + return; + } + + const key = settingModel.get('key'); + const value = settingModel.get('value'); + + if (key === 'members_free_signup_redirect') { + try { + await models.Product.forge().query().update('welcome_page_url', value).where('type', 'free'); + } catch (err) { + logging.error(err); + } + return; + } + if (key === 'members_paid_signup_redirect') { + try { + await models.Product.forge().query().update('welcome_page_url', value).where('type', 'paid'); + } catch (err) { + logging.error(err); + } + return; + } + }); + // @TODO Move to stripe service if (env !== 'production') { if (stripeService.api.configured && stripeService.api.mode === 'live') {