cancel
Showing results for 
Search instead for 
Did you mean: 

How to calculate CSV header attributes without saving it to Model

Sagar_Bh
Participant
0 Kudos

I want to import a CSV via the cloud hot folder.


There are few values that are coming in CSV which we have in the Impex header but are not present in the model. Based on that header values we need to do some calculations and save it to an attribute.

For example -
StockLevel -> available = stockA + StockB - ( Stock x + Stock Y + Stock z)

another requirement/example:

product:- code;Mcode;Scode;Fcode;ProductType -> We need to save 1 of the code based on product type and ignore all other codes

View Entire Topic
mansurarisoy
Contributor
0 Kudos

You can use Translators to achieve what you need. (Reference: https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/2105/en-US/4ce7b82cbc574456ac197393f88e...

You can combine the values with a separator (e.g. #) then in translator split them with the separator and use according to your needs. SpecialValueTranslator interface may suit more to your need.

I found an example in OOTB code for stock. The class de.hybris.platform.acceleratorservices.dataimport.batch.stock.StockTranslator implements SpecialValueTranslator and uses ":" as separator. First part is available amount and the second part is for warehouse. In ImpEx header it's used as the following (in the file /bin/modules/core-accelerator/acceleratorservices/resources/acceleratorservices/integration/hot-folder-spring.xml😞

UPDATE Product;code[unique=true];@stock[translator=de.hybris.platform.acceleratorservices.dataimport.batch.stock.StockTranslator,adapter=stockImportAdapter];$catalogVersion

As you can see, stock is not a direct attribute of product. But with the help of translator, you can update StockLevel for the product also. You can get more insight by investigating the StockTranslator and other OOTB translators.

Hope this helps,