Hi have done some steps so far:
1. create the extension of BLC_MODULE_CONFIGURATION like this:
Code: Select all
package eu.seacloud.module.tax;
import javax.persistence.Entity;
import javax.persistence.Table;
import org.broadleafcommerce.common.config.domain.AbstractModuleConfiguration;
import org.broadleafcommerce.common.config.domain.ModuleConfiguration;
@Entity
@Table(name="SEA_VAT_CONFIGURATION")
public class VATConfigurationImpl extends AbstractModuleConfiguration implements
ModuleConfiguration {
/**
* European VAT module by TSU
*/
private static final long serialVersionUID = 984294196280227960L;
private String vendorMemberCountry;
private String vendorVATNumber;
private double vendorMemberCountryTaxRate;
public String getVendorMemberCountry() {
return vendorMemberCountry;
}
public String getVendorVATNumber() {
return vendorVATNumber;
}
public double getVendorMemberCountryTaxRate() {
return vendorMemberCountryTaxRate;
}
public void setVendorMemberCountry(String vendorMemberCountry) {
this.vendorMemberCountry = vendorMemberCountry;
}
public void setVendorVATNumber(String vendorVATNumber) {
this.vendorVATNumber = vendorVATNumber;
}
public void setVendorMemberCountryTaxRate(double vendorMemberCountryTaxRate) {
this.vendorMemberCountryTaxRate = vendorMemberCountryTaxRate;
}
}
and i have added this class to persistence.xml and applicationcontext-entity.xml. All of this done in project 'core'
<bean id="blTaxModule" class="eu.seacloud.module.tax.VatTaxProviderImpl" scope="prototype"/>
2. Then i have created a TaxProvider
Code: Select all
package eu.seacloud.module.tax;
import org.broadleafcommerce.common.config.domain.ModuleConfiguration;
import org.broadleafcommerce.core.order.domain.Order;
import org.broadleafcommerce.core.pricing.service.exception.TaxException;
import org.broadleafcommerce.core.pricing.service.tax.provider.TaxProvider;
public class VatTaxProviderImpl implements TaxProvider {
@Override
public boolean canRespond(ModuleConfiguration config) {
if (config instanceof VATConfigurationImpl) {
return true;
}
return false;
}
@Override
public Order calculateTaxForOrder(Order order, ModuleConfiguration config)
throws TaxException {
// TODO Auto-generated method stub
System.out.println("calculating tax for order: "+order.getId());
return order;
}
@Override
public Order commitTaxForOrder(Order order, ModuleConfiguration config)
throws TaxException {
// TODO no need
return order;
}
@Override
public void cancelTax(Order order, ModuleConfiguration config)
throws TaxException {
// TODO Auto-generated method stub
}
}
also in core project
3. I have added the respective records in the DB
Code: Select all
insert into BLC_MODULE_CONFIGURATION values (1, null, '2014-01-01',null,0,null,null,0,'TAX_CALCULATION',1,'VAT',1);
insert info SEA_VAT_CONFIGURATION values ('BE',0.21,'0123456789',1);
4. I changed to project 'site' and added to applicationContext.xml
Code: Select all
<bean id="VATTaxProvider" class="eu.seacloud.module.tax.VatTaxProviderImpl"/>
<bean id="blTaxProviders" class="java.util.ArrayList" >
<constructor-arg>
<list >
<ref bean="VATTaxProvider" />
</list>
</constructor-arg>
</bean>
When adding a product to the cart, i can see in debug that my module configuration is loaded from the DB and that TaxServiceImpl is looking for a list of TaxProviders (bean with id "blTaxProviders") which I tried to define in applicationcontext.xml but my definition is not working as the list is not typed. Spring does not accept the constructor-arg but i do not know how to create a typed list List<TaxProvider> with a reference to my bean.
Can anyone help ?
Thank you