SAP Hybris Commerce-初始化引用属性的默认值



我正在开发SAP Commerce(Hybris(1811,并试图通过引用类型ProductSales来扩展Product类型,该类型将包含产品销售数据并通过cronjob填充。

然而,我找不到一种正确的方法来初始化所有新产品和现有产品的这种新类型。即使在系统更新之后,此引用也未初始化(null(。

CCD_ 3和CCD_。

我想初始化这个引用的类型:

  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表中,而是作为参考,是因为我不希望在目录同步期间同步这些数据。

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

谢谢你的提示。

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

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

您可以检查ProductSales的类型代码。因为它可能在之前使用过

我重读了你的问题,并创建了一个新的答案。

我认为,如果您只将属性添加到"产品"中会更容易。之后,导入下面的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

最新更新