Hybris define product prices for PointOfService - sap-commerce-cloud

Hybris Out of the box doesn't provide any friendly way to define prices for products at point of service/vendor level, I need to implement price for products per store, what is the best way to implement this?

I think the best approach is to make a composite attribute in the POS model with UserPriceGroup.
<typegroup name="PointOfService">
<itemtype code="PointOfService" autocreate="false" generate="false">
<attributes>
<attribute qualifier="posUsergroup" type="UserPriceGroup">
<persistence type="property"/>
<modifiers optional="false" initial="true"/>
</attribute>
</attributes>
</attributes>
</itemtype>
</typegroup>
--> PriceRow supports different prices based on UserPriceGroup.

Related

How to move the data from the supertype to the subtype in Hybris?

I added a new attribute to my custom model (CustomApparelProduct), which extends from ApparelProduct model. ApparelProduct already extends ProductModel (SAP core model).
extension-items.xml
<typegroup name="Apparel">
<itemtype code="ApparelProduct" extends="Product"
autocreate="true" generate="true"
jaloclass="de.hybris.training.core.jalo.ApparelProduct">
<description>Base apparel product extension that contains additional attributes.</description>
<attributes>
<attribute qualifier="genders" type="GenderList">
<description>List of genders that the ApparelProduct is designed for</description>
<modifiers/>
<persistence type="property"/>
</attribute>
</attributes>
</itemtype>
<itemtype code="CustomApparelProduct" extends="ApparelProduct"
autocreate="true" generate="true" > // My custom type
<description> Custom Apparel Product that contains total amount attributes</description>
<attributes>
<attribute qualifier="amount" type="java.lang.Integer">
<description>Total buying amount </description>
<modifiers/>
<persistence type="property"/>
<defaultvalue>Integer.valueOf(0)</defaultvalue>
</attribute>
</attributes>
</itemtype>
When I go to Hybris Admin Console to check the data from my new Types by using FlexibleSearch, the result is that all the fields lack data. ( The picture below is from my CustomApparelProduct type)
When I check the FlexibleSearch for ApparelProduct type and Product type, the result is that all the fields hava data. ( The picture below is from ApparelProduct type)
I don't know what I need to transfer the original data from Product to my new type CustomApparelProduct. The original data was inserted to system using impex and csv file; the type used to insert is Product.
How I can transfer thedata to my custom type?
You cannot change from Type A to Type B easily/directly.
You need to migrate the data. i.e. Delete Type A item. Re-insert/create item as Type B. Also, check if there are other dependencies that need to be updated.

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

Redefining data type in items.xml in Hybris

I had a datatype defined as follows in items.xml:
<attribute qualifier="daysOfWeek" type="java.lang.String">
<persistence type="property" />
</attribute>
To modify the data type to enumeration,I redefined it as follows:
<enumtype code="DaysOfWeek" autocreate="true" generate="true">
<value code="Monday" />
<value code="Tuesday" />
</enumtype>
<attribute qualifier="daysOfWeek" type="DaysOfWeek">
<persistence type="property" />
</attribute>
After updating the extension,I am getting SQLException.Is there anything wrong with this approach?
hybris doesn't support updates like this in a "running" system.
The reason is that hybris won't drop any db columns and recreate them as any data contained in there would be lost (plus its probably difficult to write this logic for multiple supported databases).
If you are in a development phase of your project, the easiest way to fix this is to initialize your system from scratch (i.e. it will drop the database and recreate it).
If you have a live system / production system, you would have to take another approach:
You would define a new attribute (different name!) with your enumeration type.
You would then probably update any code to use the new field.
You would also have to take care of data migration, i.e. write some scripts that transfer the old data (e.g. the String "Monday" to the new respective enum value).
Hope this helps!

Can someone explain details of hybris auditing system?

By Default hybris auditing system comes in picture whenever any change in model or any attribute.
I want to use Hybris auditing module in my application?(SavedValuesModel).Does this module has any issue in use? does this work under the same transaction model.? I am newbie for hybris. Please provide some details on this.
Hybris auditing system comes with the item SavedValues. this is the item which maintains the model value history in it. Please refer to the item type declaration below:
<!-- hmc legacy - Saved Values -->
<itemtype code="SavedValues"
generate="true"
jaloclass="de.hybris.platform.hmc.jalo.SavedValues"
extends="GenericItem"
autocreate="true">
<deployment table="SavedValues" typecode="334"/>
<attributes>
.
.
.
</attributes>
</itemtype>
Now this item has a 1-n relation with the SavedValueEntry,
<!-- hmc legacy - Saved values -->
<relation code="SavedValueEntriesRelation" autocreate="true" generate="true" localized="false">
<sourceElement type="SavedValues" qualifier="parent" cardinality="one">
<modifiers read="true" write="false" initial="true" optional="false" search="true"/>
</sourceElement>
<targetElement type="SavedValueEntry" qualifier="savedValuesEntries" cardinality="many"
collectiontype="set">
<modifiers read="true" write="false" optional="true" partof="true"></modifiers>
</targetElement>
</relation>
This item type contains the original and changed values of the item, along with the other details such as modification type (create/update/remove), the user doing the change etc.
The main disadvantages of this system are mentioned below:
Any changes done to the item type outside hmc (e.g. by impex etc.) are not recorded. However, if the changes need to be logged then one can use the below syntax
HMCManager.getInstance().logItemModification(item.getPk(), newValues, oldValues, false);
This audit trail has a performance overhead and needs to be cleaned up for performance tune ups.
You can follow the below references for further reading:
https://wiki.hybris.com/display/release5/SavedValues+-+Keeping+Track+of+Attribute+Value+Modification
https://experts.hybris.com/questions/9332/logging-to-savedvalues-table.html

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