0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Updated price/products data for portal settings

refs https://github.com/TryGhost/Team/issues/718

The ids for default prices for a product is now stored directly on product model instead of on global settings. This change updates
- the products data sent to Portal to use list of products with their active monthly/yearly prices, as well as
- the prices data sent to Portal to use the prices of default(first) product
This commit is contained in:
Rishabh 2021-06-04 13:03:33 +05:30
parent ea9a83d444
commit 4e01fe9d09

View file

@ -77,29 +77,27 @@ const updateMemberData = async function (req, res) {
}
};
const getDefaultProductPrices = async function () {
const getPortalProductPrices = async function () {
const page = await membersService.api.productRepository.list({
limit: 1
});
const [product] = page.data;
if (product) {
const model = await membersService.api.productRepository.get({id: product.get('id')}, {withRelated: ['stripePrices']});
const productData = model.toJSON();
const prices = productData.stripePrices || [];
const activePrices = prices.filter((d) => {
return !!d.active;
});
const monthlyPriceId = settingsCache.get('members_monthly_price_id');
const yearlyPriceId = settingsCache.get('members_yearly_price_id');
const filteredPrices = activePrices.filter((d) => {
return [monthlyPriceId, yearlyPriceId].includes(d.id);
withRelated: ['monthlyPrice', 'yearlyPrice']
});
const products = page.data.map((productModel) => {
const product = productModel.toJSON();
return {
product: productData,
prices: filteredPrices
id: product.id,
name: product.name,
description: product.description || '',
prices: [product.monthlyPrice, product.yearlyPrice]
};
});
const defaultPrices = products[0] ? products[0].prices : [];
return {
prices: defaultPrices,
products: products
};
}
return {};
};
const getMemberSiteData = async function (req, res) {
@ -111,7 +109,7 @@ const getMemberSiteData = async function (req, res) {
if (!supportAddress.includes('@')) {
supportAddress = `${supportAddress}@${blogDomain}`;
}
const {product = {}, prices = []} = await getDefaultProductPrices() || {};
const {products = [], prices = []} = await getPortalProductPrices() || {};
const response = {
title: settingsCache.get('title'),
description: settingsCache.get('description'),
@ -122,10 +120,7 @@ const getMemberSiteData = async function (req, res) {
version: ghostVersion.safe,
plans: membersService.config.getPublicPlans(),
prices,
product: {
name: product.name || '',
description: product.description || ''
},
products,
free_price_name: settingsCache.get('members_free_price_name'),
free_price_description: settingsCache.get('members_free_price_description'),
allow_self_signup: membersService.config.getAllowSelfSignup(),