CommerceUtils { public static boolean hasVariedPrices(JsonNode item) { ProductType type = getProductType(item); JsonNode structuredContent = item.path("structuredContent"); switch (type) { case PHYSICAL: case SERVICE: case GIFT_CARD: JsonNode variants = structuredContent.path("variants"); JsonNode first = variants.get(0); for (int i = 1; i < variants.size(); i++) { JsonNode var = variants.get(i); boolean flag1 = !var.path("onSale").equals(first.path("onSale")); boolean flag2 = isTruthy(first.path("onSale")) && !var.path("salePrice").equals(first.path("salePrice")); boolean flag3 = !var.path("price").equals(first.path("price")); if (flag1 || flag2 || flag3) { return true; } } return false; case DIGITAL: default: return false; } } private  CommerceUtils(); static boolean useCLDRMode(Context ctx); static ProductType getProductType(JsonNode item); static boolean isSubscribable(JsonNode item); static JsonNode getSubscriptionPlanBillingPeriodNode(JsonNode item); static String getUnitFromSubscriptionPlanBillingPeriod(JsonNode billingPeriodNode); static int getValueFromSubscriptionPlanBillingPeriod(JsonNode billingPeriodNode); static int getNumBillingCyclesFromSubscriptionPlanNode(JsonNode item); static JsonNode getLowestPriceAmongVariants(JsonNode item); static JsonNode getHighestPriceAmongVariants(JsonNode item); static JsonNode getSalePriceMoneyNode(JsonNode item); static Decimal getAmountFromMoneyNode(JsonNode moneyNode); static String getCurrencyFromMoneyNode(JsonNode moneyNode); static Decimal getLegacyPriceFromMoneyNode(JsonNode moneyNode); static double getTotalStockRemaining(JsonNode item); static boolean hasVariedPrices(JsonNode item); static boolean hasVariants(JsonNode item); static boolean isOnSale(JsonNode item); static boolean isSoldOut(JsonNode item); static void writeLegacyMoneyString(Decimal value, StringBuilder buf); static void writeVariantFormat(JsonNode variant, StringBuilder buf); static ArrayNode getItemVariantOptions(JsonNode item); static boolean isMultipleQuantityAllowedForServices(JsonNode websiteSettings);  }
@Test public void testHasVariedPrices() { Map<String, JsonNode> jsonMap = loadJson(getClass(), "has-varied-prices.json"); for (Map.Entry<String, JsonNode> entry : jsonMap.entrySet()) { String key = entry.getKey(); if (key.endsWith("-true")) { assertTrue(hasVariedPrices(entry.getValue()), key); } else { assertFalse(hasVariedPrices(entry.getValue()), key); } } }