mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Cleaned add subscription prices for member details
closes https://github.com/TryGhost/Team/issues/678 closes https://github.com/TryGhost/Team/issues/681 The prices in "Add subscription" modal should follow the same ordering as on the product detail screen, ie. currency, amount. Also, we only want to allow adding subscriptions for active prices, so the list is filtered on that. Since a Stripe customer is not allowed to have subscriptions in multiple currencies, this also filters the available currency prices based on any active subscription for a member.
This commit is contained in:
parent
d3efc29f08
commit
c449e32121
1 changed files with 22 additions and 3 deletions
|
@ -32,6 +32,7 @@ export default class ModalMemberProduct extends ModalComponent {
|
||||||
async fetchProducts() {
|
async fetchProducts() {
|
||||||
this.products = await this.store.query('product', {include: 'stripe_prices'});
|
this.products = await this.store.query('product', {include: 'stripe_prices'});
|
||||||
this.product = this.products.firstObject;
|
this.product = this.products.firstObject;
|
||||||
|
this.price = this.prices ? this.prices[0] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
get member() {
|
get member() {
|
||||||
|
@ -47,9 +48,27 @@ export default class ModalMemberProduct extends ModalComponent {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
if (this.product) {
|
if (this.product) {
|
||||||
return this.products.find((product) => {
|
let subscriptions = this.member.get('subscriptions') || [];
|
||||||
return product.id === this.product.id;
|
let activeCurrency;
|
||||||
}).stripePrices.map((price) => {
|
if (subscriptions.length > 0) {
|
||||||
|
activeCurrency = subscriptions[0].price?.currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
const product = this.products.find((_product) => {
|
||||||
|
return _product.id === this.product.id;
|
||||||
|
});
|
||||||
|
return product.stripePrices.sort((a, b) => {
|
||||||
|
return a.amount - b.amount;
|
||||||
|
}).filter((price) => {
|
||||||
|
return price.active;
|
||||||
|
}).filter((price) => {
|
||||||
|
if (activeCurrency) {
|
||||||
|
return price.currency?.toLowerCase() === activeCurrency.toLowerCase();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}).sort((a, b) => {
|
||||||
|
return a.currency.localeCompare(b.currency, undefined, {ignorePunctuation: true});
|
||||||
|
}).map((price) => {
|
||||||
return {
|
return {
|
||||||
...price,
|
...price,
|
||||||
label: `${price.nickname} (${getSymbol(price.currency)}${getNonDecimal(price.amount)}/${price.interval})`
|
label: `${price.nickname} (${getSymbol(price.currency)}${getNonDecimal(price.amount)}/${price.interval})`
|
||||||
|
|
Loading…
Add table
Reference in a new issue