我可以在Hybris中显示带有图库图像的参考产品吗?

时间:2016-03-07 07:28:33

标签: hybris

我可以在hybris中显示带有图库图像的参考产品吗?

我正在尝试从控制器检索图像,但jsp页面中的值始终为空

@RequestMapping(value = PRODUCT_CODE_PATH_VARIABLE_PATTERN, method = RequestMethod.GET)
    public String productDetail(@PathVariable("productCode") final String productCode, final Model model,
            final HttpServletRequest request, final HttpServletResponse response) throws CMSItemNotFoundException,
            UnsupportedEncodingException
    {
        final ProductModel productModel = productService.getProductForCode(productCode);
        final String redirection = checkRequestUrl(request, response, productModelUrlResolver.resolve(productModel));
        if (StringUtils.isNotEmpty(redirection))
        {
            return redirection;
        }

        updatePageTitle(productModel, model);
        populateProductDetailForDisplay(productModel, model, request);
        model.addAttribute(new ReviewForm());
        final List<ProductReferenceData> productReferences = productFacade.getProductReferencesForCode(productCode,
                Arrays.asList(ProductReferenceTypeEnum.SIMILAR, ProductReferenceTypeEnum.ACCESSORIES),
                Arrays.asList(ProductOption.BASIC, ProductOption.PRICE, ProductOption.GALLERY), null);

        try
        {
            for (int i = 0; i < productReferences.size(); i++)
            {
                final List<Map<String, ImageData>> imageDataList = getGalleryImages(productReferences.get(i).getTarget());
                final List<ImageData> imdData = new ArrayList<ImageData>();
                for (int j = 0; j < imageDataList.size(); j++)
                {

                    final ImageData sgImage = imageDataList.get(j).get("product");
                    if (sgImage != null)
                    {
                        imdData.add(sgImage);
                    }
                }
                productReferences.get(i).setPreviewImages(imdData);
            }
        }
        catch (final Exception e)
        {
            e.printStackTrace();
        }

        //model.addAttribute("imageDataList", imageDataList);
        model.addAttribute("productReferences", productReferences);
        model.addAttribute("pageType", PageType.PRODUCT.name());

        final String metaKeywords = MetaSanitizerUtil.sanitizeKeywords(productModel.getKeywords());
        final String metaDescription = MetaSanitizerUtil.sanitizeDescription(productModel.getDescription());
        setUpMetaData(model, metaKeywords, metaDescription);
        return getViewForPage(model);
    }

我扩展了产品参考数据类并添加了新属性

<bean
        class="de.hybris.platform.commercefacades.product.data.ProductReferenceData">
        <property name="previewImages"
            type="java.util.List&lt;de.hybris.platform.commercefacades.product.data.ImageData>" />
    </bean>

最后在jsp页面中我试图显示它

<section class="featured-products">

            <h4>${component.title}</h4>
            <div class="features-product-block">
                <div class="features-product carousel jcarousel-skin">

                    <c:forEach end="${component.maximumNumberProducts}"
                        items="${productReferences}" var="productReference">

                        <c:url value="${productReference.target.url}/quickView"
                            var="productQuickViewUrl" />

                        <div class="items">
                            <div class="each-product">
                                <div id="featuredprimaryPhoto" class="detailsPhotoWrap">
                                    <a href="${productQuickViewUrl}" class="popup scrollerProduct">
                                        <div class="thumb">
                                            <product:productPrimaryImage
                                                product="${productReference.target}" format="product" />
                                        </div>

                                        <h5>
                                            <c:if test="${component.displayProductTitles}">
                                                <span>${productReference.target.name}</span>
                                            </c:if>
                                        </h5> <c:if test="${component.displayProductPrices}">
                                            <p>
                                                <format:fromPrice
                                                    priceData="${productReference.target.price}" />
                                            </p>
                                        </c:if>
                                    </a>

                                </div>
                            </div>
                        </div>
                        <div id="FeaturedShowcase">
                    <ul class="wtf">

                        <c:forEach items="${productReferences.previewImages}"  var="previewImages"
                            varStatus="varStatus">
                            <li>Hello</li>
                        </c:forEach>


                    </ul>
                </div>
                    </c:forEach>
                </div>

            </div>

        </section>

我总是得到这个例外

WARN [hybrisHTTP12] [DefaultCMSComponentRendererRegistry]处理组件标记时出错。 currentComponent [ProductReferencesComponentModel(8796119335996)] exception:在第76行处理JSP页面/WEB-INF/views/desktop/cms/productreferencescomponent.jsp时发生异常

73:                     <ul class="wtf">
74:                     
75:                     <%-- <product:similarProductImagePanel similarProductImageList="${productReferences.previewImages}"/> --%>
76:                         <c:forEach items="${productReferences.previewImages}"  var="previewImages"
77:                             varStatus="varStatus">
78:                             <li>Hello</li>
79:                         </c:forEach>


Stacktrace:

有关此问题或任何建议的任何帮助

1 个答案:

答案 0 :(得分:0)

您收到此错误是因为您使用productReferences(列表)而不是productReference来获取previewImages

请更改此

<c:forEach items="${productReferences.previewImages}" var="previewImages" varStatus="varStatus">
     <li>Hello</li>
</c:forEach>

<c:forEach items="${productReference.previewImages}" var="previewImages" varStatus="varStatus">
      <li>Hello</li>
</c:forEach>

我只是将productReferences替换为productReference。希望这能解决问题。