@Test public void testExecute() { final Customer customer = createCustomer(); MutableShoppingCart shoppingCart = new ShoppingCartImpl(); shoppingCart.initialise(ctx().getBean("amountCalculationStrategy", AmountCalculationStrategy.class)); final ShoppingCartCommandFactory commands = ctx().getBean("shoppingCartCommandFactory", ShoppingCartCommandFactory.class); commands.execute(shoppingCart, new HashMap<String, Object>() {{ put(ShoppingCartCommand.CMD_CHANGECURRENCY, "EUR"); put(ShoppingCartCommand.CMD_CHANGELOCALE, "en"); put(ShoppingCartCommand.CMD_SETSHOP, "10"); }}); assertNull(shoppingCart.getShoppingContext().getLatestViewedSkus()); Map<String, Object> params = new HashMap<>(); params.put(ShoppingCartCommand.CMD_INTERNAL_VIEWSKU, "1"); params.put(ShoppingCartCommand.CMD_P_SUPPLIER, "s01"); commands.execute(shoppingCart, (Map) params); List<String> skus = shoppingCart.getShoppingContext().getLatestViewedSkus(); assertNotNull(skus); assertEquals(1, skus.size()); assertEquals("1|s01", skus.get(0)); for (int i = 1; i <= 10; i++) { params.put(ShoppingCartCommand.CMD_INTERNAL_VIEWSKU, String.valueOf(i)); params.put(ShoppingCartCommand.CMD_P_SUPPLIER, "s01"); commands.execute(shoppingCart, (Map) params); } skus = shoppingCart.getShoppingContext().getLatestViewedSkus(); assertNotNull(skus); assertEquals(10, skus.size()); for (int i = 1; i <= 10; i++) { assertEquals(String.valueOf(i) + "|s01", skus.get(i - 1)); } params.put(ShoppingCartCommand.CMD_INTERNAL_VIEWSKU, "11"); params.put(ShoppingCartCommand.CMD_P_SUPPLIER, "s01"); commands.execute(shoppingCart, (Map) params); skus = shoppingCart.getShoppingContext().getLatestViewedSkus(); assertNotNull(skus); assertEquals(10, skus.size()); for (int i = 1; i <= 10; i++) { assertEquals(String.valueOf(i + 1) + "|s01", skus.get(i - 1)); } params.put(ShoppingCartCommand.CMD_INTERNAL_VIEWSKU, Arrays.asList("12", "13")); params.put(ShoppingCartCommand.CMD_P_SUPPLIER, "s01"); commands.execute(shoppingCart, (Map) params); skus = shoppingCart.getShoppingContext().getLatestViewedSkus(); assertNotNull(skus); assertEquals(10, skus.size()); for (int i = 1; i <= 10; i++) { assertEquals(String.valueOf(i + 3) + "|s01", skus.get(i - 1)); } }
@Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final Shop shop = this.shopService.getById(shoppingCart.getShoppingContext().getShopId()); final int max = NumberUtils.toInt(shop.getAttributeValueByCode(AttributeNamesKeys.Shop.SHOP_SF_MAX_LAST_VIEWED_SKU), maxProductHistory); final Object skus = parameters.get(getCmdKey()); final String supplier = (String) parameters.get(CMD_P_SUPPLIER); if (StringUtils.isNotBlank(supplier)) { if (skus instanceof Collection) { for (final Object sku : (Collection) skus) { updateViewedSku(shoppingCart, (String) sku, supplier, max); } } else { updateViewedSku(shoppingCart, (String) skus, supplier, max); } } } }
ViewProductSkuInternalCommandImpl extends AbstractCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final Shop shop = this.shopService.getById(shoppingCart.getShoppingContext().getShopId()); final int max = NumberUtils.toInt(shop.getAttributeValueByCode(AttributeNamesKeys.Shop.SHOP_SF_MAX_LAST_VIEWED_SKU), maxProductHistory); final Object skus = parameters.get(getCmdKey()); final String supplier = (String) parameters.get(CMD_P_SUPPLIER); if (StringUtils.isNotBlank(supplier)) { if (skus instanceof Collection) { for (final Object sku : (Collection) skus) { updateViewedSku(shoppingCart, (String) sku, supplier, max); } } else { updateViewedSku(shoppingCart, (String) skus, supplier, max); } } } } }
ViewProductSkuInternalCommandImpl extends AbstractCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final Shop shop = this.shopService.getById(shoppingCart.getShoppingContext().getShopId()); final int max = NumberUtils.toInt(shop.getAttributeValueByCode(AttributeNamesKeys.Shop.SHOP_SF_MAX_LAST_VIEWED_SKU), maxProductHistory); final Object skus = parameters.get(getCmdKey()); final String supplier = (String) parameters.get(CMD_P_SUPPLIER); if (StringUtils.isNotBlank(supplier)) { if (skus instanceof Collection) { for (final Object sku : (Collection) skus) { updateViewedSku(shoppingCart, (String) sku, supplier, max); } } else { updateViewedSku(shoppingCart, (String) skus, supplier, max); } } } } ViewProductSkuInternalCommandImpl(final ShoppingCartCommandRegistry registry,
                                             final ShopService shopService,
                                             final int maxProductHistory); }
ViewProductSkuInternalCommandImpl extends AbstractCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final Shop shop = this.shopService.getById(shoppingCart.getShoppingContext().getShopId()); final int max = NumberUtils.toInt(shop.getAttributeValueByCode(AttributeNamesKeys.Shop.SHOP_SF_MAX_LAST_VIEWED_SKU), maxProductHistory); final Object skus = parameters.get(getCmdKey()); final String supplier = (String) parameters.get(CMD_P_SUPPLIER); if (StringUtils.isNotBlank(supplier)) { if (skus instanceof Collection) { for (final Object sku : (Collection) skus) { updateViewedSku(shoppingCart, (String) sku, supplier, max); } } else { updateViewedSku(shoppingCart, (String) skus, supplier, max); } } } } ViewProductSkuInternalCommandImpl(final ShoppingCartCommandRegistry registry,
                                             final ShopService shopService,
                                             final int maxProductHistory); @Override void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters); @Override String getCmdKey(); }
ViewProductSkuInternalCommandImpl extends AbstractCartCommandImpl implements ShoppingCartCommand { @Override public void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters) { if (parameters.containsKey(getCmdKey())) { final Shop shop = this.shopService.getById(shoppingCart.getShoppingContext().getShopId()); final int max = NumberUtils.toInt(shop.getAttributeValueByCode(AttributeNamesKeys.Shop.SHOP_SF_MAX_LAST_VIEWED_SKU), maxProductHistory); final Object skus = parameters.get(getCmdKey()); final String supplier = (String) parameters.get(CMD_P_SUPPLIER); if (StringUtils.isNotBlank(supplier)) { if (skus instanceof Collection) { for (final Object sku : (Collection) skus) { updateViewedSku(shoppingCart, (String) sku, supplier, max); } } else { updateViewedSku(shoppingCart, (String) skus, supplier, max); } } } } ViewProductSkuInternalCommandImpl(final ShoppingCartCommandRegistry registry,
                                             final ShopService shopService,
                                             final int maxProductHistory); @Override void execute(final MutableShoppingCart shoppingCart, final Map<String, Object> parameters); @Override String getCmdKey();  }