Index: web/support/src/main/java/org/yes/cart/web/filter/ShoppingCartFilter.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- web/support/src/main/java/org/yes/cart/web/filter/ShoppingCartFilter.java (revision 1379) +++ web/support/src/main/java/org/yes/cart/web/filter/ShoppingCartFilter.java (revision ) @@ -18,8 +18,11 @@ import org.springframework.aop.target.CommonsPoolTargetSource; +import org.yes.cart.domain.entity.Shop; import org.yes.cart.shoppingcart.AmountCalculationStrategy; import org.yes.cart.shoppingcart.ShoppingCart; +import org.yes.cart.shoppingcart.ShoppingCartCommand; +import org.yes.cart.shoppingcart.ShoppingCartCommandFactory; import org.yes.cart.util.ShopCodeContext; import org.yes.cart.web.application.ApplicationDirector; import org.yes.cart.web.shoppingcart.impl.WebShoppingCartImpl; @@ -32,6 +35,7 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import java.io.IOException; +import java.util.HashMap; /** * Shopping cart filter responsible to restore shopping cart from cookies, if it possible. @@ -47,19 +51,24 @@ private final AmountCalculationStrategy calculationStrategy; + private final ShoppingCartCommandFactory cartCommandFactory; + /** - * @param tuplizerPool pool of tuplizer to manage cookie to object to cookie transformation * @param applicationDirector app director. + * @param tuplizerPool pool of tuplizer to manage cookie to object to cookie transformation * @param calculationStrategy calculation strategy + * @param cartCommandFactory cart command factory */ public ShoppingCartFilter( final ApplicationDirector applicationDirector, final CommonsPoolTargetSource tuplizerPool, - final AmountCalculationStrategy calculationStrategy) { + final AmountCalculationStrategy calculationStrategy, + final ShoppingCartCommandFactory cartCommandFactory) { super(applicationDirector); this.tuplizerPool = tuplizerPool; this.calculationStrategy = calculationStrategy; + this.cartCommandFactory = cartCommandFactory; } @@ -84,6 +93,7 @@ ShopCodeContext.getLog(this).warn("Cart not restored from cookies"); } cart.initialise(calculationStrategy); + setDefaultValuesIfNecessary(ApplicationDirector.getCurrentShop(), cart); ApplicationDirector.setShoppingCart(cart); } catch (Exception e) { @@ -100,6 +110,27 @@ return request; } + + + /** + * Set default values. Mostly for new cart. + * + * @param shop shop + * @param cart cart + */ + private void setDefaultValuesIfNecessary(final Shop shop, final ShoppingCart cart) { + + if (cart.getCurrencyCode() == null && shop != null) { // new cart only may satisfy this condition + + cartCommandFactory.execute(cart, new HashMap() {{ + put(ShoppingCartCommand.CMD_SETSHOP, shop.getShopId()); + put(ShoppingCartCommand.CMD_CHANGECURRENCY, shop.getDefaultCurrency()); + }}); + + } + + } + /** Index: web/store/src/main/webapp/WEB-INF/web.xml IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- web/store/src/main/webapp/WEB-INF/web.xml (revision 1379) +++ web/store/src/main/webapp/WEB-INF/web.xml (revision ) @@ -74,7 +74,7 @@ - shoppingCartFilter + shopResolverFilter org.springframework.web.filter.DelegatingFilterProxy targetFilterLifecycle @@ -82,12 +82,12 @@ excludePattern - (services/(backdoor|cachedirector))|(imgvault/)|(wicket/resource/) + services/(backdoor|cachedirector) - shopResolverFilter + shoppingCartFilter org.springframework.web.filter.DelegatingFilterProxy targetFilterLifecycle @@ -95,7 +95,7 @@ excludePattern - services/(backdoor|cachedirector) + (services/(backdoor|cachedirector))|(imgvault/)|(wicket/resource/) @@ -219,12 +219,12 @@ - shoppingCartFilter + shopResolverFilter /* - shopResolverFilter + shoppingCartFilter /* \ No newline at end of file Index: web/support/src/main/java/org/yes/cart/web/filter/ShopResolverFilter.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- web/support/src/main/java/org/yes/cart/web/filter/ShopResolverFilter.java (revision 1379) +++ web/support/src/main/java/org/yes/cart/web/filter/ShopResolverFilter.java (revision ) @@ -21,9 +21,6 @@ import org.springframework.web.context.ServletContextAware; import org.yes.cart.domain.entity.Shop; import org.yes.cart.service.domain.SystemService; -import org.yes.cart.shoppingcart.ShoppingCart; -import org.yes.cart.shoppingcart.ShoppingCartCommand; -import org.yes.cart.shoppingcart.ShoppingCartCommandFactory; import org.yes.cart.util.ShopCodeContext; import org.yes.cart.web.application.ApplicationDirector; import org.yes.cart.web.support.request.HttpServletRequestWrapper; @@ -33,7 +30,6 @@ import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; -import java.util.HashMap; /** @@ -51,16 +47,12 @@ private ServletContext servletContext; - private final ShoppingCartCommandFactory cartCommandFactory; - public ShopResolverFilter( final ApplicationDirector applicationDirector, - final SystemService systemService, - final ShoppingCartCommandFactory cartCommandFactory) { + final SystemService systemService) { super(applicationDirector); this.systemService = systemService; - this.cartCommandFactory = cartCommandFactory; } /** @@ -83,8 +75,6 @@ return null; } - setDefaultValues(shop); - ApplicationDirector.setCurrentShop(shop); ApplicationDirector.setShopperIPAddress(getRemoteIpAddr(servletRequest)); ShopCodeContext.setShopCode(shop.getCode()); @@ -105,26 +95,6 @@ } return userIpAddress; } - - /** - * Set default values. Mostly for new cart. - * @param shop shop - */ - private void setDefaultValues(final Shop shop) { - - final ShoppingCart shoppingCart = ApplicationDirector.getShoppingCart(); - if (shoppingCart != null) { // this may happen if shoppingCart filter is not assigned to this url pattern - if (shoppingCart.getCurrencyCode() == null) { // new cart only may satisfy this condition - - cartCommandFactory.execute(shoppingCart, new HashMap() {{ - put(ShoppingCartCommand.CMD_SETSHOP, shop.getShopId()); - put(ShoppingCartCommand.CMD_CHANGECURRENCY, shop.getDefaultCurrency()); - }}); - - } - } - } - /** Index: web/support/src/main/resources/websupport-webapp.xml IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- web/support/src/main/resources/websupport-webapp.xml (revision 1379) +++ web/support/src/main/resources/websupport-webapp.xml (revision ) @@ -33,7 +33,6 @@ - @@ -46,6 +45,7 @@ + \ No newline at end of file