创建 Populator 以复制 ProductPrimaryImagePopulator 功能
Creating a Populator to duplicate the ProductPrimaryImagePopulator functionality
我已将默认产品类型扩展为也具有与图像属性相同的视频属性,除了名称:
<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>
我现在正在尝试复制 ProductPrimaryImagePopulator 以在数据对象中设置视频,但我遗漏了一些明显的东西。这是代码和错误:
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;
}
}
错误
[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)
我知道我需要解决的另一个问题是 ProductModel.PICTURE,Eclipse 没有向我显示该值,我应该使用什么来获取视频?
AbstractProductImagePopulator cannot be resolved to a type
我猜你还没有定义依赖关系。
AbstractProductImagePopulator 存在于 commercefacades
中。确保 demofacades
将 commercefacades
定义为 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?
由于您在 items.xml 中添加了 Product.videos
,ProductModel.VIDEOS
之类的内容应该可以在 ProductModel
中使用。
确保首先解决所有构建/编译错误。然后,检查是否一切正常。此外,您还需要将填充器添加到将转换 ProductModel 的转换器中。
我已将默认产品类型扩展为也具有与图像属性相同的视频属性,除了名称:
<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>
我现在正在尝试复制 ProductPrimaryImagePopulator 以在数据对象中设置视频,但我遗漏了一些明显的东西。这是代码和错误:
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;
}
}
错误
[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)
我知道我需要解决的另一个问题是 ProductModel.PICTURE,Eclipse 没有向我显示该值,我应该使用什么来获取视频?
AbstractProductImagePopulator cannot be resolved to a type
我猜你还没有定义依赖关系。
AbstractProductImagePopulator 存在于 commercefacades
中。确保 demofacades
将 commercefacades
定义为 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?
由于您在 items.xml 中添加了 Product.videos
,ProductModel.VIDEOS
之类的内容应该可以在 ProductModel
中使用。
确保首先解决所有构建/编译错误。然后,检查是否一切正常。此外,您还需要将填充器添加到将转换 ProductModel 的转换器中。