コード例 #1
0
  /**
   * @param p
   * @return details
   */
  public static ProductDetails valueOf(Product p) {
    ProductDetails pd = new ProductDetails();

    pd.setId(p.getId());
    pd.setBrand(p.getBrand());
    pd.setName(p.getName());

    pd.setImageUrl(findProductImage(p));

    pd.setUrl(p.getUrl());

    setSkuLevelStuff(p, pd);

    return pd;
  }
コード例 #2
0
  /**
   * @param other
   * @return evaluation
   */
  @Override
  public int compareTo(ProductDetails other) {

    if (other == null) {
      return -1;
    }

    //		if(!this.soldOut && other.isSoldOut())
    //		{
    //		    return Boolean.valueOf(this.isSoldOut()).compareTo(other.isSoldOut());
    //		}

    Double minPrice = Double.parseDouble(this.minPrice);
    Double otherMinPrice = Double.parseDouble(other.getMinPrice());

    return minPrice.compareTo(otherMinPrice);
    //		if(diff != 0){
    //			return diff;
    //		}
    //
    //		return this.brand.compareTo(other.getBrand());
  }
コード例 #3
0
  private static void setSkuLevelStuff(Product p, ProductDetails pd) {
    boolean isSoldOut = true;
    List<String> colors = new ArrayList<String>();
    List<String> sizes = new ArrayList<String>();

    for (Sku sku : p.getSkus()) {
      try {
        NumberFormat format = NumberFormat.getInstance();
        Number skuPrice = NumberFormat.getInstance().parse(sku.getSalePrice());

        // minimum price logic
        if (pd.getMinPrice() != null) {
          Number minPrice = format.parse(pd.getMinPrice());

          if (skuPrice.doubleValue() < minPrice.doubleValue()) {
            pd.setMinPrice(sku.getSalePrice());
          }
        } else {
          pd.setMinPrice(sku.getSalePrice());
        }

        // maximum price logic
        if (pd.getMaxPrice() != null) {
          Number maxPrice = format.parse(pd.getMaxPrice());

          if (skuPrice.doubleValue() > maxPrice.doubleValue()) {
            pd.setMaxPrice(sku.getSalePrice());
          }
        } else {
          pd.setMaxPrice(sku.getSalePrice());
        }
      } catch (ParseException e) {
        e.printStackTrace(System.err);
      }

      if ("for sale".equalsIgnoreCase(sku.getInventoryStatus())) {
        isSoldOut = false;

        String color = getAttribute(sku.getAttributes(), "color");
        if (color != null) {
          colors.add(color);
        }
        String size = getAttribute(sku.getAttributes(), "size");
        if (size != null) {
          sizes.add(size);
        }
      }
      if ("reserved".equalsIgnoreCase(sku.getInventoryStatus())) {
        isSoldOut = false;
      }
    }

    pd.setSoldOut(isSoldOut);
    pd.setSizes(sizes);
    pd.setColors(colors);
  }