@Test public void testExecute() { ShopService shopService = (ShopService) ctx().getBean(ServiceSpringKeys.SHOP_SERVICE); Shop shop = shopService.getById(10L); final Customer customer = createCustomer(); final ProductSkuService skuService = ctx().getBean("productSkuService", ProductSkuService.class); final CustomerWishListService customerWishListService = ctx().getBean("customerWishListService", CustomerWishListService.class); MutableShoppingCart shoppingCart = new ShoppingCartImpl(); shoppingCart.getShoppingContext().setShopCode(shop.getCode()); shoppingCart.getShoppingContext().setShopId(shop.getShopId()); shoppingCart.initialise(ctx().getBean("amountCalculationStrategy", AmountCalculationStrategy.class)); final ShoppingCartCommandFactory commands = ctx().getBean("shoppingCartCommandFactory", ShoppingCartCommandFactory.class); assertEquals(ShoppingCart.NOT_LOGGED, shoppingCart.getLogonState()); Map<String, String> params = new HashMap<>(); params.put(ShoppingCartCommand.CMD_LOGIN_P_EMAIL, customer.getEmail()); params.put(ShoppingCartCommand.CMD_LOGIN_P_PASS, "rawpassword"); params.put(LoginCommandImpl.CMD_LOGIN, "1"); commands.execute(shoppingCart, (Map) params); assertEquals(ShoppingCart.LOGGED_IN, shoppingCart.getLogonState()); commands.execute(shoppingCart, (Map) singletonMap(ShoppingCartCommand.CMD_SETSHOP, 10)); commands.execute(shoppingCart, (Map) singletonMap(ShoppingCartCommand.CMD_CHANGECURRENCY, "EUR")); List<CustomerWishList> wishList = customerWishListService.findWishListByCustomerId(customer.getCustomerId()); assertNotNull(wishList); assertTrue(wishList.isEmpty()); params.clear(); params.put(ShoppingCartCommand.CMD_ADDTOWISHLIST, "CC_TEST1"); params.put(ShoppingCartCommand.CMD_P_SUPPLIER, "WAREHOUSE_1"); params.put(ShoppingCartCommand.CMD_ADDTOWISHLIST_P_TAGS, "mine"); commands.execute(shoppingCart, (Map) params); wishList = customerWishListService.findWishListByCustomerId(customer.getCustomerId()); assertNotNull(wishList); assertEquals(1, wishList.size()); CustomerWishList item1 = wishList.get(0); assertEquals(CustomerWishList.PRIVATE, item1.getVisibility()); assertEquals(CustomerWishList.SIMPLE_WISH_ITEM, item1.getWlType()); assertEquals("CC_TEST1", item1.getSkuCode()); assertEquals("mine", item1.getTag()); assertEquals(1, item1.getQuantity().intValue()); assertEquals("19.99", item1.getRegularPriceWhenAdded().toString()); params.put(ShoppingCartCommand.CMD_ADDTOWISHLIST, "CC_TEST1"); params.put(ShoppingCartCommand.CMD_P_SUPPLIER, "WAREHOUSE_1"); params.put(ShoppingCartCommand.CMD_ADDTOWISHLIST_P_TAGS, "mine shared"); commands.execute(shoppingCart, (Map) params); wishList = customerWishListService.findWishListByCustomerId(customer.getCustomerId()); assertNotNull(wishList); assertEquals(1, wishList.size()); item1 = wishList.get(0); assertEquals(CustomerWishList.PRIVATE, item1.getVisibility()); assertEquals(CustomerWishList.SIMPLE_WISH_ITEM, item1.getWlType()); assertEquals("CC_TEST1", item1.getSkuCode()); assertEquals("mine shared", item1.getTag()); assertEquals(2, item1.getQuantity().intValue()); assertEquals("19.99", item1.getRegularPriceWhenAdded().toString()); }
@Override protected void execute(final MutableShoppingCart shoppingCart, final ProductSku productSku, final String skuCode, final String supplier, final String itemGroup, final BigDecimal qty, final Map<String, Object> parameters) { if (ShoppingCart.LOGGED_IN == shoppingCart.getLogonState()) { final String type = getTypeValue(parameters); final String tags = getTagsValue(parameters); final boolean tagsr = isTagsValueReplace(parameters); final String visibility = getVisibilityValue(parameters); final String notification = getNotificationValue(parameters); createWishListItem(shoppingCart, skuCode, supplier, qty, type, tags, tagsr, visibility, notification, parameters); if (CustomerWishList.CART_SAVE_FOR_LATER.equals(type)) { LOG.debug("[{}] Added item of sku code {} to save for later, removing sku from cart", shoppingCart.getGuid(), skuCode); final Map removeParams = new HashMap(); removeParams.put(ShoppingCartCommand.CMD_REMOVEALLSKU, skuCode); removeParams.put(ShoppingCartCommand.CMD_P_SUPPLIER, supplier); getRemoveAllSku().execute(shoppingCart, removeParams); } else if (forceRecalculateCart) { recalculatePricesInCart(shoppingCart); markDirty(shoppingCart); } LOG.debug("[{}] Added item of sku code {} to wishlist", shoppingCart.getGuid(), skuCode); } else { LOG.debug("[{}] Unable to added item of sku code {} to wishlist, user is not logged in", shoppingCart.getGuid(), skuCode); } }
AddSkuToWishListEventCommandImpl extends AbstractSkuCartCommandImpl { @Override protected void execute(final MutableShoppingCart shoppingCart, final ProductSku productSku, final String skuCode, final String supplier, final String itemGroup, final BigDecimal qty, final Map<String, Object> parameters) { if (ShoppingCart.LOGGED_IN == shoppingCart.getLogonState()) { final String type = getTypeValue(parameters); final String tags = getTagsValue(parameters); final boolean tagsr = isTagsValueReplace(parameters); final String visibility = getVisibilityValue(parameters); final String notification = getNotificationValue(parameters); createWishListItem(shoppingCart, skuCode, supplier, qty, type, tags, tagsr, visibility, notification, parameters); if (CustomerWishList.CART_SAVE_FOR_LATER.equals(type)) { LOG.debug("[{}] Added item of sku code {} to save for later, removing sku from cart", shoppingCart.getGuid(), skuCode); final Map removeParams = new HashMap(); removeParams.put(ShoppingCartCommand.CMD_REMOVEALLSKU, skuCode); removeParams.put(ShoppingCartCommand.CMD_P_SUPPLIER, supplier); getRemoveAllSku().execute(shoppingCart, removeParams); } else if (forceRecalculateCart) { recalculatePricesInCart(shoppingCart); markDirty(shoppingCart); } LOG.debug("[{}] Added item of sku code {} to wishlist", shoppingCart.getGuid(), skuCode); } else { LOG.debug("[{}] Unable to added item of sku code {} to wishlist, user is not logged in", shoppingCart.getGuid(), skuCode); } } }
AddSkuToWishListEventCommandImpl extends AbstractSkuCartCommandImpl { @Override protected void execute(final MutableShoppingCart shoppingCart, final ProductSku productSku, final String skuCode, final String supplier, final String itemGroup, final BigDecimal qty, final Map<String, Object> parameters) { if (ShoppingCart.LOGGED_IN == shoppingCart.getLogonState()) { final String type = getTypeValue(parameters); final String tags = getTagsValue(parameters); final boolean tagsr = isTagsValueReplace(parameters); final String visibility = getVisibilityValue(parameters); final String notification = getNotificationValue(parameters); createWishListItem(shoppingCart, skuCode, supplier, qty, type, tags, tagsr, visibility, notification, parameters); if (CustomerWishList.CART_SAVE_FOR_LATER.equals(type)) { LOG.debug("[{}] Added item of sku code {} to save for later, removing sku from cart", shoppingCart.getGuid(), skuCode); final Map removeParams = new HashMap(); removeParams.put(ShoppingCartCommand.CMD_REMOVEALLSKU, skuCode); removeParams.put(ShoppingCartCommand.CMD_P_SUPPLIER, supplier); getRemoveAllSku().execute(shoppingCart, removeParams); } else if (forceRecalculateCart) { recalculatePricesInCart(shoppingCart); markDirty(shoppingCart); } LOG.debug("[{}] Added item of sku code {} to wishlist", shoppingCart.getGuid(), skuCode); } else { LOG.debug("[{}] Unable to added item of sku code {} to wishlist, user is not logged in", shoppingCart.getGuid(), skuCode); } } AddSkuToWishListEventCommandImpl(final ShoppingCartCommandRegistry registry,
                                            final PriceResolver priceResolver,
                                            final PricingPolicyProvider pricingPolicyProvider,
                                            final ProductService productService,
                                            final ShopService shopService,
                                            final CustomerService customerService,
                                            final CustomerWishListService customerWishListService,
                                            final ProductQuantityStrategy productQuantityStrategy); }
