1
votes

I'm working on SAP Commerce (Hybris) 1811 and I'm trying to extend a Product type with a reference to a type ProductSales, which is going to contain product sales data and be filled via a cronjob.

However, I can't find a proper way to initialize this new type for all new and existing products. Even after a system update, this reference is uninitialized (null).

There should be a 1-to-1 relation between Product and ProductSales.

I'd like this referenced type to be initialized:

  1. During system update for all existing products which don't have the reference yet
  2. Create an instance for all newly created products

My items.xml definition:

<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>

The reason I'm not storing the data directly in the Product table, but as a reference, is that I don't want these data to be synchronized during catalog synchronization.

What would be the best way to initialize this new type for all products?

Thanks for any tips.

3

3 Answers

1
votes

In the end, I solved this by creating the missing references in the cronjob itself. I only create this wrapper object in the staged catalog to be synced later.

By the way, I found that besides modifying the sync job, creating a wrapper object and keeping its reference synchronized between the catalogs is the solution recommended by SAP.

0
votes

You can check for of ProductSales typeCode .Because it may have been used before

0
votes

I re-read your question and created a new answer.

I think it's easier if you just add the attributes to Product. After that, import the impex below to disable sync for the attributes you don't want to be synced. You will need to replace "MySyncJob" with the code that use for the sync job.

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