use of org.broadleafcommerce.core.pricing.service.tax.provider.TaxProvider in project BroadleafCommerce by BroadleafCommerce.
the class TaxServiceImpl method calculateTaxForOrder.
@Override
public Order calculateTaxForOrder(Order order) throws TaxException {
List<ModuleConfiguration> configurations = moduleConfigService.findActiveConfigurationsByType(ModuleConfigurationType.TAX_CALCULATION);
// Try to find a default configuration
ModuleConfiguration config = null;
if (configurations != null) {
for (ModuleConfiguration configuration : configurations) {
if (configuration.getIsDefault()) {
config = configuration;
break;
}
}
if (config == null && CollectionUtils.isNotEmpty(configurations)) {
// if there wasn't a default one, use the first active one...
config = configurations.get(0);
}
}
if (CollectionUtils.isNotEmpty(providers)) {
for (TaxProvider provider : providers) {
if (provider.canRespond(config)) {
return provider.calculateTaxForOrder(order, config);
}
}
}
// haven't returned anything, nothing must have run
if (!mustCalculate) {
return order;
}
throw new TaxException("No eligible tax providers were configured.");
}
Aggregations