ShoppingCartImpl implements MutableShoppingCart { @Override public boolean setProductSkuPrice(final String supplier, final String skuCode, final BigDecimal salePrice, final BigDecimal listPrice) { boolean updated = false; for (final CartItemImpl item : getItems()) { if (ShoppingCartUtils.isCartItem(item, supplier, skuCode)) { if (item.isFixedPrice()) { if (MoneyUtils.isFirstBiggerThanSecond(salePrice, item.getPrice())) { item.setSalePrice(salePrice); item.setListPrice(listPrice); } else { item.setSalePrice(item.getPrice()); item.setListPrice(item.getPrice()); } } else { item.setPrice(salePrice != null ? salePrice : listPrice); item.setSalePrice(salePrice); item.setListPrice(listPrice); item.setAppliedPromo(null); item.setPromoApplied(false); } updated = true; } } return updated; }  @Override void initialise(final AmountCalculationStrategy calculationStrategy); @Override void markDirty(); @Override void clean(); @Override void recalculate(); @Override @JsonIgnore boolean isSeparateBillingAddress(); @Override @JsonIgnore boolean isBillingAddressNotRequired(); @Override @JsonIgnore boolean isDeliveryAddressNotRequired(); @Override @JsonIgnore String getOrderMessage(); @Override String getGuid(); @Override @JsonIgnore Map<String, Long> getCarrierSlaId(); @Override @JsonIgnore boolean isAllCarrierSlaSelected(); @Override @JsonIgnore boolean isAllCartItemsBucketed(); @Override @JsonIgnore List<CartItem> getCartItemList(); @Override @JsonIgnore Map<DeliveryBucket, List<CartItem>> getCartItemMap(); @Override @JsonIgnore List<CartItem> getShippingList(); @Override @JsonIgnore Map<DeliveryBucket, List<CartItem>> getShippingListMap(); @Override BigDecimal getProductSkuQuantity(final String supplier,
                                            final String sku); @Override boolean addProductSkuToCart(final String supplier,
                                       final String sku,
                                       final String skuName,
                                       final BigDecimal quantity,
                                       final String itemGroup,
                                       final boolean configurable,
                                       final boolean notSoldSeparately); @Override boolean addShippingToCart(final DeliveryBucket deliveryBucket,
                                     final String carrierSlaGUID,
                                     final String carrierSlaName,
                                     final BigDecimal quantity); @Override boolean addGiftToCart(final String supplier,
                                 final String sku,
                                 final String skuName,
                                 final BigDecimal quantity,
                                 final String promotionCode); @Override boolean setProductSkuToCart(final String supplier,
                                       final String sku,
                                       final String skuName,
                                       final BigDecimal quantity,
                                       final String itemGroup); @Override boolean setProductSkuDeliveryBucket(final String sku,
                                               final DeliveryBucket deliveryBucket); @Override boolean setGiftDeliveryBucket(final String sku,
                                         final DeliveryBucket deliveryBucket); @Override boolean removeCartItem(final String supplier,
                                  final String productSku,
                                  final String itemGroup); @Override boolean removeCartItemQuantity(final String supplier,
                                          final String productSku,
                                          final BigDecimal quantity,
                                          final String itemGroup); @Override boolean removeItemPromotions(); @Override boolean removeItemOffers(); @Override boolean removeShipping(); @Override boolean removeShipping(final String carrierSlaGUID,
                                  final DeliveryBucket deliveryBucket); @Override boolean setProductSkuPrice(final String supplier,
                                      final String skuCode,
                                      final BigDecimal salePrice,
                                      final BigDecimal listPrice); @Override boolean setShippingPrice(final String carrierSlaGUID,
                                    final DeliveryBucket deliveryBucket,
                                    final BigDecimal salePrice,
                                    final BigDecimal listPrice); @Override boolean setGiftPrice(final String supplier,
                                final String skuCode,
                                final BigDecimal salePrice,
                                final BigDecimal listPrice); @Override boolean setProductSkuPromotion(final String supplier,
                                          final String skuCode,
                                          final BigDecimal promoPrice,
                                          final String promoCode); @Override boolean setProductSkuOffer(final String supplier,
                                      final String skuCode,
                                      final BigDecimal fixedPrice,
                                      final String authCode); @Override boolean setShippingPromotion(final String carrierSlaGUID,
                                        final DeliveryBucket deliveryBucket,
                                        final BigDecimal promoPrice,
                                        final String promoCode); @Override boolean setProductSkuTax(final String supplier,
                                    final String skuCode,
                                    final BigDecimal netPrice,
                                    final BigDecimal grossPrice,
                                    final BigDecimal rate,
                                    final String taxCode,
                                    final boolean exclPrice); @Override boolean setShippingTax(final String carrierSlaGUID, final DeliveryBucket deliveryBucket, final BigDecimal netPrice, final BigDecimal grossPrice, final BigDecimal rate, final String taxCode, final boolean exclPrice); @Override List<String> getCoupons(); @Override @JsonIgnore List<String> getAppliedCoupons(); @Override boolean addCoupon(final String coupon); @Override boolean removeCoupon(final String coupon); @Override @JsonIgnore int getCartItemsCount(); @Override @JsonIgnore List<String> getCartItemsSuppliers(); @Override String getCurrencyCode(); @Override void setCurrencyCode(final String currencyCode); @Override @JsonIgnore String getCustomerName(); @Override long getModifiedTimestamp(); @Override @JsonIgnore boolean isModified(); @Override @JsonIgnore boolean hasGifts(); @Override @JsonIgnore boolean isPromotionsDisabled(); @Override void setPromotionsDisabled(final boolean promotionsDisabled); @Override @JsonIgnore String getOrdernum(); @Override void setOrdernum(final String ordernum); @Override @JsonIgnore String getCustomerEmail(); @Override @JsonIgnore int getLogonState(); @Override MutableShoppingContext getShoppingContext(); @Override String getCurrentLocale(); @Override void setCurrentLocale(final String currentLocale); @Override MutableOrderInfo getOrderInfo(); @Override long getProcessingStartTimestamp(); @Override Total getTotal();  }
