Skip to content

Commit

Permalink
fix: use $0.00 for price if price is not defined, log info (#198)
Browse files Browse the repository at this point in the history
Originally submitted by Kyle (KthProg): #14
  • Loading branch information
andreshernandez-e2x committed Jun 14, 2024
1 parent 5d7199a commit 008752c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion plugin/src/utils/get-typed-money-as-number.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { TypedMoney } from '@commercetools/platform-sdk';
import logger from './log';

export const getTypedMoneyAsNumber = (money?: TypedMoney): number => {
if (!money) {
logger.info('No price found for product.');
return 0;
}

export const getTypedMoneyAsNumber = (money: TypedMoney): number => {
return money.centAmount / Math.pow(10, money.fractionDigits);
};
10 changes: 10 additions & 0 deletions plugin/src/utils/locale-currency-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,14 @@ describe('getProductPriceByPriority', () => {
currency: 'EUR',
});
});

it('should return a single price with an amount of 0 (zero) when prices are not defined', async () => {
const price = getProductPriceByPriority([]);

expect(price).toEqual({
amount: 0,
country: undefined,
currency: undefined,
});
});
});

0 comments on commit 008752c

Please sign in to comment.