public static List<String> getPossibleSizes(Product product, Variant variant) { List<Variant> variants = getPossibleVariants(product, variant, "size"); List<String> sizes = new ArrayList<String>(); for (Variant matchedVariant : variants) { sizes.add(matchedVariant.getString("size")); } return sizes; }
public static List<Variant> getPossibleVariants( Product product, Variant variant, String selectedAttribute) { List<Variant> matchingVariantList = new ArrayList<Variant>(); List<Attribute> desiredAttributes = new ArrayList<Attribute>(); for (Attribute attribute : variant.getAttributes()) { if (!selectedAttribute.equals(attribute.getName()) && hasMoreAttributeValues(product, attribute.getName())) { desiredAttributes.add(attribute); } } VariantList variantList = product.getVariants().byAttributes(desiredAttributes); for (Attribute attr : product.getVariants().getAvailableAttributes(selectedAttribute)) { if (variantList.byAttributes(attr).size() < 1) { matchingVariantList.add((product.getVariants().byAttributes(attr).first()).orNull()); } else { matchingVariantList.add((variantList.byAttributes(attr).first()).orNull()); } } matchingVariantList.removeAll(Collections.singleton(null)); return matchingVariantList; }
public static Call getProductUrl(Product product, Variant variant, Category category) { return routes.Products.select(product.getSlug(), String.valueOf(variant.getId())); }