CommerceUtils { public static boolean hasVariants(JsonNode item) { JsonNode structuredContent = item.path("structuredContent"); JsonNode variants = structuredContent.path("variants"); ProductType type = getProductType(item); return type.equals(ProductType.DIGITAL) ? false : variants.size() > 1; } 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 testHasVariants() { Map<String, JsonNode> jsonMap = loadJson(getClass(), "has-variants.json"); for (Map.Entry<String, JsonNode> entry : jsonMap.entrySet()) { String key = entry.getKey(); if (key.endsWith("-true")) { assertTrue(hasVariants(entry.getValue()), key); } else { assertFalse(hasVariants(entry.getValue()), key); } } }