@Override
  public void populate(
      final VariantValueCategoryModel variantValueCategory,
      final VariantMatrixElementData variantMatrixElementData)
      throws ConversionException {
    final VariantCategoryData parent = new VariantCategoryData();

    final VariantCategoryModel variantCategoryModel =
        (VariantCategoryModel) variantValueCategory.getSupercategories().get(0);
    parent.setName(variantCategoryModel.getName());
    parent.setHasImage(variantCategoryModel.getHasImage());

    final VariantValueCategoryData data = new VariantValueCategoryData();
    data.setName(variantValueCategory.getName());
    data.setSequence(variantValueCategory.getSequence());

    variantMatrixElementData.setVariantValueCategory(data);
    variantMatrixElementData.setParentVariantCategory(parent);

    final VariantOptionData variantOptionData = new VariantOptionData();
    final VariantOptionQualifierData variantOptionQualifierData = new VariantOptionQualifierData();
    variantOptionQualifierData.setImage(new ImageData());
    variantOptionData.setVariantOptionQualifiers(
        Arrays.asList(new VariantOptionQualifierData[] {variantOptionQualifierData}));

    variantMatrixElementData.setVariantOption(variantOptionData);
  }
Ejemplo n.º 2
0
  /**
   * JSP EL Function to get an image for a Product in a specific format based on the product code.
   *
   * @param product The product.
   * @param productCode The desired product code.
   * @param format The desired format.
   * @return The image.
   */
  public static ImageData getImageForProductCode(
      final ProductData product, final String productCode, final String format) {
    if (product != null && productCode != null && format != null) {

      int selectedIndex = 0;

      for (int i = 1; i <= product.getCategories().size(); i++) {
        int j = 0;
        final List<VariantMatrixElementData> theMatrix;

        if (i == 1) {
          theMatrix = product.getVariantMatrix();
        } else {
          theMatrix = product.getVariantMatrix().get(selectedIndex).getElements();
          selectedIndex = 0;
        }

        if (theMatrix.get(selectedIndex).getParentVariantCategory().getHasImage()) {
          for (final VariantMatrixElementData matrixElementData : theMatrix) {
            if (matrixElementData.getVariantOption().getVariantOptionQualifiers() != null
                && productCode.equals(matrixElementData.getVariantOption().getCode())) {
              for (final VariantOptionQualifierData variantOption :
                  matrixElementData.getVariantOption().getVariantOptionQualifiers()) {
                if (format.equals(variantOption.getImage().getFormat())) {
                  return variantOption.getImage();
                }
              }
              selectedIndex = j;
            }

            j++;
          }
        }
      }
    }
    return null;
  }