@Test public void testExecute() { ShopService shopService = (ShopService) ctx().getBean(ServiceSpringKeys.SHOP_SERVICE); Shop shop10 = shopService.getById(10L); Shop shop20 = shopService.getById(20L); final Customer customer = createCustomer(); MutableShoppingCart shoppingCart = new ShoppingCartImpl(); shoppingCart.initialise(ctx().getBean("amountCalculationStrategy", AmountCalculationStrategy.class)); final ShoppingCartCommandFactory commands = ctx().getBean("shoppingCartCommandFactory", ShoppingCartCommandFactory.class); Map<String, String> params = new HashMap<>(); shoppingCart.getShoppingContext().setShopCode(shop20.getCode()); shoppingCart.getShoppingContext().setShopId(shop20.getShopId()); commands.execute(shoppingCart, (Map) params); assertEquals(ShoppingCart.NOT_LOGGED, shoppingCart.getLogonState()); assertEquals(ShoppingCart.NOT_LOGGED, shoppingCart.getLogonState()); params.put(ShoppingCartCommand.CMD_LOGIN_P_EMAIL, customer.getEmail()); params.put(ShoppingCartCommand.CMD_LOGIN_P_PASS, "rawpassword"); params.put(ShoppingCartCommand.CMD_LOGIN, "1"); commands.execute(shoppingCart, (Map) params); assertEquals(ShoppingCart.NOT_LOGGED, shoppingCart.getLogonState()); shoppingCart.getShoppingContext().setShopCode(shop10.getCode()); shoppingCart.getShoppingContext().setShopId(shop10.getShopId()); commands.execute(shoppingCart, (Map) params); assertEquals(ShoppingCart.LOGGED_IN, shoppingCart.getLogonState()); assertNull(shoppingCart.getOrderInfo().getDetailByKey(AttributeNamesKeys.Cart.ORDER_INFO_B2B_REF)); assertNull(shoppingCart.getOrderInfo().getDetailByKey(AttributeNamesKeys.Cart.ORDER_INFO_B2B_CHARGE_ID)); assertNull(shoppingCart.getOrderInfo().getDetailByKey(AttributeNamesKeys.Cart.ORDER_INFO_B2B_EMPLOYEE_ID)); assertEquals("false", shoppingCart.getOrderInfo().getDetailByKey(AttributeNamesKeys.Cart.ORDER_INFO_APPROVE_ORDER)); assertEquals("false", shoppingCart.getOrderInfo().getDetailByKey(AttributeNamesKeys.Cart.ORDER_INFO_BLOCK_CHECKOUT)); }
@Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final String email = (String) parameters.get(CMD_LOGIN_P_EMAIL); final String passw = (String) parameters.get(CMD_LOGIN_P_PASS); final long shopId = shoppingCart.getShoppingContext().getShopId(); final Shop current = shopService.getById(shopId); final MutableShoppingContext ctx = shoppingCart.getShoppingContext(); final MutableOrderInfo info = shoppingCart.getOrderInfo(); if (current != null && authenticate(email, current, passw)) { final Customer customer = customerResolver.getCustomerByEmail(email, current); final List<String> customerShops = new ArrayList<>(); shoppingCart.getShoppingContext().setCustomerShopId(shoppingCart.getShoppingContext().getShopId()); shoppingCart.getShoppingContext().setCustomerShopCode(shoppingCart.getShoppingContext().getShopCode()); for (final Shop shop : customerResolver.getCustomerShops(customer)) { customerShops.add(shop.getCode()); if (shop.getMaster() != null && shop.getMaster().getShopId() == shopId) { shoppingCart.getShoppingContext().setCustomerShopId(shop.getShopId()); shoppingCart.getShoppingContext().setCustomerShopCode(shop.getCode()); } } ctx.setCustomerEmail(customer.getEmail()); ctx.setCustomerName(customerResolver.formatNameFor(customer, current)); ctx.setCustomerShops(customerShops); setDefaultCustomerOptions(shoppingCart); setDefaultAddressesIfNecessary(current, customer, shoppingCart); setDefaultTaxOptions(shoppingCart); recalculatePricesInCart(shoppingCart); recalculate(shoppingCart); markDirty(shoppingCart); } else { ctx.clearContext(); info.clearInfo(); setDefaultCustomerOptions(shoppingCart); setDefaultTaxOptions(shoppingCart); markDirty(shoppingCart); } } }
LoginCommandImpl extends AbstractRecalculatePriceCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final String email = (String) parameters.get(CMD_LOGIN_P_EMAIL); final String passw = (String) parameters.get(CMD_LOGIN_P_PASS); final long shopId = shoppingCart.getShoppingContext().getShopId(); final Shop current = shopService.getById(shopId); final MutableShoppingContext ctx = shoppingCart.getShoppingContext(); final MutableOrderInfo info = shoppingCart.getOrderInfo(); if (current != null && authenticate(email, current, passw)) { final Customer customer = customerResolver.getCustomerByEmail(email, current); final List<String> customerShops = new ArrayList<>(); shoppingCart.getShoppingContext().setCustomerShopId(shoppingCart.getShoppingContext().getShopId()); shoppingCart.getShoppingContext().setCustomerShopCode(shoppingCart.getShoppingContext().getShopCode()); for (final Shop shop : customerResolver.getCustomerShops(customer)) { customerShops.add(shop.getCode()); if (shop.getMaster() != null && shop.getMaster().getShopId() == shopId) { shoppingCart.getShoppingContext().setCustomerShopId(shop.getShopId()); shoppingCart.getShoppingContext().setCustomerShopCode(shop.getCode()); } } ctx.setCustomerEmail(customer.getEmail()); ctx.setCustomerName(customerResolver.formatNameFor(customer, current)); ctx.setCustomerShops(customerShops); setDefaultCustomerOptions(shoppingCart); setDefaultAddressesIfNecessary(current, customer, shoppingCart); setDefaultTaxOptions(shoppingCart); recalculatePricesInCart(shoppingCart); recalculate(shoppingCart); markDirty(shoppingCart); } else { ctx.clearContext(); info.clearInfo(); setDefaultCustomerOptions(shoppingCart); setDefaultTaxOptions(shoppingCart); markDirty(shoppingCart); } } } }
LoginCommandImpl extends AbstractRecalculatePriceCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final String email = (String) parameters.get(CMD_LOGIN_P_EMAIL); final String passw = (String) parameters.get(CMD_LOGIN_P_PASS); final long shopId = shoppingCart.getShoppingContext().getShopId(); final Shop current = shopService.getById(shopId); final MutableShoppingContext ctx = shoppingCart.getShoppingContext(); final MutableOrderInfo info = shoppingCart.getOrderInfo(); if (current != null && authenticate(email, current, passw)) { final Customer customer = customerResolver.getCustomerByEmail(email, current); final List<String> customerShops = new ArrayList<>(); shoppingCart.getShoppingContext().setCustomerShopId(shoppingCart.getShoppingContext().getShopId()); shoppingCart.getShoppingContext().setCustomerShopCode(shoppingCart.getShoppingContext().getShopCode()); for (final Shop shop : customerResolver.getCustomerShops(customer)) { customerShops.add(shop.getCode()); if (shop.getMaster() != null && shop.getMaster().getShopId() == shopId) { shoppingCart.getShoppingContext().setCustomerShopId(shop.getShopId()); shoppingCart.getShoppingContext().setCustomerShopCode(shop.getCode()); } } ctx.setCustomerEmail(customer.getEmail()); ctx.setCustomerName(customerResolver.formatNameFor(customer, current)); ctx.setCustomerShops(customerShops); setDefaultCustomerOptions(shoppingCart); setDefaultAddressesIfNecessary(current, customer, shoppingCart); setDefaultTaxOptions(shoppingCart); recalculatePricesInCart(shoppingCart); recalculate(shoppingCart); markDirty(shoppingCart); } else { ctx.clearContext(); info.clearInfo(); setDefaultCustomerOptions(shoppingCart); setDefaultTaxOptions(shoppingCart); markDirty(shoppingCart); } } } LoginCommandImpl(final ShoppingCartCommandRegistry registry,
                            final CustomerResolver customerResolver,
                            final ShopService shopService,
                            final PriceResolver priceResolver,
                            final PricingPolicyProvider pricingPolicyProvider,
                            final ProductService productService); }
