I have a classification system attribute in a classification class that classifies all categories in my catalog.
This attribute is called Vanprijs. I can add values to this attribute for different products/variants on the hMC. Like on the picture below, but how can I add these values via impex files?
I did try this, but the importer doesn't recognize Vanprijs as a known attribute:
INSERT_UPDATE ModelVariantProduct;$baseProduct;code[unique=true];name[lang=$lang];Vanprijs;$catalogVersion;$approved
;B300047;M300047;Toiletverhoger (met deksel en stabiele armleuningen);10
This is how it's done (note the 2 variables $clAttrModifiers and $vanprijsFeature):
$lang=nl
$productCatalog=myProductCatalog
$catalogVersion=catalogversion(catalog(id[default=$productCatalog]),version[default='Staged'])[unique=true,default=$productCatalog:Staged]
$approved=approvalstatus(code)[default='check']
$baseProduct=baseProduct(code,$catalogVersion)
$clAttrModifiers=system='MySystemClassifications',version='General',translator=de.hybris.platform.catalog.jalo.classification.impex.ClassificationAttributeTranslator,lang=nl
$vanprijsFeature=#Vanprijs[$clAttrModifiers];
INSERT_UPDATE Product;code[unique=true];$vanprijsFeature;$catalogVersion
;M300047;200.59;
Related
How can you rename & add new columns beside the item attributes when exporting data via ImpEx?
I have the following:
"#% impex.setTargetFile( ""attributes.csv"" , true );"
insert_update ClassificationAttribute; pk[unique=true]; code ; creationtime; classes
But I want to have, besides code & creationTime, the name and the code of the classes and subcategories/supercategories of them. For now I can only get the PK.
And I want the columns to be renamed, for example: the code column to be renamed into attribute_code
Maybe you want to read more at
https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/2005/en-US/8bef9530866910148e6cff59d9afa127.html
and
https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/2005/en-US/1c8f5bebdc6e434782ff0cfdb0ca1847.html
and
https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/2005/en-US/8bd9d5bb86691014ba9d95a88ede75f3.html
You cannot achieve this using impexes, unless you are okay with having two csvs, one corresponding to classificationattribute and another one for classsification class:
"#% impex.setTargetFile( ""ClassificationAttribute.csv"" , true );"
insert_update ClassificationAttribute; pk[unique=true]; code ; creationtime;classes(&Item)
"#% impex.setTargetFile( ""ClassificationClass.csv"" , true );"
insert_update ClassificationClass;&Item;code;name;supercategories(code)
The supercategories is a list and classes is also a list, a list of list scenario is not supported in a single line of impex. Even with this in place you cannot reimport the data with a renamed attribute.
You can however, achieve the same using a customized version of excel export and import, OOTB code is implemented using apache POI. Extend DefaultExcelExportService and override create custom export classification attribute. Write the reverse logic after extending DefaultExcelImportService, if reimport is required:
public class CustomClassificationExportServiceImpl extends DefaultExcelExportService implements CustomExportService{
public class CustomClassificationImportServiceImpl extends DefaultExcelImportService implements CustomImportService{
Create custom method for classification export. This method fetches the classes corresponding to each classificationattribute as a list and converts this into a set of excel cells.
Create a meta excel sheet that stores the mapping of the actual attribute with the alias attribute given (if reimport required).
Implement the custom logic for import in DefaultExcelImportService. This should fetch the actual attribute using metadata, convert the excel columns to a list etc
I have EDM model classes generated by entity FrameWork DB first approach. Everytime I update EDMX all the classes that have I added validation,schema, attribute names to be displayed are gone.
What is the best approach to handle this situation ?
enter image description here
enter image description here
The generated classes are partial, so you can generate your own properties and methods into a new partial class (in different file) for associate generated class.
Hope my answer could help.
I know how to write and use Cell Decorator and Translators during impex imports
in hybris, However, I am not sure when the one is preferred over the other?
For example, I have used Cell Decorator to change the value of an attribute slightly like if a customer is from US I will append an '_US' at the end of customer number while inserting in the DB.
Similarly, I have used Translator when I need to find a status of a product Available/Out of stock based on product ID.
However, I am not 100% positive is this the only differentiation.
Any explanation with example will be appreciated.
What is a translator?
(from SAP documatentation):
A translator class is a converter between ImpEx-related CSV files and values of attributes of Hybris Commerce items
The translator is a "converter" it is used when you need to modify your data into some other kind of data.
What is a decorator?
(From Wikipedia)
The decorator pattern is a design pattern that allows behavior to be added to an individual object, dynamically, without affecting the behavior of other objects from the same class
What should be used in hybris
For Impex most of the time you want to use a translator because you want to use simple syntax in the Impex file and convert( ie. translate/modify) it to the target format using code.
When you need to add functionality to an existing feature use a decorator. It can be used in Impex too if you want to add data.
For example you can read the Wikipedia article for decorator, in hybris you can look at ChineseLogisticCellDecorator. For translators, you have the list in hybris documentation (mentioned above)
I have a product catalog and a classification catalog. The product catalog contains a product and the classification catalog contains attributes, however when I try to insert the product with the attributes it doesn't show when I click the product and go under attributes tab.
How I enter product with attributes:
$lang=en
$productCatalog=productCatalog
$catalogVersion=catalogversion(catalog(id[default=$productCatalog]),version[default='Staged'])[unique=true,default=$productCatalog:Staged]
$approved=approvalstatus(code)[default='check']
$baseProduct=baseProduct(code,$catalogVersion)
$clAttrModifiers=system='MySystemClassifications',version='General',translator=de.hybris.platform.catalog.jalo.classification.impex.ClassificationAttributeTranslator,lang=nl
$id=#id[$clAttrModifiers];
INSERT_UPDATE Product;code[unique=true];$id;$catalogVersion
;M300047;200.59;
Is there something I have to do after adding it to link it to the product?
There are a lot of pitfalls when working with the classification system. I cannot see an obvious error in your impex script, so I want to ask for every precondition, that has to be fulfilled.
You need a ClassificationSystem (equivalent for Catalog for categories and product)
You need a ClassificationSystemversion (equivalent for CatalogVersion for category and product)
Your product has to be in a category.
This category needs a super category of type ClassificationClass.
You need a ClassificationAttribute.
You need a ClassAttributeAssignment which assigns your ClassificationAttribute to a ClassificationClass.
(Optional) You can create ClassificationAttributeUnits to define the unit of an attribute.
(Optional) You can create ClassificationAttributeValues to define possible values for a ClassificationAttribute.
When these preconditions are met, you can assign values to a product using your impex script.
Since this structure is a bit tricky, let me clarify it with an example:
Consider the ClassificationClasses "Photocameras" and "Videocameras". There are ClassificationAttributes like "Resolution", who are assigned to both ClassificationClasses using a ClassAttributeAssignment. But there might also be a ClassificationAttribute "Shutter Speed" assigned to only photocameras using a ClassAttributeAssignment. For photocameras shutter speed might be measured in milliseconds. So in the ClassAttributeAssignment for photocameras and shutter speed you assign a ClassificationUnit "milliseconds". Now consider a new ClassificationAttribute "Form Factor". There are only a few available form factors, so for each form factor you create one ClassificationAttributeValue. Using a ClassAttributeAssignment, you can assign an ClassificationAttribute "Form Factor" to your "Photocameras" ClassificationClass with the ClassificationValues "Compact Camera", "SLR" and so on. Once again, there might be different form factor values for video cameras.
My app has pre-populate Category data contain icon image and its name. In the next version I need to localized its name, is this possible ? Found Adding relation for localized methods here, but this is an only way to do it ?
There is no "Localize" feature build in to Core Data. So adding the localized names in a separate entity as mentioned in How to represent a localized string type in Core Data? is the way to go.