[MSHOP-64] Product teaser broken in 4.5 Created: 22/Feb/13  Updated: 16/May/13  Resolved: 16/May/13

Status: Closed
Project: Magnolia Shop (closed)
Component/s: None
Affects Version/s: 1.1.1
Fix Version/s: 1.1.2

Type: Bug Priority: Neutral
Reporter: Will Scheidegger Assignee: Will Scheidegger
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

The product teaser does not work in Mag 4.5 anymore: The model class throws a NPE when the renderer tries to access the teaser target:

Caused by: java.lang.NullPointerException
	at info.magnolia.jcr.wrapper.DelegatePropertyWrapper.getType(DelegatePropertyWrapper.java:228)
	at info.magnolia.jcr.util.ContentMap.getNodeProperty(ContentMap.java:199)
	at info.magnolia.jcr.util.ContentMap.get(ContentMap.java:174)
	at info.magnolia.freemarker.models.ContentMapModel.getAsString(ContentMapModel.java:92)
	at freemarker.core.Expression.isEmpty(Expression.java:161)
	at freemarker.core.BuiltIn$has_contentBI._getAsTemplateModel(BuiltIn.java:730)

I think the wrapping of the JCR node and then converting to a ContentMap somehow does not work. Property.getType() returns null when the property "@name" is being fetched from the target node.



 Comments   
Comment by Will Scheidegger [ 22/Feb/13 ]

There does not seem to be much of a difference between what the AbstractTeaserModel.getTarget() and the ProductTeaserModel.getTarget() does. Both get a node and then use the exact same code to wrap, convert and return it. The problem might be, that the nodes themselves are different. In AbstractTeaserModel gets a MgnlVersioningNodeWrapper from NodeUtil.getNodeByIdentifier() whereas in ProductTeaserModel an I18nNodeWrapper is being used.

Comment by Will Scheidegger [ 22/Feb/13 ]

O.k., so it actually is due the different node types used. When doing a detour, fetching the node again by identifier as it is done in AbstractTeaserModel the ProductTeaserModel now works fine. The method could look something like this:

    
    @Override
    public ContentMap getTarget() {

        Node target = ShopUtil.getContentByTemplateCategorySubCategory(siteRoot, "feature", "product-detail");

        if (target != null) {
            try {
                log.debug("detail page: " + target.getPath());
                target = NodeUtil.getNodeByIdentifier(getRepository(), target.getIdentifier());
                return templatingFunctions.asContentMap(stkFunctions.wrap(target));
            } catch (RepositoryException ex) {
                log.error("could not get path for node " + target);
            }
        } else {
            log.error("no page with subcategory product-detail found");
        }
        return null;
    }

Is there anything that should be improved? E.g. can the detour be avoided somehow? Or should I patch this?

Comment by Teresa Miyar [ 25/Feb/13 ]

I've tested 1.1.1-snapshot and the product teaser works. Could you try to reproduce the problem with the latest version?
Could you send the definition of the product detail page? there might be something wrong there.

Comment by Will Scheidegger [ 16/May/13 ]

Works with latest version and Mag 4.5.8

Generated at Mon Feb 12 07:08:56 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.