how to see if a relation is created in hybris? - sap-commerce-cloud

I have created a relation in hybris. How to see if the relation was created? Is there a field created in backoffice or in code? My code
<relation code="CartEntries2B2BUnits" autocreate="true" localized="false" generate="true">
<sourceElement qualifier="cartEntry" type="CartEntry" cardinality="many">
<modifiers read="true" write="true" search="true" optional="true"/>
</sourceElement>
<targetElement qualifier="b2bUnit" type="B2BUnit" cardinality="one">
<modifiers read="true" write="true" search="true" optional="true"/>
</targetElement>
</relation>

After build you can see changes on java code. After initialize/update you can see new relation type and new fields on source and target type in type system at backoffice.
Sidenote
By an one-to-many relation you will find a new attribute on the model.
By a many-to-many relation an own ModelType will be created. Here is a picture with an example for it. other stackoverflow question

Related

How to localize a custom type created in trainingcore-items.xml in Hybris?

I have created a custom type in items.xml.
How can I localize the item type? Where should I use the localized keyword for the item type to be localized?
<itemtype code="Service" autocreate="true" generate="true">
<deployment typecode="23456" table="Service"/>
<attributes>
<attribute qualifier="code" type="java.lang.String" autocreate="true" generate="true">
<persistence type="property"/>
<description>Service Code</description>
<modifiers unique="true" read="true" write="true"/>
</attribute>
<attribute qualifier="serviceType" type="ServiceType" autocreate="true" generate="true">
<persistence type="property"/>
<description>Service Type</description>
<modifiers read="true" write="true"/>
</attribute>
<attribute qualifier="years" type="java.lang.Integer" autocreate="true" generate="true">
<persistence type="property"/>
<description>Service Years</description>
<modifiers read="true" write="true"/>
</attribute>
</itemtype>
The answer that you accepted is wrong.
You shouldn't do type="localized:Service". What this does is let you set a different Service value for each language.
If what you wanted to do was add different labels/localization for the Service type, then what you did in your other question is correct.
For English localization/translation, define the localization in trainingcore_locales_en.properties:
type.Service.name=Service
type.Service.code.name=code
type.Service.serviceType.name=serviceType
type.Service.years.name=years
type.ServiceType.name=ServiceType
type.ServiceType.Basic.name=Basic
type.ServiceType.BasicOnsite.name=BasicOnsite
type.ServiceType.Advanced.name=Advanced
For German translation, set the translation in trainingcore_locales_de.properties.
Reference:
Localization: https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/2011/en-US/8c05dbbc86691014a3fb88b6238b64b6.html
#geffchang's answer is correct. #Parvesh is wrong. It is not possible to have automagically localized Service just by adding localized:.
To do that you need to create new map-type:
<maptype code="localized:Service"
argumenttype="Language"
returntype="Service"
autocreate="true"
generate="false"/>
Do you mean you want to add this service as a localized attribute in another item type?
that can be done with something like this.
` <attribute qualifier="service" type="localized:Service">
<persistence type="property" />
</attribute>`

SAP Hybris 1905 - Update OOTB 'relation'

I'm looking at updating an OOTB 'relation', just wanted to add 'ordered=true'.
OOTB
\hybris\bin\modules\commerce-services\commerceservices\resources\commerceservices-items.xml
<relation code="PoS2WarehouseRel" localized="false"
generate="true" autocreate="true">
<description>This relation determines available warehouses for the point of service.</description>
<deployment table="PoS2WarehouseRel" typecode="6217" />
<sourceElement qualifier="pointsOfService" type="PointOfService"
cardinality="many" />
<targetElement qualifier="warehouses" type="Warehouse"
cardinality="many" collectiontype="list" />
</relation>
In my extension core, myextncore-items.xml, I overwrote the OOTB relation,
<relation code="PoS2WarehouseRel" localized="false"
generate="true" autocreate="false">
<description>This relation determines available warehouses for the point of service.</description>
<sourceElement qualifier="pointsOfService" type="PointOfService"
cardinality="many" />
<targetElement qualifier="warehouses" type="Warehouse"
cardinality="many" collectiontype="list" ordered="true"/>
</relation>
But getting error - [ycheckdeployments] No deployment defined for relation PoS2WarehouseRel
Then I tried, Updating to a new code name, added a 'deployment' element,
<relation code="PoS2WarehouseRelNew" localized="false"
generate="true" autocreate="true">
<description>This relation determines available warehouses for the point of service.</description>
<deployment table="PoS2WarehouseRelNew" typecode="13000" />
<sourceElement qualifier="pointsOfService" type="PointOfService"
cardinality="many" />
<targetElement qualifier="warehouses" type="Warehouse"
cardinality="many" collectiontype="list" ordered="true"/>
</relation>
This time getting error - java.lang.UnsupportedOperationException: Attribute warehouses from PoS2WarehouseRelNew relation is already declared in Warehouse
How do I define/update a relation between 'pointsOfService' and 'warehouses' ?
Maybe the example here helps:
https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/1905/en-US/bae7ed9732a4423f867114217ae21b46.html
In that example they redeclared the Collection attribute on one end of the itemtype. But looks hacky...
UPDATE: The given link included relationType has ordered property but xsd file hasn't got. I haven't tried this yet, may be compiler give an error.
Relations haven't got ordered attribute. ordered attribute exist on collections. You can check xxx-item.xml file schema item.xsdin module folder.
I've encountered the same problem. No deployment was defined and when i did - got the same exception. In my case it was all about changing name in qualifier.
In this case i would change it to "posWarehouses" ;)

