SAP Hybris Commerce - 初始化参考属性的默认值

SAP Hybris Commerce - Initialize default value for a reference attribute

我正在使用 SAP Commerce (Hybris) 1811,我正在尝试扩展一个 Product 类型并引用一个类型 ProductSales,它将包含产品销售数据并通过 cronjob 进行填充。

但是,我找不到为所有新产品和现有产品初始化此新类型的正确方法。即使在系统更新后,此引用仍未初始化(空)。

ProductProductSales 之间应该是一对一的关系。

我想要初始化此引用类型:

  1. 在对所有尚无参考的现有产品进行系统更新期间
  2. 为所有新创建的产品创建一个实例

我的items.xml定义:

<itemtype code="ProductSales" autocreate="true" generate="true" >
    <deployment table="productsales" typecode="15011" />
    <attributes>
        <attribute qualifier="unitsSold" type="localized:java.lang.Long">
            <description>Amount of units sold</description>
            <persistence type="property"/>
        </attribute>
        <attribute qualifier="ordersCount" type="localized:java.lang.Long">
            <description>Count of how many orders contained this product</description>
            <persistence type="property"/>
        </attribute>
    </attributes>
</itemtype>

<itemtype code="Product" autocreate="false" generate="false">
   ...
    <attribute qualifier="productSales" type="ProductSales">
        <description>Product Sales</description>
        <modifiers partof="true" optional="false" initial="true" />
        <persistence type="property"/>
    </attribute>
   ...
</itemtype>

我之所以没有将数据直接存储在 Product table 中,而是作为参考,是因为我不希望在目录同步期间同步这些数据。

为所有产品初始化这种新类型的最佳方法是什么?

感谢任何提示。

您可以检查 ProductSales typeCode 。因为它可能以前被使用过

我 re-read 你的问题并创建了一个新答案。

我认为如果只将属性添加到 Product 会更容易。之后,导入下面的 impex 以禁用您不想同步的属性的同步。您需要将“MySyncJob”替换为用于同步作业的代码。

INSERT_UPDATE SyncAttributeDescriptorConfig;syncJob(code)[unique=true][path-delimiter=!];attributeDescriptor(enclosingType(code), qualifier)[unique=true];includedInSync;copyByValue
;MySyncJob;Product:unitsSold;false;false
;MySyncJob;Product:ordersCount;false;false

最后,我通过在 cronjob 本身中创建缺失的引用解决了这个问题。我只在暂存目录中创建此包装器对象以供稍后同步。

顺便说一句,我发现除了修改同步作业之外,创建一个包装对象并保持其引用在目录之间同步是SAP推荐的解决方案。