Search in sources :

Example 1 with TaxProvider

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.");
}
Also used : ModuleConfiguration(org.broadleafcommerce.common.config.domain.ModuleConfiguration) TaxException(org.broadleafcommerce.core.pricing.service.exception.TaxException) TaxProvider(org.broadleafcommerce.core.pricing.service.tax.provider.TaxProvider)

Aggregations

ModuleConfiguration (org.broadleafcommerce.common.config.domain.ModuleConfiguration)1 TaxException (org.broadleafcommerce.core.pricing.service.exception.TaxException)1 TaxProvider (org.broadleafcommerce.core.pricing.service.tax.provider.TaxProvider)1