ChangeCurrencyEventCommandImpl extends AbstractRecalculatePriceCartCommandImpl { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final String currencyCode = (String) parameters.get(getCmdKey()); if (currencyCode != null && !currencyCode.equals(shoppingCart.getCurrencyCode())) { final Shop shop = getShopService().getById(shoppingCart.getShoppingContext().getShopId()); if (shop.getSupportedCurrenciesAsList().contains(currencyCode)) { shoppingCart.setCurrencyCode(currencyCode); shoppingCart.getOrderInfo().setCarrierSlaId(null); shoppingCart.getOrderInfo().setPaymentGatewayLabel(null); recalculatePricesInCart(shoppingCart); markDirty(shoppingCart); } } } } ChangeCurrencyEventCommandImpl(final ShoppingCartCommandRegistry registry,
                                          final PriceResolver priceResolver,
                                          final PricingPolicyProvider pricingPolicyProvider,
                                          final ProductService productService,
                                          final ShopService shopService); @Override String getCmdKey(); @Override void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters);  }
@Test public void testExecute() { MutableShoppingCart shoppingCart = new ShoppingCartImpl(); shoppingCart.initialise(ctx().getBean("amountCalculationStrategy", AmountCalculationStrategy.class)); final ShoppingCartCommandFactory commands = ctx().getBean("shoppingCartCommandFactory", ShoppingCartCommandFactory.class); commands.execute(shoppingCart, (Map) Collections.singletonMap(ShoppingCartCommand.CMD_SETSHOP, "10")); commands.execute(shoppingCart, (Map) Collections.singletonMap(ShoppingCartCommand.CMD_CHANGECURRENCY, "EUR")); assertEquals(MoneyUtils.ZERO, shoppingCart.getTotal().getSubTotal()); for (int i = 0; i < 3; i++) { commands.execute(shoppingCart, (Map) Collections.singletonMap(ShoppingCartCommand.CMD_ADDTOCART, "CC_TEST1")); } assertEquals("57.00", shoppingCart.getTotal().getSubTotal().toPlainString()); commands.execute(shoppingCart, (Map) Collections.singletonMap(ShoppingCartCommand.CMD_CHANGECURRENCY, "USD")); assertEquals("USD", shoppingCart.getCurrencyCode()); assertEquals("570.03", shoppingCart.getTotal().getSubTotal().toPlainString()); }