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:
parent
ea9a83d444
commit
4e01fe9d09
1 changed files with 19 additions and 24 deletions
|
@ -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({
|
const page = await membersService.api.productRepository.list({
|
||||||
limit: 1
|
withRelated: ['monthlyPrice', 'yearlyPrice']
|
||||||
});
|
});
|
||||||
const [product] = page.data;
|
|
||||||
if (product) {
|
const products = page.data.map((productModel) => {
|
||||||
const model = await membersService.api.productRepository.get({id: product.get('id')}, {withRelated: ['stripePrices']});
|
const product = productModel.toJSON();
|
||||||
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);
|
|
||||||
});
|
|
||||||
return {
|
return {
|
||||||
product: productData,
|
id: product.id,
|
||||||
prices: filteredPrices
|
name: product.name,
|
||||||
|
description: product.description || '',
|
||||||
|
prices: [product.monthlyPrice, product.yearlyPrice]
|
||||||
};
|
};
|
||||||
}
|
});
|
||||||
return {};
|
|
||||||
|
const defaultPrices = products[0] ? products[0].prices : [];
|
||||||
|
return {
|
||||||
|
prices: defaultPrices,
|
||||||
|
products: products
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const getMemberSiteData = async function (req, res) {
|
const getMemberSiteData = async function (req, res) {
|
||||||
|
@ -111,7 +109,7 @@ const getMemberSiteData = async function (req, res) {
|
||||||
if (!supportAddress.includes('@')) {
|
if (!supportAddress.includes('@')) {
|
||||||
supportAddress = `${supportAddress}@${blogDomain}`;
|
supportAddress = `${supportAddress}@${blogDomain}`;
|
||||||
}
|
}
|
||||||
const {product = {}, prices = []} = await getDefaultProductPrices() || {};
|
const {products = [], prices = []} = await getPortalProductPrices() || {};
|
||||||
const response = {
|
const response = {
|
||||||
title: settingsCache.get('title'),
|
title: settingsCache.get('title'),
|
||||||
description: settingsCache.get('description'),
|
description: settingsCache.get('description'),
|
||||||
|
@ -122,10 +120,7 @@ const getMemberSiteData = async function (req, res) {
|
||||||
version: ghostVersion.safe,
|
version: ghostVersion.safe,
|
||||||
plans: membersService.config.getPublicPlans(),
|
plans: membersService.config.getPublicPlans(),
|
||||||
prices,
|
prices,
|
||||||
product: {
|
products,
|
||||||
name: product.name || '',
|
|
||||||
description: product.description || ''
|
|
||||||
},
|
|
||||||
free_price_name: settingsCache.get('members_free_price_name'),
|
free_price_name: settingsCache.get('members_free_price_name'),
|
||||||
free_price_description: settingsCache.get('members_free_price_description'),
|
free_price_description: settingsCache.get('members_free_price_description'),
|
||||||
allow_self_signup: membersService.config.getAllowSelfSignup(),
|
allow_self_signup: membersService.config.getAllowSelfSignup(),
|
||||||
|
|
Loading…
Reference in a new issue