@Test public void testSetProductSkuPrice() throws Exception { cart.addProductSkuToCart("s01", "ABC", "SKU name", BigDecimal.ONE, null, false, false); final CartItem noPrice = cart.getCartItemList().get(0); assertEquals(BigDecimal.ZERO, noPrice.getListPrice()); assertEquals(BigDecimal.ZERO, noPrice.getSalePrice()); assertEquals(BigDecimal.ZERO, noPrice.getPrice()); assertFalse(noPrice.isPromoApplied()); assertFalse(noPrice.isFixedPrice()); assertNull(noPrice.getAppliedPromo()); cart.setProductSkuPrice("s01", "ABC", new BigDecimal("9.99"), new BigDecimal("10.99")); final CartItem hasPrice = cart.getCartItemList().get(0); assertEquals(new BigDecimal("10.99"), hasPrice.getListPrice()); assertEquals(new BigDecimal("9.99"), hasPrice.getSalePrice()); assertEquals(new BigDecimal("9.99"), hasPrice.getPrice()); assertFalse(hasPrice.isPromoApplied()); assertFalse(hasPrice.isFixedPrice()); assertNull(hasPrice.getAppliedPromo()); cart.setProductSkuPromotion("s01", "ABC", new BigDecimal("4.99"), "50OFF"); final CartItem promoPrice = cart.getCartItemList().get(0); assertEquals(new BigDecimal("10.99"), promoPrice.getListPrice()); assertEquals(new BigDecimal("9.99"), promoPrice.getSalePrice()); assertEquals(new BigDecimal("4.99"), promoPrice.getPrice()); assertTrue(promoPrice.isPromoApplied()); assertFalse(promoPrice.isFixedPrice()); assertEquals("50OFF", promoPrice.getAppliedPromo()); cart.setProductSkuPrice("s01", "ABC", new BigDecimal("9.99"), new BigDecimal("10.99")); final CartItem promoPriceAfterReset = cart.getCartItemList().get(0); assertEquals(new BigDecimal("10.99"), promoPriceAfterReset.getListPrice()); assertEquals(new BigDecimal("9.99"), promoPriceAfterReset.getSalePrice()); assertEquals(new BigDecimal("9.99"), promoPriceAfterReset.getPrice()); assertFalse(promoPriceAfterReset.isPromoApplied()); assertFalse(promoPriceAfterReset.isFixedPrice()); assertNull(promoPriceAfterReset.getAppliedPromo()); cart.setProductSkuOffer("s01", "ABC", new BigDecimal("8.99"), "AUTH001"); final CartItem offerPrice = cart.getCartItemList().get(0); assertEquals(new BigDecimal("10.99"), offerPrice.getListPrice()); assertEquals(new BigDecimal("9.99"), offerPrice.getSalePrice()); assertEquals(new BigDecimal("8.99"), offerPrice.getPrice()); assertFalse(offerPrice.isPromoApplied()); assertTrue(offerPrice.isFixedPrice()); assertEquals("AUTH001", offerPrice.getAppliedPromo()); cart.setProductSkuPrice("s01", "ABC", new BigDecimal("11.99"), new BigDecimal("12.99")); final CartItem offerPriceAfterResetHigher = cart.getCartItemList().get(0); assertEquals(new BigDecimal("12.99"), offerPriceAfterResetHigher.getListPrice()); assertEquals(new BigDecimal("11.99"), offerPriceAfterResetHigher.getSalePrice()); assertEquals(new BigDecimal("8.99"), offerPriceAfterResetHigher.getPrice()); assertFalse(offerPriceAfterResetHigher.isPromoApplied()); assertTrue(offerPriceAfterResetHigher.isFixedPrice()); assertEquals("AUTH001", offerPriceAfterResetHigher.getAppliedPromo()); cart.setProductSkuPrice("s01", "ABC", new BigDecimal("4.99"), new BigDecimal("5.99")); final CartItem offerPriceAfterResetLower = cart.getCartItemList().get(0); assertEquals(new BigDecimal("8.99"), offerPriceAfterResetLower.getListPrice()); assertEquals(new BigDecimal("8.99"), offerPriceAfterResetLower.getSalePrice()); assertEquals(new BigDecimal("8.99"), offerPriceAfterResetLower.getPrice()); assertFalse(offerPriceAfterResetLower.isPromoApplied()); assertTrue(offerPriceAfterResetLower.isFixedPrice()); assertEquals("AUTH001", offerPriceAfterResetLower.getAppliedPromo()); }