@Test public void testGetVariantAttributes() { productModel = context.request().adaptTo(ProductImpl.class); List<VariantAttribute> attributes = productModel.getVariantAttributes(); Assert.assertNotNull(attributes); ConfigurableProduct cp = (ConfigurableProduct) product; Assert.assertEquals(cp.getConfigurableOptions().size(), attributes.size()); for (int i = 0; i < attributes.size(); i++) { VariantAttribute attribute = attributes.get(i); ConfigurableProductOptions option = cp.getConfigurableOptions().get(i); Assert.assertEquals(option.getAttributeCode(), attribute.getId()); Assert.assertEquals(option.getLabel(), attribute.getLabel()); for (int j = 0; j < attribute.getValues().size(); j++) { VariantValue value = attribute.getValues().get(j); ConfigurableProductOptionsValues optionValue = option.getValues().get(j); Assert.assertEquals(optionValue.getValueIndex(), value.getId()); Assert.assertEquals(optionValue.getLabel(), value.getLabel()); } } }
@Override public List<VariantAttribute> getVariantAttributes() { if (!isConfigurable()) { return Collections.emptyList(); } ConfigurableProduct product = (ConfigurableProduct) productRetriever.fetchProduct(); List<VariantAttribute> optionList = new ArrayList<>(); for (ConfigurableProductOptions option : product.getConfigurableOptions()) { optionList.add(mapVariantAttribute(option)); } return optionList; }
ProductImpl implements Product { @Override public List<VariantAttribute> getVariantAttributes() { if (!isConfigurable()) { return Collections.emptyList(); } ConfigurableProduct product = (ConfigurableProduct) productRetriever.fetchProduct(); List<VariantAttribute> optionList = new ArrayList<>(); for (ConfigurableProductOptions option : product.getConfigurableOptions()) { optionList.add(mapVariantAttribute(option)); } return optionList; } }
ProductImpl implements Product { @Override public List<VariantAttribute> getVariantAttributes() { if (!isConfigurable()) { return Collections.emptyList(); } ConfigurableProduct product = (ConfigurableProduct) productRetriever.fetchProduct(); List<VariantAttribute> optionList = new ArrayList<>(); for (ConfigurableProductOptions option : product.getConfigurableOptions()) { optionList.add(mapVariantAttribute(option)); } return optionList; }  }
ProductImpl implements Product { @Override public List<VariantAttribute> getVariantAttributes() { if (!isConfigurable()) { return Collections.emptyList(); } ConfigurableProduct product = (ConfigurableProduct) productRetriever.fetchProduct(); List<VariantAttribute> optionList = new ArrayList<>(); for (ConfigurableProductOptions option : product.getConfigurableOptions()) { optionList.add(mapVariantAttribute(option)); } return optionList; }  @Override Boolean getFound(); @Override String getName(); @Override String getDescription(); @Override String getSku(); @Override String getCurrency(); @Override Double getPrice(); @Override Price getPriceRange(); @Override Boolean getInStock(); @Override Boolean isConfigurable(); @Override Boolean isGroupedProduct(); @Override Boolean isVirtualProduct(); @Override Boolean isBundleProduct(); @Override String getVariantsJson(); @Override List<Variant> getVariants(); @Override List<GroupItem> getGroupedProductItems(); @Override List<Asset> getAssets(); @Override String getAssetsJson(); @Override List<VariantAttribute> getVariantAttributes(); @Override Boolean loadClientPrice(); @Override String getFormattedPrice(); @Override AbstractProductRetriever getProductRetriever(); }
ProductImpl implements Product { @Override public List<VariantAttribute> getVariantAttributes() { if (!isConfigurable()) { return Collections.emptyList(); } ConfigurableProduct product = (ConfigurableProduct) productRetriever.fetchProduct(); List<VariantAttribute> optionList = new ArrayList<>(); for (ConfigurableProductOptions option : product.getConfigurableOptions()) { optionList.add(mapVariantAttribute(option)); } return optionList; }  @Override Boolean getFound(); @Override String getName(); @Override String getDescription(); @Override String getSku(); @Override String getCurrency(); @Override Double getPrice(); @Override Price getPriceRange(); @Override Boolean getInStock(); @Override Boolean isConfigurable(); @Override Boolean isGroupedProduct(); @Override Boolean isVirtualProduct(); @Override Boolean isBundleProduct(); @Override String getVariantsJson(); @Override List<Variant> getVariants(); @Override List<GroupItem> getGroupedProductItems(); @Override List<Asset> getAssets(); @Override String getAssetsJson(); @Override List<VariantAttribute> getVariantAttributes(); @Override Boolean loadClientPrice(); @Override String getFormattedPrice(); @Override AbstractProductRetriever getProductRetriever();  }