From b73fdf66d1c05da9c409799542a05f3acca44d21 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Fri, 7 May 2021 22:33:28 +0530 Subject: [PATCH] Added interval fallbacks for monthly/yearly plans refs https://github.com/TryGhost/Team/issues/643 Previously, we always expected `Monthly` or `Yearly` prices to be available for attribtues/links as those were the only prices allowed in Portal. With custom prices, as prices can have dynamic names, we still support Monthly/Yearly prices for backwards compatibility. The way Monthly/Yearly prices are determined with custom prices is first trying to find the first price by the name same as `Monthly` / `Yearly`, followed by finding a plan having interval `month`/`year`. This gives us the best possible window to continue supporting Monthly/Yearly till all themes have time to adapt to custom prices --- ghost/portal/src/utils/helpers.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ghost/portal/src/utils/helpers.js b/ghost/portal/src/utils/helpers.js index 09a192d993..dcd5524add 100644 --- a/ghost/portal/src/utils/helpers.js +++ b/ghost/portal/src/utils/helpers.js @@ -111,12 +111,16 @@ export function getQueryPrice({site = {}, priceId}) { const prices = getAvailablePrices({site}); if (priceId === 'free') { return !prices || prices.length === 0 || prices.find(p => p.type === 'free'); - } else if (priceId === 'monthly') { - return prices && prices.length > 0 && prices.find(p => p.name === 'Monthly'); - } else if (priceId === 'yearly') { - return prices && prices.length > 0 && prices.find(p => p.name === 'Yearly'); - } else if (priceId) { - return prices && prices.length > 0 && prices.find(p => p.id === priceId); + } else if (prices && prices.length > 0 && priceId === 'monthly') { + const monthlyByName = prices.find(p => p.name === 'Monthly'); + const monthlyByInterval = prices.find(p => p.interval === 'month'); + return monthlyByName || monthlyByInterval; + } else if (prices && prices.length > 0 && priceId === 'yearly') { + const yearlyByName = prices.find(p => p.name === 'Yearly'); + const yearlyByInterval = prices.find(p => p.interval === 'year'); + return yearlyByName || yearlyByInterval; + } else if (prices && prices.length > 0 && priceId) { + return prices.find(p => p.id === priceId); } return null; }