How to set the order limit in Hybris? - sap-commerce-cloud

I have to fix an order limit in Hybris, whereby the customer is not allowed to order more than a specific amount.
I was thinking of handling it in specific places, where the user can include items in the cart(i.e. on PDP and cart), but I think the promotions will have to be handled separately when the user tries to checkout.
Where is such a check recommended and is there a standard OOB approach?

I would suggest a validation on a checkout flow step.
For example, if you have a step after the cart entries validation (this is often the real start of the checkout), you can configure a validator to this step :
<bean id="MyFirstCheckoutStep" parent="checkoutStep">
<property name="checkoutGroup" ref="myCheckoutGroup"/>
<property name="checkoutStepValidator" ref="orderAmountLimitValidator"/>
...
...
</bean>
<bean id="orderAmountLimitValidator"
class="com.site.checkout.steps.validation.impl.OrderAmountLimitValidator"
parent="abstractCheckoutStepValidator"/>
Now you should implement your logic in the class com.site.checkout.steps.validation.impl.OrderAmountLimitValidator that should extend AbstractCheckoutStepValidator and return proper ValidationResults value.

Related

How to remove OOTB attributes from Backoffice

I need to remove Out of the box attributes from Backoffice, these attributes are defined in the multipe OOTB extensions.
I am not sure if you want to hide these attributes from backoffice or you want these attributes to be removed completely from the database.
If you just want to hide them, you can add the following custom property for these attributes in the items.xml:
<custom-properties>
<property name="hiddenForUI">
<value>Boolean.TRUE</value>
</property>
</custom-properties>
Please check core-items.xml for some examples.
Alternatively, you can import the following ImpEx:
INSERT_UPDATE AttributeDescriptor;qualifier[unique=true];enclosingType(code)[unique=true];hiddenForUI
;the-attribute-to-be-hidden;the-itemtype-to-which-the-attribute-belongs;TRUE
If you want them to be removed completely from the database, you can do the following things:
Identify the extensions in which they have been defined and if any of these extensions are not required, just remove them from localextensions.xml
Remove these attributes from their respective items.xml
Then, you need to execute ant clean all updatesystem. However, the columns corresponding to these attributes will still persist in the database as system update does not remove/drop any table/column from the database (you can only add new tables/columns and add/update/remove the data using system update). In most of the cases, system initialization is also not a possibility. So, you are left with only one option, which is to delete the columns from the database using the SQL queries.

What is the use of "hmcIndexField" in Hybris?

I noticed that some attributes contain within their definition a hmc custom property:
<custom-properties>
<property name="hmcIndexField">
<value>"thefield"</value>
</property>
</custom-properties>
Can someone explain why is this custom property needed and when should it be used ?
It is an deprecated attribute for hmc search configuration. You can find all information here:
Lucene Search HMC Hybris4
In common the page says that you can define customized searches in the hmc. With this property you define which attributes will be searchable wit the LuceneSearch.

Spring Integration - modifying one property of the payload

In my SI flow I want to modify one property of the payload. At the beginning of the flow I populate a Java bean (let's call it MyFlowBean) and I send it via the difference components of the flow.
At one point I want to alter the property 'extractedValue' of this bean and I want to do it in the right way. I mean I am sure there is a component (a transformer??) where I can say e.g.
<transform propert='payload.extractedValue' value='[spEl expression]' />
Ok, I know there isn't such a tag in SI, it was just a sample.
Also I could achieve it with serviceActivator but it doesn't seem right to me to write a Java class that contain 2 lines of code and use this class in the service activator.
It has to be more elegant way.
Thanks,
V.
The Content Enricher pattern is for your and respectively the <enricher> component is present in the Spring Integration to achieve the desired goal:
<enricher>
<property name="extractedValue" expression="[spEl expression]"/>
</enricher>

BDC model/search connector and multi value field with refinment

BDC model:
My BDC model's entity has a property named Color.
The TypeName is specified as System.String[].
<TypeDescriptor Name="Color" TypeName="System.String[]">
<Properties>
<Property Name="RequiredInForms" Type="System.Boolean">false</Property>
</Properties>
</TypeDescriptor>
Database:
In my database (my BDC content source) I added column values like this one:
;#Blue;#Green;#Yellow;#
Search Schema
I created a new managed property and enabled multiple values (and also refinable - active, queryable, retrievable, safe).
Search Results
Filtering on a specific color via search works.
Example: RsExpAdvWorksProductColor:"blue"
Search Refinement
However I cannot refine on colors.
Adding a refiner on my Managed Property shows up like that:
Color
;#Blue;#Green;#Yellow;#
;#Green;#Yellow;#
;#Red;#Green;#Yellow;#Blue;#Black;#Cyan;#
Obviously the single values are not treated as such - the whole "string" of "special-delimiter" separated values is being shown as a refinment criteria.
Any hints?
Update 2015-03-20: I took a closer look at the built-in multi choice columns. In search results they are being returned as "Value1;#Value2;#" and so on. Basically there is a trailing Red;#Blue;# separator - no leading ;#Red;#Blue;# one. Much to my regret that didn't solve my problem.
Update 2015-03-20: Surprise surprise. It is in fact "working as designed" (like so many things in SharePoint :P). What I am looking for has to be dealt with separately. It behaves exactly the same with built-in multi choice fields so there is nothing wrong with my BDC/Search integration.
Regarding the refiner, have a look at the following links...
http://www.eliostruyf.com/part-6-create-multi-value-search-refiner-control/
https://hyankov.wordpress.com/2014/12/15/sharepoint-2013-refiner-multi-value-contains-instead-of-an-equals/

XML Schema: How to validate an attribute with multiple keys concatenated?

Let's say I can get XML like this:
<Property Name="Title"/>
<Property Name="Content"/>
<Property Name="Address"/>
<Source properties="Title,Content,Address"/>
How coud I validate the "properties" attribute of "Source", so that any composition of the above listed "Property" items could be checked? (For example: "Title", "Title,Content", all of these concatenations are correct, while "Title, URL" is not correct.)
You can't do that within XML Schema. You can do it with your own higher level of validation based on XSLT, XQuery or Schematron, for example.
xan is right; validating always means, to match a XML file against a given schema. But there is no schema involved here, your problem is instead, to read a data file, and validate later entries against earlier ones (if the box above is supposed to represent one file) or one data file against another data file (if the gap is supposed to be a file separator). Beyond that, a schema defines the structure of elements and attributes and optionally data types (values only, if there is a strict enumeration of valid values). Also no match here, instead you want to verify data against data. Sorry, the tool of a schema mismatches the problem to solve.

Resources