mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-04 17:04:59 +03:00
Updated portal plans on monthly/yearly price change
no refs Portal plans setting contains list of prices that are allowed by site owner to use in Portal UI. Since we now switch monthly/yearly prices dynamically, we need to update portal plans on price change to still reflect updated monthly/yearly prices in Portal UI.
This commit is contained in:
parent
eecd6d03b6
commit
f9672e7095
@ -233,6 +233,7 @@ export default class MembersAccessController extends Controller {
|
||||
);
|
||||
}
|
||||
if (monthlyPrice && yearlyPrice) {
|
||||
this.updatePortalPlans(monthlyPrice.id, yearlyPrice.id);
|
||||
this.settings.set('membersMonthlyPriceId', monthlyPrice.id);
|
||||
this.settings.set('membersYearlyPriceId', yearlyPrice.id);
|
||||
return this.product;
|
||||
@ -242,6 +243,7 @@ export default class MembersAccessController extends Controller {
|
||||
const updatedStripePrices = savedProduct.stripePrices || [];
|
||||
const updatedMonthlyPrice = getActivePrice(updatedStripePrices, 'month', monthlyAmount);
|
||||
const updatedYearlyPrice = getActivePrice(updatedStripePrices, 'year', yearlyAmount);
|
||||
this.updatePortalPlans(updatedMonthlyPrice.id, updatedYearlyPrice.id);
|
||||
this.settings.set('membersMonthlyPriceId', updatedMonthlyPrice.id);
|
||||
this.settings.set('membersYearlyPriceId', updatedYearlyPrice.id);
|
||||
return savedProduct;
|
||||
@ -249,6 +251,22 @@ export default class MembersAccessController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
updatePortalPlans(monthlyPriceId, yearlyPriceId) {
|
||||
let portalPlans = this.settings.get('portalPlans') || [];
|
||||
const currentMontlyPriceId = this.settings.get('membersMonthlyPriceId');
|
||||
const currentYearlyPriceId = this.settings.get('membersYearlyPriceId');
|
||||
if (portalPlans.includes(currentMontlyPriceId)) {
|
||||
portalPlans = portalPlans.filter(d => d.id !== currentMontlyPriceId);
|
||||
portalPlans.push(monthlyPriceId);
|
||||
}
|
||||
|
||||
if (portalPlans.includes(currentYearlyPriceId)) {
|
||||
portalPlans = portalPlans.filter(d => d.id !== currentYearlyPriceId);
|
||||
portalPlans.push(yearlyPriceId);
|
||||
}
|
||||
this.settings.set('portalPlans', portalPlans);
|
||||
}
|
||||
|
||||
getPrice(prices, type) {
|
||||
const monthlyPriceId = this.settings.get('membersMonthlyPriceId');
|
||||
const yearlyPriceId = this.settings.get('membersYearlyPriceId');
|
||||
|
@ -167,7 +167,7 @@
|
||||
@placeholder=''
|
||||
data-test-title-input={{true}}
|
||||
/>
|
||||
<span class="gh-input-append"><span class="ttu">{{this.currency}}</span>/month</span>
|
||||
<span class="gh-input-append"><span class="ttu">{{this.currency}}</span>/year</span>
|
||||
</div>
|
||||
</div>
|
||||
{{#if this.stripePlanError}}
|
||||
|
Loading…
Reference in New Issue
Block a user