LoginCommandImpl extends AbstractRecalculatePriceCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final String email = (String) parameters.get(CMD_LOGIN_P_EMAIL); final String passw = (String) parameters.get(CMD_LOGIN_P_PASS); final long shopId = shoppingCart.getShoppingContext().getShopId(); final Shop current = shopService.getById(shopId); final MutableShoppingContext ctx = shoppingCart.getShoppingContext(); final MutableOrderInfo info = shoppingCart.getOrderInfo(); if (current != null && authenticate(email, current, passw)) { final Customer customer = customerResolver.getCustomerByEmail(email, current); final List<String> customerShops = new ArrayList<>(); shoppingCart.getShoppingContext().setCustomerShopId(shoppingCart.getShoppingContext().getShopId()); shoppingCart.getShoppingContext().setCustomerShopCode(shoppingCart.getShoppingContext().getShopCode()); for (final Shop shop : customerResolver.getCustomerShops(customer)) { customerShops.add(shop.getCode()); if (shop.getMaster() != null && shop.getMaster().getShopId() == shopId) { shoppingCart.getShoppingContext().setCustomerShopId(shop.getShopId()); shoppingCart.getShoppingContext().setCustomerShopCode(shop.getCode()); } } ctx.setCustomerEmail(customer.getEmail()); ctx.setCustomerName(customerResolver.formatNameFor(customer, current)); ctx.setCustomerShops(customerShops); setDefaultCustomerOptions(shoppingCart); setDefaultAddressesIfNecessary(current, customer, shoppingCart); setDefaultTaxOptions(shoppingCart); recalculatePricesInCart(shoppingCart); recalculate(shoppingCart); markDirty(shoppingCart); } else { ctx.clearContext(); info.clearInfo(); setDefaultCustomerOptions(shoppingCart); setDefaultTaxOptions(shoppingCart); markDirty(shoppingCart); } } } LoginCommandImpl(final ShoppingCartCommandRegistry registry,
                            final CustomerResolver customerResolver,
                            final ShopService shopService,
                            final PriceResolver priceResolver,
                            final PricingPolicyProvider pricingPolicyProvider,
                            final ProductService productService); @Override String getCmdKey(); @Override void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters); }
