Page 1 of 1

SimpleTaxModule is never called

Posted: Tue Feb 18, 2014 5:17 am
by Theo Schumacher
Hi,

I'am trying to activate the SimpleTaxModule as described in the getting started guide. I have changed my application-Context.xml and added

Code: Select all

 <bean id="blTaxModule" class="org.broadleafcommerce.core.pricing.service.module.SimpleTaxModule">
   <!-- Set properties for your specific tax configuration.  -->
  <property name="itemStateTaxRateMap">
    <map>
      <entry key="DE" value=".99" /> 
    </map>
  </property>
  <property name="defaultItemTaxRate"  value=".21" />
</bean>


I changed defaultTaxRate to defaultItemTaxRate because this is the real name of the property in 3.0.8

When ordering a product in the demo site, I never get any tax. Placing a breapoint on TaxActivity.class shows that the method 'execute' is never called.

I have seen in another post that tax modules for external tax systems has changed and uses a TaxProvider class and a Module configuration in the database.

Is the documentation of the tax module no more up-to-date? How should I do to use the SimpleTaxModule which is still present in the source code?

Thx

Re: SimpleTaxModule is never called

Posted: Tue Feb 18, 2014 7:52 am
by Deepak
We also facing same problem do you have any updated document for configure tax module.




rgds
deepak

Re: SimpleTaxModule is never called

Posted: Tue Feb 18, 2014 12:07 pm
by Theo Schumacher
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

Re: SimpleTaxModule is never called

Posted: Wed Feb 19, 2014 2:16 am
by Deepak
Hello Theo Schumacher,
Hope you are doing fine!!! i need a small help from you which is need a clarification about you have sended a few steps which you have created a entity with implements and extends and xml configuration after doing that you got the output or facing the same issue.




thx
Deepak

Re: SimpleTaxModule is never called

Posted: Wed Feb 19, 2014 3:12 am
by Theo Schumacher
Hi

current status is that did I not try to use SimpleTaxModule anymore as it is no more compatible with the new method used by broadleaf. Therefore I created my own TaxProvider. But as I did not manage to inject a List<TaxProvider> as a bean with name "blTaxProviders", my TaxProvider is never called. Maybe you know how to do that in spring xml ?

I will try to find out today

Regards

Re: SimpleTaxModule is never called

Posted: Wed Feb 19, 2014 5:38 am
by Theo Schumacher
Hello

I could make it work. This is the final setup for applicationContext.xml:

Code: Select all

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
      xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="
        http://www.springframework.org/schema/jee
        http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.2.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
        http://www.springframework.org/schema/aop
http://www.springframework.org/schema/util/spring-util-3.2.xsd
        http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">


   <bean id="VATTaxProvider" class="eu.seacloud.module.tax.VatTaxProviderImpl" />

   <util:list id="blTaxProviders" value-type="eu.seacloud.module.tax.VatTaxProviderImpl">
      <ref bean="VATTaxProvider" />
   </util:list>
   <bean id="oldTaxModule"
      class="org.broadleafcommerce.core.pricing.service.module.SimpleTaxModule">
      <!-- Set properties for your specific tax configuration. -->
      <property name="itemStateTaxRateMap">
         <map>
            <entry key="DE" value=".99" />
         </map>
      </property>
      <property name="defaultItemTaxRate" value=".21" />
   </bean>


to make use of the old SimpleTaxModule, i have changed my TaxProvider as here:

Code: Select all

package eu.seacloud.module.tax;

import javax.annotation.Resource;

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.module.SimpleTaxModule;
import org.broadleafcommerce.core.pricing.service.tax.provider.TaxProvider;

public class VatTaxProviderImpl implements TaxProvider {

   @Resource (name = "oldTaxModule")
   protected SimpleTaxModule simpleTaxModule;
   
   @Override
   public boolean canRespond(ModuleConfiguration config) {
      if (config instanceof VATConfigurationImpl) {
         return true;
         }
         return false;
   }

   @SuppressWarnings("deprecation")
   @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 simpleTaxModule.calculateTaxForOrder(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

   }

}


when adding a sauce to the cart, a log message is written to the console saying that tax is calculated. When calling checkout on the cart, tax is effectively added on top of the order. Now I can go on with implementation of the european VAT module.

Hope it can help others
Theo