Skip to content

Commit

Permalink
Merge pull request #533 from ouranos/feature/113-fix-local-product-cu…
Browse files Browse the repository at this point in the history
…rrency-selection

[OPALSUP-113] Fix currency selection for local product
  • Loading branch information
ouranos authored Aug 10, 2018
2 parents 2152bca + cefd4e9 commit 2798e33
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/app/components/mno-local-products/mno-local-product.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ angular.module 'mnoEnterpriseAngular'

vm.pricedPlan = ProvisioningHelper.pricedPlan

vm.planAvailableForCurrency = (plan) ->
_.includes(_.map(plan.prices, 'currency'), vm.orgCurrency)

vm.hideNoPricingFound = (plan) ->
vm.isPublic || vm.planAvailableForCurrency(plan) || !vm.pricedPlan(plan)

Expand All @@ -46,18 +49,23 @@ angular.module 'mnoEnterpriseAngular'
else
vm.orgCurrency = MnoeConfig.marketplaceCurrency()

vm.planAvailableForCurrency = (plan) ->
_.includes(_.map(plan.prices, 'currency'), vm.orgCurrency)
# App to be displayed
productId = $stateParams.productId
vm.product = _.findWhere(vm.products, { nid: productId })
vm.product ||= _.findWhere(vm.products, { id: productId })

# Plans
plans = vm.product.pricing_plans
# Is currency selection enabled
currencySelection = MnoeConfig.isCurrencySelectionEnabled()
# Are there any available plans
availablePlans = ProvisioningHelper.plansForCurrency(vm.product.pricing_plans, vm.orgCurrency)
availablePlans = ProvisioningHelper.plansForCurrency(plans, vm.orgCurrency)

# We can order if there's an availablePlan for the currency
# Or if the currency selection is enabled and we have a priced plan
vm.orderPossible = !_.isEmpty(availablePlans) ||
(currencySelection && _.some(plans, (plan) -> ProvisioningHelper.pricedPlan(plan) && plan.prices?))

vm.orderPossible = !_.isEmpty(availablePlans) || (vm.product.pricing_plans?[0].default?[0] && currencySelection)
vm.buttonDisabledTooltip = vm.updateButtonDisabledTooltip()

$state.go(vm.parentState) unless vm.product?
Expand Down

0 comments on commit 2798e33

Please sign in to comment.