LoginCommandImpl extends AbstractRecalculatePriceCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final String email = (String) parameters.get(CMD_LOGIN_P_EMAIL); final String passw = (String) parameters.get(CMD_LOGIN_P_PASS); final long shopId = shoppingCart.getShoppingContext().getShopId(); final Shop current = shopService.getById(shopId); final MutableShoppingContext ctx = shoppingCart.getShoppingContext(); final MutableOrderInfo info = shoppingCart.getOrderInfo(); if (current != null && authenticate(email, current, passw)) { final Customer customer = customerResolver.getCustomerByEmail(email, current); final List<String> customerShops = new ArrayList<>(); shoppingCart.getShoppingContext().setCustomerShopId(shoppingCart.getShoppingContext().getShopId()); shoppingCart.getShoppingContext().setCustomerShopCode(shoppingCart.getShoppingContext().getShopCode()); for (final Shop shop : customerResolver.getCustomerShops(customer)) { customerShops.add(shop.getCode()); if (shop.getMaster() != null && shop.getMaster().getShopId() == shopId) { shoppingCart.getShoppingContext().setCustomerShopId(shop.getShopId()); shoppingCart.getShoppingContext().setCustomerShopCode(shop.getCode()); } } ctx.setCustomerEmail(customer.getEmail()); ctx.setCustomerName(customerResolver.formatNameFor(customer, current)); ctx.setCustomerShops(customerShops); setDefaultCustomerOptions(shoppingCart); setDefaultAddressesIfNecessary(current, customer, shoppingCart); setDefaultTaxOptions(shoppingCart); recalculatePricesInCart(shoppingCart); recalculate(shoppingCart); markDirty(shoppingCart); } else { ctx.clearContext(); info.clearInfo(); setDefaultCustomerOptions(shoppingCart); setDefaultTaxOptions(shoppingCart); markDirty(shoppingCart); } } } LoginCommandImpl(final ShoppingCartCommandRegistry registry,
                            final CustomerResolver customerResolver,
                            final ShopService shopService,
                            final PriceResolver priceResolver,
                            final PricingPolicyProvider pricingPolicyProvider,
                            final ProductService productService); @Override String getCmdKey(); @Override void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters);  }