diff --git a/ghost/admin/app/controllers/settings/membership.js b/ghost/admin/app/controllers/settings/membership.js index 71f92ed5eb..f2ec8f2437 100644 --- a/ghost/admin/app/controllers/settings/membership.js +++ b/ghost/admin/app/controllers/settings/membership.js @@ -233,6 +233,7 @@ export default class MembersAccessController extends Controller { ); } if (monthlyPrice && yearlyPrice) { + this.updatePortalPlans(monthlyPrice.id, yearlyPrice.id); this.settings.set('membersMonthlyPriceId', monthlyPrice.id); this.settings.set('membersYearlyPriceId', yearlyPrice.id); return this.product; @@ -242,6 +243,7 @@ export default class MembersAccessController extends Controller { const updatedStripePrices = savedProduct.stripePrices || []; const updatedMonthlyPrice = getActivePrice(updatedStripePrices, 'month', monthlyAmount); const updatedYearlyPrice = getActivePrice(updatedStripePrices, 'year', yearlyAmount); + this.updatePortalPlans(updatedMonthlyPrice.id, updatedYearlyPrice.id); this.settings.set('membersMonthlyPriceId', updatedMonthlyPrice.id); this.settings.set('membersYearlyPriceId', updatedYearlyPrice.id); return savedProduct; @@ -249,6 +251,22 @@ export default class MembersAccessController extends Controller { } } + updatePortalPlans(monthlyPriceId, yearlyPriceId) { + let portalPlans = this.settings.get('portalPlans') || []; + const currentMontlyPriceId = this.settings.get('membersMonthlyPriceId'); + const currentYearlyPriceId = this.settings.get('membersYearlyPriceId'); + if (portalPlans.includes(currentMontlyPriceId)) { + portalPlans = portalPlans.filter(d => d.id !== currentMontlyPriceId); + portalPlans.push(monthlyPriceId); + } + + if (portalPlans.includes(currentYearlyPriceId)) { + portalPlans = portalPlans.filter(d => d.id !== currentYearlyPriceId); + portalPlans.push(yearlyPriceId); + } + this.settings.set('portalPlans', portalPlans); + } + getPrice(prices, type) { const monthlyPriceId = this.settings.get('membersMonthlyPriceId'); const yearlyPriceId = this.settings.get('membersYearlyPriceId'); diff --git a/ghost/admin/app/templates/settings/membership.hbs b/ghost/admin/app/templates/settings/membership.hbs index 19912a20b0..104b55e618 100644 --- a/ghost/admin/app/templates/settings/membership.hbs +++ b/ghost/admin/app/templates/settings/membership.hbs @@ -167,7 +167,7 @@ @placeholder='' data-test-title-input={{true}} /> - {{this.currency}}/month + {{this.currency}}/year {{#if this.stripePlanError}}