Limit number of results in, or remove, attributechip from hmc admin tab

I have a list relation within one of my items in Hybris. This list is not necessary to display in the HMC admin tab and is causing long load times when viewing the item.
I'm having difficulty trying to limit the number of results displayed or remove the particular attributechip from the HMC all together using the hmc.xml.
Any advice would be appreciated.
Thanks
<relation code="Favorite2ProductRelation" localized="false"
generate="true" autocreate="true">
<sourceElement type="Favorite" qualifier="favorite"
cardinality="many">
<modifiers read="true" write="true" search="true" />
<custom-properties>
<property name="hiddenForUI">
<value>Boolean.TRUE</value>
</property>
</custom-properties>
</sourceElement>
<targetElement type="Product" qualifier="product"
cardinality="one">
<modifiers read="true" write="true" search="true" initial="true"
optional="false" />
</targetElement>
In the attribute definition you can set the property hiddenForUI, it will hide the field from bo :
<attribute ...>
<custom-properties>
<property name="hiddenForUI">
<value>Boolean.TRUE</value>
</property>
</custom-properties>
</attribute>
However it seems that it can't be used in relation...
You can switch the attribute value using impex :
INSERT_UPDATE RelationDescriptor;qualifier[unique=true];hiddenForUI[default=true]
;<attributeOfYourRelationToHide>;
If you have an attribute name present in different objects, you can specify which object you working on with enclosingType (thanks to Mouad El Fakir for the recall)
INSERT_UPDATE RelationDescriptor;enclosingType(code)[unique=true];qualifier[unique=true];hiddenForUI[default=true]
;<objectHoldingTheAttributeToHide>;<attributeOfYourRelationToHide>;

Update Categories in Hybris for products

I have several products with different super categories assign in Hybris.
I add the super categories to these products via impex.
$supercategories=supercategories(code,$catalogVersion)
UPDATE Product;code[unique=true];$catalogVersion[unique=true];supercategories(code,$catalogVersion)[mode=append]
;ProductName;;1017
;ProductName1;;1017
I'm wondering if there's a way I can defined which super category goes first at the moment I'm assigning the categories to the products, or an update to decide which one goes first.
So in few words, I will need super category 368 to be the first one.
Currently is New Result
297 368
368 686
686 297
You need to change the relation to enable ordered="true" for supercategories.
ordered="boolean" [0..1]
If 'true' an additional ordering attribute will be generated for maintaining ordering. Default is 'false'.
OOTB :
<relation code="CategoryProductRelation" autocreate="true" generate="true" localized="false">
<deployment table="Cat2ProdRel" typecode="143"/>
<sourceElement qualifier="supercategories" type="Category" cardinality="many" ordered="false">
<description>Super Categories</description>
<modifiers read="true" write="true" search="true" optional="true"/>
</sourceElement>
<targetElement qualifier="products" type="Product" cardinality="many" collectiontype="list" ordered="true">
<description>Products</description>
<modifiers read="true" write="true" search="true" optional="true"/>
</targetElement>
</relation>
TO :
<relation code="CategoryProductRelation" autocreate="true" generate="true" localized="false">
<deployment table="Cat2ProdRel" typecode="143"/>
<sourceElement qualifier="supercategories" type="Category" cardinality="many" ordered="true">
<description>Super Categories</description>
<modifiers read="true" write="true" search="true" optional="true"/>
</sourceElement>
<targetElement qualifier="products" type="Product" cardinality="many" collectiontype="list" ordered="true">
<description>Products</description>
<modifiers read="true" write="true" search="true" optional="true"/>
</targetElement>
</relation>
I am not sure whether redeclare=true will work in relation tag or not, but since for supercategories order="false", order will not maintained until unless its true.

Hybris - overriding existing unique attributes of an Item Type to make them non-unique

In my hybris application, I wanted to override my CustomerReview item type so that its attributes product and user are not unique anymore.
The uniqueness of these attributes are declared in the relationships between CustomerReview and Product/User. I tried adding the relationship declaration again to my extname-items.xml file and set the appropriate unique="false" attributes, as follows:
<relation generate="false" localized="false" code="ReviewToUserRel" autocreate="false">
<sourceElement type="User" qualifier="user" cardinality="one">
<modifiers write="false" initial="true" optional="false" unique="false" />
</sourceElement>
<targetElement type="CustomerReview" qualifier="customerReviews" cardinality="many">
<modifiers write="false" initial="true" />
</targetElement>
</relation>
This doesn't do the trick though. After I rebuild the application and Update the Running System, the user and product attributes of a CustomerReview are still unique attributes.
So what's the best solution for this problem?
It's true that rewriting the relation will not override it.
Another way to solve it would be to add an attribute to the type and set that as unique. For instance emailAddress:
<itemtype code="CustomerReview" autocreate="false" generate="false">
<attributes>
<attribute type="java.lang.String" qualifier="email">
<persistence type="property" />
<modifiers read="true" write="true" unique="true"/>
</attribute>
</attributes>
</itemtype>
Then you could have multiple reviews from the same user for the same product, as long as the emailAddress differs.
Updating the relation will not overwrite the existing relation. Better create new item definition for CustomerReview and then relate this with product.

Resources