Skip to content

Commit

Permalink
fix: default tax rate not exist issue
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlLiu2023 authored and kris-liu-smile committed Jun 27, 2023
1 parent a49bfc7 commit 3faca98
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
5 changes: 2 additions & 3 deletions apps/storefront/src/pages/quote/QuoteDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ function QuoteDetail() {
(taxZone: { id: number }) => taxZone.id === 1
)
if (defaultTaxZone) {
const { rates } = defaultTaxZone
const { enabled } = rates[0]
if (enabled && rates[0].classRates.length) {
const { rates = [] } = defaultTaxZone
if (rates.length && rates[0].enabled && rates[0].classRates.length) {
rates[0].classRates.forEach((rate) => classRates.push(rate))
}
}
Expand Down
5 changes: 3 additions & 2 deletions apps/storefront/src/utils/b3Product/b3TaxRate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ const getTaxRate = (taxClassId: number) => {
if (taxZoneRates.length) {
const withValueTaxZoneRates =
taxZoneRates.filter(
(taxZoneRate: TaxZoneRatesProps) => taxZoneRate.rates.length > 0
(taxZoneRate: TaxZoneRatesProps) =>
taxZoneRate.rates.length > 0 && taxZoneRate.enabled
) || []

if (withValueTaxZoneRates.length > 0) {
const currentTaxZoneRate =
withValueTaxZoneRates.find(
(taxZoneRate: TaxZoneRatesProps) =>
taxZoneRate.rates[0].priority === 1
taxZoneRate.rates[0].priority === 0 && taxZoneRate.rates[0].enabled
) || withValueTaxZoneRates[0]

taxRates = currentTaxZoneRate?.rates[0]?.classRates || []
Expand Down
11 changes: 2 additions & 9 deletions apps/storefront/src/utils/storefrontConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,17 +294,10 @@ const getStoreTaxZoneRates = async () => {
)
if (defaultTaxZone) {
const {
rates,
priceDisplaySettings: { showInclusive },
} = defaultTaxZone
const { enabled } = rates[0]
if (enabled) {
B3SStorage.set('showInclusiveTaxPrice', showInclusive)
store.dispatch(setShowInclusiveTaxPrice(showInclusive))
} else {
B3SStorage.set('showInclusiveTaxPrice', false)
store.dispatch(setShowInclusiveTaxPrice(false))
}
B3SStorage.set('showInclusiveTaxPrice', showInclusive)
store.dispatch(setShowInclusiveTaxPrice(showInclusive))
}
}

Expand Down

0 comments on commit 3faca98

Please sign in to comment.