0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00

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
This commit is contained in:
Rishabh 2021-05-07 22:33:28 +05:30 committed by Rishabh Garg
parent 815e00c761
commit b73fdf66d1

View file

@ -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;
}