Customizing Tax
Broadleaf Commerce can be configured for tax calculation in a number of ways. You can use the simple tax calculator, one of our included third party tax modules (such as CyberSource), or by using a creating a custom tax module.
In this tutorial we will configure the Simple Tax Module for our example company, 'Acme Co' for tax calculation.
Prerequisites
- Broadleaf's Tax Strategy
- [[Broadleaf's Simple Tax Module | Simple Tax Module ]]
Acme Co Tax Requirements
Acme Co has three physical retail locations in the United States: Los Angeles, California, Austin, Texas, and New York City, New York. Each state has its own sales tax rate.
The table below details the locations and their sales tax rate:
Location | Sales Tax Rate |
---|---|
Los Angeles, CA | 8.75% |
Austin, TX | 8.25% |
New York City, NY | 8.875% |
Configuring the Simple Tax Module
To customize the simple tax module, simply declare and merge additional tax providers into the blTaxProviders
bean within your applicationContext xml. This overrides Broadleaf's out-of-the-box configuration for tax calculation.
Specifying a rate by state will suffice for our needs. Therefore, the property we need to customize in this bean is the itemStateTaxRateMap
. For additional properties and their descriptions, see more in the [[Simple Tax Module]] docs.
Here is the complete XML configuration snippet:
<bean id="stateTaxProvider" class="org.broadleafcommerce.core.pricing.service.tax.provider.SimpleTaxProvider">
<property name="itemStateTaxRateMap">
<map>
<entry key="CA" value=".0875" />
<entry key="TX" value=".0825" />
<entry key="NY" value=".08875" />
</map>
</property>
</bean>
<bean id="customTaxProviders" class="org.springframework.beans.factory.config.ListFactoryBean">
<property name="sourceList">
<list>
<ref bean="stateTaxProvider" />
</list>
</property>
</bean>
<bean class="org.broadleafcommerce.common.extensibility.context.merge.LateStageMergeBeanPostProcessor">
<property name="collectionRef" value="customTaxProviders"/>
<property name="targetRef" value="blTaxProviders"/>
</bean>
Here is the complete Java configuration snippet:
@Merge("blTaxProviders")
public List<TaxProvider> customTaxProviders() {
Map<String, Double> itemStateTaxRateMap = new HashMap<>();
itemStateTaxRateMap.put("CA", .0875);
itemStateTaxRateMap.put("TX", .0825);
itemStateTaxRateMap.put("NY", .08875);
SimpleTaxProvider simpleTaxProvider = new SimpleTaxProvider();
simpleTaxProvider.setItemStateTaxRateMap(itemStateTaxRateMap);
return Collections.singletonList(simpleTaxProvider);
}
The changes should take effect on the next server startup. That's it!