AddSkuToWishListEventCommandImpl extends AbstractSkuCartCommandImpl { @Override protected void execute(final MutableShoppingCart shoppingCart, final ProductSku productSku, final String skuCode, final String supplier, final String itemGroup, final BigDecimal qty, final Map<String, Object> parameters) { if (ShoppingCart.LOGGED_IN == shoppingCart.getLogonState()) { final String type = getTypeValue(parameters); final String tags = getTagsValue(parameters); final boolean tagsr = isTagsValueReplace(parameters); final String visibility = getVisibilityValue(parameters); final String notification = getNotificationValue(parameters); createWishListItem(shoppingCart, skuCode, supplier, qty, type, tags, tagsr, visibility, notification, parameters); if (CustomerWishList.CART_SAVE_FOR_LATER.equals(type)) { LOG.debug("[{}] Added item of sku code {} to save for later, removing sku from cart", shoppingCart.getGuid(), skuCode); final Map removeParams = new HashMap(); removeParams.put(ShoppingCartCommand.CMD_REMOVEALLSKU, skuCode); removeParams.put(ShoppingCartCommand.CMD_P_SUPPLIER, supplier); getRemoveAllSku().execute(shoppingCart, removeParams); } else if (forceRecalculateCart) { recalculatePricesInCart(shoppingCart); markDirty(shoppingCart); } LOG.debug("[{}] Added item of sku code {} to wishlist", shoppingCart.getGuid(), skuCode); } else { LOG.debug("[{}] Unable to added item of sku code {} to wishlist, user is not logged in", shoppingCart.getGuid(), skuCode); } } AddSkuToWishListEventCommandImpl(final ShoppingCartCommandRegistry registry,
                                            final PriceResolver priceResolver,
                                            final PricingPolicyProvider pricingPolicyProvider,
                                            final ProductService productService,
                                            final ShopService shopService,
                                            final CustomerService customerService,
                                            final CustomerWishListService customerWishListService,
                                            final ProductQuantityStrategy productQuantityStrategy); @Override String getCmdKey(); ShoppingCartCommand getRemoveAllSku(); void setForceRecalculateCart(final boolean forceRecalculateCart); }
