【问题标题】:Custom Product restrictions are not working on child components自定义产品限制不适用于子组件
【发布时间】:2022-10-12 22:37:54
【问题描述】:

由于项目特定的可见性规则,我为组件创建了自定义产品限制。此产品限制可应用于 ExampleListComponent、ExampleComponent,也可在需要时用于主页、产品页面或内容页面。 ExampleListComponent 可以有多个 ExampleComponent 实例。当对 ExampleListComponent(直接添加到主页内容槽)应用限制时,它工作正常,但在 ExampleComponent(子组件)上应用相同限制时,它不起作用。以下是一些代码sn-ps

项目.xml

<collectiontype code="ExampleCardList" elementtype="ExampleComponent" autocreate="true" generate="true" type="list" />

    <itemtype code="ExampleComponent" extends="AbstractMediaContainerComponent" autocreate="true" generate="true" jaloclass="com.example.core.jalo.ExampleComponent">
        <attributes>
            <attribute qualifier="title" type="localized:java.lang.String">
                <persistence type="property" />
            </attribute>
            <attribute qualifier="secondaryMedia" type="Media">
                <modifiers read="true" write="true" search="true" unique="false" />
                <persistence type="property" />
            </attribute>
        </attributes>
    </itemtype>

    <itemtype code="ExampleListComponent" extends="SimpleCMSComponent" autocreate="true" generate="true" jaloclass="com.example.core.jalo.ExampleListComponent">
        <attributes>
            <attribute qualifier="cards" type="ExampleCardList">
                <persistence type="property" />
            </attribute>
        </attributes>
    </itemtype>

    <itemtype code="ExampleAvailabilityRestriction" jaloclass="com.example.core.jalo.restrictions.ExampleAvailabilityRestriction" extends="AbstractRestriction" autocreate="true"   generate="true">
        <attributes>
            <attribute qualifier="product" type="ProductList">
                <persistence type="property" />
            </attribute>
        </attributes>
    </itemtype>
    
    

ExampleAvailabilityRestrictionEvaluator.java

public class ExampleAvailabilityRestriction implements CMSRestrictionEvaluator<ExampleAvailabilityRestrictionModel> {

    public boolean evaluate(ExampleAvailabilityRestrictionModel restrictionModel, RestrictionData restrictionData) {
        List<ProductModel> products = restrictionModel.getProduct();
        if (CollectionUtils.isEmpty(products)) {
            return true;
        }

        for (ProductModel product : products) {
            if (!availabilityService.isProductAvailable(product.getCode())) {
                return false;
            }
        }

        return true;
    }
}

我验证了其他 OTB 限制并且代码看起来没问题。是否需要任何其他配置才能对子组件应用限制。

【问题讨论】:

    标签: sap-commerce-cloud restriction


    【解决方案1】:

    这篇文章帮助我解决了这个问题。

    https://answers.sap.com/questions/13121879/time-restriction-not-working-on-cms-link-component.html

    在 examplecomponent.jsp 中添加了以下行

    <c:if test="${ycommerce:evaluateRestrictions(component)}">
    
    </c:if>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-30
      • 1970-01-01
      • 1970-01-01
      • 2021-10-02
      • 2018-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多