mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
🐛 Fixed incorrect price shown for offer page with fixed discount
no refs the fixed discount is only applied to offer if the offer currency matches with original price currency. The bug happened due to case difference between the offer and price currencies which should be compared case insensitive
This commit is contained in:
parent
3ad4e9c4c9
commit
f4fdda94e5
3 changed files with 24 additions and 3 deletions
|
@ -3,7 +3,7 @@ import AppContext from '../../AppContext';
|
||||||
import {ReactComponent as CheckmarkIcon} from '../../images/icons/checkmark.svg';
|
import {ReactComponent as CheckmarkIcon} from '../../images/icons/checkmark.svg';
|
||||||
import CloseButton from '../common/CloseButton';
|
import CloseButton from '../common/CloseButton';
|
||||||
import InputForm from '../common/InputForm';
|
import InputForm from '../common/InputForm';
|
||||||
import {getCurrencySymbol, getProductFromId, hasMultipleProductsFeature} from '../../utils/helpers';
|
import {getCurrencySymbol, getProductFromId, hasMultipleProductsFeature, isSameCurrency} from '../../utils/helpers';
|
||||||
import {ValidateInputForm} from '../../utils/form';
|
import {ValidateInputForm} from '../../utils/form';
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
|
|
||||||
|
@ -445,7 +445,7 @@ export default class OfferPage extends React.Component {
|
||||||
const price = offer.cadence === 'month' ? product.monthlyPrice : product.yearlyPrice;
|
const price = offer.cadence === 'month' ? product.monthlyPrice : product.yearlyPrice;
|
||||||
const originalAmount = price.amount;
|
const originalAmount = price.amount;
|
||||||
let updatedAmount;
|
let updatedAmount;
|
||||||
if (offer.type === 'fixed' && offer.currency === price.currency) {
|
if (offer.type === 'fixed' && isSameCurrency(offer.currency, price.currency)) {
|
||||||
updatedAmount = ((originalAmount - offer.amount)) / 100;
|
updatedAmount = ((originalAmount - offer.amount)) / 100;
|
||||||
return updatedAmount > 0 ? updatedAmount : 0;
|
return updatedAmount > 0 ? updatedAmount : 0;
|
||||||
} else if (offer.type === 'percent') {
|
} else if (offer.type === 'percent') {
|
||||||
|
|
|
@ -484,6 +484,10 @@ export const createPopupNotification = ({type, status, autoHide, duration, close
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function isSameCurrency(currency1, currency2) {
|
||||||
|
return currency1?.toLowerCase() === currency2?.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
export function getPriceIdFromPageQuery({site, pageQuery}) {
|
export function getPriceIdFromPageQuery({site, pageQuery}) {
|
||||||
const productMonthlyPriceQueryRegex = /^(?:(\S+?))?\/monthly$/;
|
const productMonthlyPriceQueryRegex = /^(?:(\S+?))?\/monthly$/;
|
||||||
const productYearlyPriceQueryRegex = /^(?:(\S+?))?\/yearly$/;
|
const productYearlyPriceQueryRegex = /^(?:(\S+?))?\/yearly$/;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {getPriceIdFromPageQuery} from './helpers';
|
import {getPriceIdFromPageQuery, isSameCurrency} from './helpers';
|
||||||
import * as Fixtures from './fixtures';
|
import * as Fixtures from './fixtures';
|
||||||
|
|
||||||
describe('Helpers - ', () => {
|
describe('Helpers - ', () => {
|
||||||
|
@ -11,4 +11,21 @@ describe('Helpers - ', () => {
|
||||||
const value = mockPriceIdFn({site: siteData, pageQuery});
|
const value = mockPriceIdFn({site: siteData, pageQuery});
|
||||||
expect(value).toBe(expectedPriceId);
|
expect(value).toBe(expectedPriceId);
|
||||||
});
|
});
|
||||||
|
describe('isSameCurrency - ', () => {
|
||||||
|
test('can match two currencies correctly ', () => {
|
||||||
|
let currency1 = 'USD';
|
||||||
|
let currency2 = 'USD';
|
||||||
|
expect(isSameCurrency(currency1, currency2)).toBe(true);
|
||||||
|
});
|
||||||
|
test('can match currencies with case mismatch', () => {
|
||||||
|
let currency1 = 'USD';
|
||||||
|
let currency2 = 'usd';
|
||||||
|
expect(isSameCurrency(currency1, currency2)).toBe(true);
|
||||||
|
});
|
||||||
|
test('can match currencies with case mismatch', () => {
|
||||||
|
let currency1 = 'eur';
|
||||||
|
let currency2 = 'usd';
|
||||||
|
expect(isSameCurrency(currency1, currency2)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue