PriceServiceImpl extends BaseGenericServiceImpl<SkuPrice> implements PriceService { @Override public List<SkuPrice> getAllCurrentPrices(final Long productId, final String selectedSku, final long customerShopId, final Long masterShopId, final String currencyCode, final String pricingPolicy, final String supplier) { final List<Pair<String, SkuPrice>> skuPrices; if (selectedSku == null && productId != null) { skuPrices = getSkuPrices(productId, customerShopId, masterShopId, currencyCode, pricingPolicy, supplier); } else if (selectedSku != null) { skuPrices = getSkuPrices(selectedSku, customerShopId, masterShopId, currencyCode, pricingPolicy, supplier); } else { skuPrices = Collections.emptyList(); } final List<Pair<String, SkuPrice>> filtered = getSkuPricesFilteredByTimeFrame(skuPrices); final List<SkuPrice> prices = new ArrayList<>(); for (final Pair<String, SkuPrice> price : filtered) { prices.add(price.getSecond()); } prices.sort(SORT_PRICE_BY_QUANTITY); final Iterator<SkuPrice> pricesIt = prices.iterator(); BigDecimal tier = null; while (pricesIt.hasNext()) { final SkuPrice price = pricesIt.next(); if (tier == null || !MoneyUtils.isFirstEqualToSecond(price.getQuantity(), tier)) { tier = price.getQuantity(); } else { pricesIt.remove(); } } return prices; } PriceServiceImpl(final GenericDAO<SkuPrice, Long> skuPriceDao); @Override SkuPrice getMinimalPrice(final Long productId,
                                    final String selectedSku,
                                    final long customerShopId,
                                    final Long masterShopId,
                                    final String currencyCode,
                                    final BigDecimal quantity,
                                    final boolean enforceTier,
                                    final String pricingPolicy,
                                    final String supplier); @Override List<SkuPrice> getAllCurrentPrices(final Long productId,
                                              final String selectedSku,
                                              final long customerShopId,
                                              final Long masterShopId,
                                              final String currencyCode,
                                              final String pricingPolicy,
                                              final String supplier); @Override List<SkuPrice> getAllPrices(final Long productId, final String selectedSku, final String currencyCode); @Override SkuPrice create(final SkuPrice instance); @Override SkuPrice update(final SkuPrice instance); @Override List<SkuPrice> findPrices(final int start, final int offset, final String sort, final boolean sortDescending, final Map<String, List> filter); @Override int findPriceCount(final Map<String, List> filter);  }