AddSkuToWishListEventCommandImpl extends AbstractSkuCartCommandImpl { @Override protected void execute(final MutableShoppingCart shoppingCart, final ProductSku productSku, final String skuCode, final String supplier, final String itemGroup, final BigDecimal qty, final Map<String, Object> parameters) { if (ShoppingCart.LOGGED_IN == shoppingCart.getLogonState()) { final String type = getTypeValue(parameters); final String tags = getTagsValue(parameters); final boolean tagsr = isTagsValueReplace(parameters); final String visibility = getVisibilityValue(parameters); final String notification = getNotificationValue(parameters); createWishListItem(shoppingCart, skuCode, supplier, qty, type, tags, tagsr, visibility, notification, parameters); if (CustomerWishList.CART_SAVE_FOR_LATER.equals(type)) { LOG.debug("[{}] Added item of sku code {} to save for later, removing sku from cart", shoppingCart.getGuid(), skuCode); final Map removeParams = new HashMap(); removeParams.put(ShoppingCartCommand.CMD_REMOVEALLSKU, skuCode); removeParams.put(ShoppingCartCommand.CMD_P_SUPPLIER, supplier); getRemoveAllSku().execute(shoppingCart, removeParams); } else if (forceRecalculateCart) { recalculatePricesInCart(shoppingCart); markDirty(shoppingCart); } LOG.debug("[{}] Added item of sku code {} to wishlist", shoppingCart.getGuid(), skuCode); } else { LOG.debug("[{}] Unable to added item of sku code {} to wishlist, user is not logged in", shoppingCart.getGuid(), skuCode); } } AddSkuToWishListEventCommandImpl(final ShoppingCartCommandRegistry registry,
                                            final PriceResolver priceResolver,
                                            final PricingPolicyProvider pricingPolicyProvider,
                                            final ProductService productService,
                                            final ShopService shopService,
                                            final CustomerService customerService,
                                            final CustomerWishListService customerWishListService,
                                            final ProductQuantityStrategy productQuantityStrategy); @Override String getCmdKey(); ShoppingCartCommand getRemoveAllSku(); void setForceRecalculateCart(final boolean forceRecalculateCart);  }