Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 public static Call getProductUrl(Product product, Variant variant, Category category) {
   return routes.Products.select(product.getSlug(), String.valueOf(variant.getId()));
 }