@Test public void testGetAllCurrentProductPrices() throws Exception { Shop shop = shopService.getShopByDomainName("www.gadget.yescart.org"); List<SkuPrice> skuPrice = priceService.getAllCurrentPrices(10000L, null, shop.getShopId(), null, "EUR", null, null); assertNotNull(skuPrice); assertEquals(3, skuPrice.size()); assertNotNull(skuPrice.get(0).getSalePriceForCalculation()); assertNull(skuPrice.get(0).getPricingPolicy()); assertNull(skuPrice.get(0).getSupplier()); assertNull(skuPrice.get(0).getTag()); assertValue("1", skuPrice.get(0).getQuantity()); assertEquals("SOBOT-PINK", skuPrice.get(0).getSkuCode()); assertValue("150.85", skuPrice.get(0).getRegularPrice()); assertValue("140.11", skuPrice.get(0).getSalePrice()); assertNotNull(skuPrice.get(1).getSalePriceForCalculation()); assertNull(skuPrice.get(1).getPricingPolicy()); assertNull(skuPrice.get(1).getSupplier()); assertNull(skuPrice.get(1).getTag()); assertValue("2", skuPrice.get(1).getQuantity()); assertEquals("SOBOT-LIGHT", skuPrice.get(1).getSkuCode()); assertValue("150.85", skuPrice.get(1).getRegularPrice()); assertValue("130.11", skuPrice.get(1).getSalePrice()); assertNotNull(skuPrice.get(2).getSalePriceForCalculation()); assertNull(skuPrice.get(2).getPricingPolicy()); assertNull(skuPrice.get(2).getSupplier()); assertNull(skuPrice.get(2).getTag()); assertValue("3", skuPrice.get(2).getQuantity()); assertEquals("SOBOT-LIGHT", skuPrice.get(2).getSkuCode()); assertValue("150.85", skuPrice.get(2).getRegularPrice()); assertValue("100.11", skuPrice.get(2).getSalePrice()); skuPrice = priceService.getAllCurrentPrices(10000L, null, shop.getShopId(), null, "EUR", "P1", null); assertNotNull(skuPrice); assertEquals(3, skuPrice.size()); assertNotNull(skuPrice.get(0).getSalePriceForCalculation()); assertEquals("P1", skuPrice.get(0).getPricingPolicy()); assertNull(skuPrice.get(0).getSupplier()); assertNull(skuPrice.get(0).getTag()); assertValue("1", skuPrice.get(0).getQuantity()); assertEquals("SOBOT-ORIG", skuPrice.get(0).getSkuCode()); assertValue("150.85", skuPrice.get(0).getRegularPrice()); assertValue("120.22", skuPrice.get(0).getSalePrice()); assertNotNull(skuPrice.get(1).getSalePriceForCalculation()); assertEquals("P1", skuPrice.get(1).getPricingPolicy()); assertNull(skuPrice.get(1).getSupplier()); assertNull(skuPrice.get(1).getTag()); assertValue("2", skuPrice.get(1).getQuantity()); assertEquals("SOBOT-LIGHT", skuPrice.get(1).getSkuCode()); assertValue("150.85", skuPrice.get(1).getRegularPrice()); assertValue("115.22", skuPrice.get(1).getSalePrice()); assertNotNull(skuPrice.get(2).getSalePriceForCalculation()); assertNull(skuPrice.get(2).getPricingPolicy()); assertNull(skuPrice.get(2).getSupplier()); assertNull(skuPrice.get(2).getTag()); assertEquals("SOBOT-LIGHT", skuPrice.get(2).getSkuCode()); assertValue("150.85", skuPrice.get(2).getRegularPrice()); assertValue("100.11", skuPrice.get(2).getSalePrice()); skuPrice = priceService.getAllCurrentPrices(10000L, null, shop.getShopId(), null, "EUR", null, "TEST"); assertNotNull(skuPrice); assertEquals(3, skuPrice.size()); assertNotNull(skuPrice.get(0).getSalePriceForCalculation()); assertValue("1", skuPrice.get(0).getQuantity()); assertNull(skuPrice.get(0).getPricingPolicy()); assertEquals("TEST", skuPrice.get(0).getSupplier()); assertEquals("sup", skuPrice.get(0).getTag()); assertEquals("SOBOT-PINK", skuPrice.get(0).getSkuCode()); assertValue("140.85", skuPrice.get(0).getRegularPrice()); assertValue("110.11", skuPrice.get(0).getSalePrice()); assertNotNull(skuPrice.get(1).getSalePriceForCalculation()); assertValue("2", skuPrice.get(1).getQuantity()); assertNull(skuPrice.get(1).getPricingPolicy()); assertEquals("TEST", skuPrice.get(1).getSupplier()); assertEquals("sup", skuPrice.get(1).getTag()); assertEquals("SOBOT-LIGHT", skuPrice.get(1).getSkuCode()); assertValue("140.85", skuPrice.get(1).getRegularPrice()); assertValue("105.22", skuPrice.get(1).getSalePrice()); assertNotNull(skuPrice.get(2).getSalePriceForCalculation()); assertValue("3", skuPrice.get(2).getQuantity()); assertNull(skuPrice.get(2).getPricingPolicy()); assertNull(skuPrice.get(2).getSupplier()); assertNull(skuPrice.get(2).getTag()); assertEquals("SOBOT-LIGHT", skuPrice.get(2).getSkuCode()); assertValue("150.85", skuPrice.get(2).getRegularPrice()); assertValue("100.11", skuPrice.get(2).getSalePrice()); skuPrice = priceService.getAllCurrentPrices(10000L, null, shop.getShopId(), null, "EUR", "P1", "TEST"); assertNotNull(skuPrice); assertEquals(3, skuPrice.size()); assertNotNull(skuPrice.get(0).getSalePriceForCalculation()); assertValue("1", skuPrice.get(0).getQuantity()); assertEquals("P1", skuPrice.get(0).getPricingPolicy()); assertEquals("TEST", skuPrice.get(0).getSupplier()); assertEquals("sup", skuPrice.get(0).getTag()); assertEquals("SOBOT-PINK", skuPrice.get(0).getSkuCode()); assertValue("140.85", skuPrice.get(0).getRegularPrice()); assertValue("100.11", skuPrice.get(0).getSalePrice()); assertNotNull(skuPrice.get(1).getSalePriceForCalculation()); assertValue("2", skuPrice.get(1).getQuantity()); assertEquals("P1", skuPrice.get(1).getPricingPolicy()); assertEquals("TEST", skuPrice.get(1).getSupplier()); assertEquals("sup", skuPrice.get(1).getTag()); assertEquals("SOBOT-LIGHT", skuPrice.get(1).getSkuCode()); assertValue("140.85", skuPrice.get(1).getRegularPrice()); assertValue("95.22", skuPrice.get(1).getSalePrice()); assertNotNull(skuPrice.get(2).getSalePriceForCalculation()); assertValue("3", skuPrice.get(2).getQuantity()); assertNull(skuPrice.get(2).getPricingPolicy()); assertNull(skuPrice.get(2).getSupplier()); assertNull(skuPrice.get(2).getTag()); assertEquals("SOBOT-LIGHT", skuPrice.get(2).getSkuCode()); assertValue("150.85", skuPrice.get(2).getRegularPrice()); assertValue("100.11", skuPrice.get(2).getSalePrice()); }
@Test public void testGetAllCurrentSKUPrices() throws Exception { Shop shop = shopService.getShopByDomainName("www.gadget.yescart.org"); List<SkuPrice> skuPrice = priceService.getAllCurrentPrices(10000L, "SOBOT-LIGHT", shop.getShopId(), null, "EUR", null, null); assertNotNull(skuPrice); assertEquals(3, skuPrice.size()); assertNotNull(skuPrice.get(0).getSalePriceForCalculation()); assertNull(skuPrice.get(0).getPricingPolicy()); assertNull(skuPrice.get(0).getSupplier()); assertNull(skuPrice.get(0).getTag()); assertValue("1", skuPrice.get(0).getQuantity()); assertEquals("SOBOT-LIGHT", skuPrice.get(0).getSkuCode()); assertValue("150.0", skuPrice.get(0).getRegularPrice()); assertValue(null, skuPrice.get(0).getSalePrice()); assertNotNull(skuPrice.get(1).getSalePriceForCalculation()); assertNull(skuPrice.get(1).getPricingPolicy()); assertNull(skuPrice.get(1).getSupplier()); assertNull(skuPrice.get(1).getTag()); assertValue("2", skuPrice.get(1).getQuantity()); assertEquals("SOBOT-LIGHT", skuPrice.get(1).getSkuCode()); assertValue("150.85", skuPrice.get(1).getRegularPrice()); assertValue("130.11", skuPrice.get(1).getSalePrice()); assertNotNull(skuPrice.get(2).getSalePriceForCalculation()); assertNull(skuPrice.get(2).getPricingPolicy()); assertNull(skuPrice.get(2).getSupplier()); assertNull(skuPrice.get(2).getTag()); assertValue("3", skuPrice.get(2).getQuantity()); assertEquals("SOBOT-LIGHT", skuPrice.get(2).getSkuCode()); assertValue("150.85", skuPrice.get(2).getRegularPrice()); assertValue("100.11", skuPrice.get(2).getSalePrice()); skuPrice = priceService.getAllCurrentPrices(10000L, "SOBOT-LIGHT", shop.getShopId(), null, "EUR", "P1", null); assertNotNull(skuPrice); assertEquals(3, skuPrice.size()); assertNotNull(skuPrice.get(0).getSalePriceForCalculation()); assertEquals("P1", skuPrice.get(0).getPricingPolicy()); assertNull(skuPrice.get(0).getSupplier()); assertNull(skuPrice.get(0).getTag()); assertValue("1", skuPrice.get(0).getQuantity()); assertEquals("SOBOT-LIGHT", skuPrice.get(0).getSkuCode()); assertValue("140.00", skuPrice.get(0).getRegularPrice()); assertValue(null, skuPrice.get(0).getSalePrice()); assertNotNull(skuPrice.get(1).getSalePriceForCalculation()); assertEquals("P1", skuPrice.get(1).getPricingPolicy()); assertNull(skuPrice.get(1).getSupplier()); assertNull(skuPrice.get(1).getTag()); assertValue("2", skuPrice.get(1).getQuantity()); assertEquals("SOBOT-LIGHT", skuPrice.get(1).getSkuCode()); assertValue("150.85", skuPrice.get(1).getRegularPrice()); assertValue("115.22", skuPrice.get(1).getSalePrice()); assertNotNull(skuPrice.get(2).getSalePriceForCalculation()); assertNull(skuPrice.get(2).getPricingPolicy()); assertNull(skuPrice.get(2).getSupplier()); assertNull(skuPrice.get(2).getTag()); assertEquals("SOBOT-LIGHT", skuPrice.get(2).getSkuCode()); assertValue("150.85", skuPrice.get(2).getRegularPrice()); assertValue("100.11", skuPrice.get(2).getSalePrice()); skuPrice = priceService.getAllCurrentPrices(10000L, "SOBOT-LIGHT", shop.getShopId(), null, "EUR", null, "TEST"); assertNotNull(skuPrice); assertEquals(3, skuPrice.size()); assertNotNull(skuPrice.get(0).getSalePriceForCalculation()); assertValue("1", skuPrice.get(0).getQuantity()); assertNull(skuPrice.get(0).getPricingPolicy()); assertNull(skuPrice.get(0).getSupplier()); assertNull(skuPrice.get(0).getTag()); assertEquals("SOBOT-LIGHT", skuPrice.get(0).getSkuCode()); assertValue("150.0", skuPrice.get(0).getRegularPrice()); assertValue(null, skuPrice.get(0).getSalePrice()); assertNotNull(skuPrice.get(1).getSalePriceForCalculation()); assertValue("2", skuPrice.get(1).getQuantity()); assertNull(skuPrice.get(1).getPricingPolicy()); assertEquals("TEST", skuPrice.get(1).getSupplier()); assertEquals("sup", skuPrice.get(1).getTag()); assertEquals("SOBOT-LIGHT", skuPrice.get(1).getSkuCode()); assertValue("140.85", skuPrice.get(1).getRegularPrice()); assertValue("105.22", skuPrice.get(1).getSalePrice()); assertNotNull(skuPrice.get(2).getSalePriceForCalculation()); assertValue("3", skuPrice.get(2).getQuantity()); assertNull(skuPrice.get(2).getPricingPolicy()); assertNull(skuPrice.get(2).getSupplier()); assertNull(skuPrice.get(2).getTag()); assertEquals("SOBOT-LIGHT", skuPrice.get(2).getSkuCode()); assertValue("150.85", skuPrice.get(2).getRegularPrice()); assertValue("100.11", skuPrice.get(2).getSalePrice()); skuPrice = priceService.getAllCurrentPrices(10000L, "SOBOT-LIGHT", shop.getShopId(), null, "EUR", "P1", "TEST"); assertNotNull(skuPrice); assertEquals(3, skuPrice.size()); assertNotNull(skuPrice.get(0).getSalePriceForCalculation()); assertValue("1", skuPrice.get(0).getQuantity()); assertEquals("P1", skuPrice.get(0).getPricingPolicy()); assertNull(skuPrice.get(0).getSupplier()); assertNull(skuPrice.get(0).getTag()); assertEquals("SOBOT-LIGHT", skuPrice.get(0).getSkuCode()); assertValue("140.0", skuPrice.get(0).getRegularPrice()); assertValue(null, skuPrice.get(0).getSalePrice()); assertNotNull(skuPrice.get(1).getSalePriceForCalculation()); assertValue("2", skuPrice.get(1).getQuantity()); assertEquals("P1", skuPrice.get(1).getPricingPolicy()); assertEquals("TEST", skuPrice.get(1).getSupplier()); assertEquals("sup", skuPrice.get(1).getTag()); assertEquals("SOBOT-LIGHT", skuPrice.get(1).getSkuCode()); assertValue("140.85", skuPrice.get(1).getRegularPrice()); assertValue("95.22", skuPrice.get(1).getSalePrice()); assertNotNull(skuPrice.get(2).getSalePriceForCalculation()); assertValue("3", skuPrice.get(2).getQuantity()); assertNull(skuPrice.get(2).getPricingPolicy()); assertNull(skuPrice.get(2).getSupplier()); assertNull(skuPrice.get(2).getTag()); assertEquals("SOBOT-LIGHT", skuPrice.get(2).getSkuCode()); assertValue("150.85", skuPrice.get(2).getRegularPrice()); assertValue("100.11", skuPrice.get(2).getSalePrice()); }