mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Added price data to templates (#11259)
no-issue This is p. damn hacky!! This exports `{{@price.monthly}}` and `{{@price.yearly}}` to the theme so that we can have dynamic payment pages
This commit is contained in:
parent
1114f85d66
commit
95543b0461
1 changed files with 34 additions and 1 deletions
|
@ -39,6 +39,37 @@ function ensureActiveTheme(req, res, next) {
|
|||
next();
|
||||
}
|
||||
|
||||
/*
|
||||
* @TODO
|
||||
* This should be definitely refactored and we need to consider _some_
|
||||
* members settings as publicly readable
|
||||
*/
|
||||
function haxGetMembersPriceData() {
|
||||
const defaultPriceData = {monthly: 0, yearly: 0};
|
||||
try {
|
||||
const membersSettings = settingsCache.get('members_subscription_settings');
|
||||
const stripeProcessor = membersSettings.paymentProcessors.find(
|
||||
processor => processor.adapter === 'stripe'
|
||||
);
|
||||
|
||||
const priceData = stripeProcessor.config.plans.reduce((prices, plan) => {
|
||||
const numberAmount = 0 + plan.amount;
|
||||
const dollarAmount = numberAmount ? Math.round(numberAmount / 100) : 0;
|
||||
return Object.assign(prices, {
|
||||
[plan.name.toLowerCase()]: dollarAmount
|
||||
});
|
||||
}, {});
|
||||
|
||||
if (Number.isInteger(priceData.monthly) && Number.isInteger(priceData.yearly)) {
|
||||
return priceData;
|
||||
}
|
||||
|
||||
return defaultPriceData;
|
||||
} catch (err) {
|
||||
return defaultPriceData;
|
||||
}
|
||||
}
|
||||
|
||||
function updateGlobalTemplateOptions(req, res, next) {
|
||||
// Static information, same for every request unless the settings change
|
||||
// @TODO: bind this once and then update based on events?
|
||||
|
@ -49,6 +80,7 @@ function updateGlobalTemplateOptions(req, res, next) {
|
|||
posts_per_page: activeTheme.get().config('posts_per_page'),
|
||||
image_sizes: activeTheme.get().config('image_sizes')
|
||||
};
|
||||
const priceData = haxGetMembersPriceData();
|
||||
|
||||
// @TODO: only do this if something changed?
|
||||
// @TODO: remove blog if we drop v2 (Ghost 4.0)
|
||||
|
@ -57,7 +89,8 @@ function updateGlobalTemplateOptions(req, res, next) {
|
|||
blog: siteData,
|
||||
site: siteData,
|
||||
labs: labsData,
|
||||
config: themeData
|
||||
config: themeData,
|
||||
price: priceData
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue