I have extended the default product type to also have a videos attribute that is identical to the identical to the images attribute, except for the name:
<itemtype code="Product" extends="GenericItem" autocreate="false" generate="false">
<description>Extend the product type to also hold links to videos.</description>
<attributes>
<attribute qualifier="videos" type="MediaContainerList">
<description>List of videos for a given product</description>
<modifiers/>
<persistence type="property"/>
</attribute>
</attributes>
</itemtype>
I am now trying to copy the ProductPrimaryImagePopulator to set the videos in the Data object, but I am missing something obvious. Here is the code and the error:
import de.hybris.platform.commercefacades.product.data.ImageData;
import de.hybris.platform.commercefacades.product.data.ImageDataType;
import de.hybris.platform.commercefacades.product.data.ProductData;
import de.hybris.platform.core.model.media.MediaContainerModel;
import de.hybris.platform.core.model.media.MediaModel;
import de.hybris.platform.core.model.product.ProductModel;
import de.hybris.platform.servicelayer.dto.converter.ConversionException;
import java.util.ArrayList;
import java.util.List;
public class ProductVideoPopulator<SOURCE extends ProductModel, TARGET extends ProductData>
extends AbstractProductImagePopulator<SOURCE, TARGET> {
@Override
public void populate(final SOURCE productModel, final TARGET productData) throws ConversionException {
final MediaContainerModel primaryImageMediaContainer = getPrimaryImageMediaContainer(productModel);
if (primaryImageMediaContainer != null) {
final List<ImageData> imageList = new ArrayList<ImageData>();
// Use the first container as the primary image
addImagesInFormats(primaryImageMediaContainer, ImageDataType.PRIMARY, 0, imageList);
for (final ImageData imageData : imageList) {
if (imageData.getAltText() == null) {
imageData.setAltText(productModel.getName());
}
}
productData.setVideos(imageList);
}
}
protected MediaContainerModel getPrimaryImageMediaContainer(final SOURCE productModel) {
final MediaModel picture = (MediaModel) getProductAttribute(productModel, ProductModel.PICTURE);
if (picture != null) {
return picture.getMediaContainer();
}
return null;
}
}
The error
[yjavac] Compiling 1 source file to /Users/riley/dev/work/hybrisdemo/core-customize/hybris/bin/custom/demo/demofacades/classes
[yjavac] ----------
[yjavac] 1. ERROR in /Users/riley/dev/work/hybrisdemo/core-customize/hybris/bin/custom/demo/demofacades/src/com/nobiz/demo/facades/populators/ProductVideoPopulator.java (at line 15)
[yjavac] extends AbstractProductImagePopulator<SOURCE, TARGET> {
[yjavac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[yjavac] AbstractProductImagePopulator cannot be resolved to a type
[yjavac] ----------
[yjavac] 2. ERROR in /Users/riley/dev/work/hybrisdemo/core-customize/hybris/bin/custom/demo/demofacades/src/com/nobiz/demo/facades/populators/ProductVideoPopulator.java (at line 17)
[yjavac] public void populate(final SOURCE productModel, final TARGET productData) throws ConversionException {
[yjavac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[yjavac] The method populate(SOURCE, TARGET) of type ProductVideoPopulator<SOURCE,TARGET> must override or implement a supertype method
[yjavac] ----------
[yjavac] 2 problems (2 errors)
Another issue I know I will need to resolve is in the ProductModel.PICTURE, Eclipse is not showing me that value, what should I be using to get the videos?
AbstractProductImagePopulator cannot be resolved to a type
I'm guessing that you have not defined the dependencies.
AbstractProductImagePopulator exists in commercefacades
. Make sure demofacades
defines commercefacades
as a dependency in extensioninfo.xml
.
Another issue I know I will need to resolve is in the ProductModel.PICTURE, Eclipse is not showing me that value, what should I be using to get the videos?
Since you added Product.videos
in items.xml, something like ProductModel.VIDEOS
should be available in ProductModel
.
Make sure to resolve all build / compilation errors first. Then, check if it's all good. Additionally, you will also need to add the populator to the converter that will convert the ProductModel.