From 0062c9f351fbdee3837f2aa64a56bcab7fb7cb86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Est=C3=A1cio=20Pereira?= Date: Wed, 30 May 2018 12:50:25 -0300 Subject: [PATCH] Fix ProductPrice Component when no installments are passed. --- CHANGELOG.md | 2 + react/components/ProductPrice/index.js | 127 ++++++++++++++----------- 2 files changed, 71 insertions(+), 58 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de70b3658..e5801f678 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Fix _ProductPrice_ Component when no Installments are passed. ## [1.3.0] - 2018-05-29 ### Added diff --git a/react/components/ProductPrice/index.js b/react/components/ProductPrice/index.js index 09955c2c5..85a852dd7 100644 --- a/react/components/ProductPrice/index.js +++ b/react/components/ProductPrice/index.js @@ -21,17 +21,24 @@ class Price extends Component { showInstallments: false, } - render() { + currencyOptions = { + style: 'currency', + currency: this.context.culture.currency, + minimumFractionDigits: 2, + maximumFractionDigits: 2, + } + + getInstallmentsNode() { const { - sellingPrice, - listPrice, installments, - showInstallments, showLabels, - showSavings, intl: { formatNumber }, } = this.props + if (!installments || isEmpty(installments)) { + return null + } + const noInterestRateInstallments = installments.filter( installment => !installment.InterestRate ) @@ -50,19 +57,9 @@ class Price extends Component { : current ) - const differentPrices = - this.props.showListPrice && sellingPrice !== listPrice - - const currencyOptions = { - style: 'currency', - currency: this.context.culture.currency, - minimumFractionDigits: 2, - maximumFractionDigits: 2, - } - const formattedInstallmentPrice = formatNumber( installment.Value, - currencyOptions + this.currencyOptions ) const [installmentsElement, installmentPriceElement, timesElement] = [ @@ -75,6 +72,46 @@ class Price extends Component { )) + return ( +
+
+ {showLabels ? ( + + ) : ( + + {installmentsElement} {timesElement} {installmentPriceElement} + + )} + {!installment.InterestRate && ( + + + + )} +
+
+ ) + } + + render() { + const { + sellingPrice, + listPrice, + showInstallments, + showLabels, + showSavings, + intl: { formatNumber }, + } = this.props + + const differentPrices = + this.props.showListPrice && sellingPrice !== listPrice + return (
{differentPrices && ( @@ -85,7 +122,7 @@ class Price extends Component {
)}
- {formatNumber(listPrice, currencyOptions)} + {formatNumber(listPrice, this.currencyOptions)}
)} @@ -96,52 +133,26 @@ class Price extends Component { )}
- {formatNumber(sellingPrice, currencyOptions)} + {formatNumber(sellingPrice, this.currencyOptions)}
- {showInstallments && - installment && ( -
-
- {showLabels ? ( - - ) : ( - - {installmentsElement} {timesElement}{' '} - {installmentPriceElement} - - )} - {!installment.InterestRate && ( - - - - )} -
-
- )} + {showInstallments && this.getInstallmentsNode()} {differentPrices && showSavings && ( -
-
- -
+
+
+
- )} +
+ )}
) }