on 2019 Aug 15 11:40 AM
Hi!
Working with Restriction Types - This article is incomplete and does not help me go through the process from 0 to 100. I need help, I will describe my problem in detail.
Goal: create a new type of restriction by region.
What I've done:
1. Created a record of a new type

2. Configured in this way
<itemtype code="CMSRegionRestriction" extends="AbstractRestriction" jaloclass="de.hybris.platform.cms2.jalo.restrictions.AbstractRestriction" generate="true" singleton="false" jaloonly="false" metatype="RestrictionType" autocreate="true"/>
3. Now I have questions. What attributes need to be created for the type to work and a list of its values to be displayed in smartedit?


4. I understand that there are not enough attributes and correctly configured links in them with the essence of the regions. And this is the question of how to configure them? I am confused about where and what refers to each other. I tried to do based on the box restriction on categories and saw that in the category model you need to create an additional attribute, which serves as a kind of bundle. This is true?
5. I can’t find an article on creating a new connection and I don’t understand at all what to choose in the indicated fields and is it necessary to create something first as I wrote above about the additional attribute in the category? Please explain in simple terms what these fields mean.


If I missed something while presenting a question or missed a step when creating a type of restriction, please tell me. Thank you in advance!
Request clarification before answering.
hi Oleg,
to create a new type of restriction by region you need:
Example:
<items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="items.xsd">
<itemtypes>
<itemtype generate="true" code="RegionRestriction" jaloclass="org.training.jalo.RegionRestriction" extends="AbstractRestriction" autocreate="true">
<attributes>
<attribute qualifier="region" type="Region">
<description>Restricted region</description>
<modifiers optional="false"/>
<persistence type="property"/>
</attribute>
</attributes>
</itemtype>
</itemtypes>
</items>@Component
public class RegionRestrictionEvaluator implements CMSRestrictionEvaluator<RegionRestrictionModel> {
@Autowired
private UserService userService;
@Override
public boolean evaluate(RegionRestrictionModel regionRestrictionModel, RestrictionData restrictionData) {
final UserModel currentUser = userService.getCurrentUser();
final RegionModel restrictedRegion = regionRestrictionModel.getRegion();
final List<RegionModel> usersRegions = Lists.newArrayList();
if (!Collections.isEmpty(currentUser.getAddresses())) {
usersRegions.addAll(currentUser.getAddresses().stream().map(AddressModel::getRegion).collect(Collectors.toList()));
}
return usersRegions.contains(restrictedRegion);
}
}<bean id="cmsUserGroupRestrictionEvaluatorMapping" class="de.hybris.platform.cms2.servicelayer.services.evaluator.CMSRestrictionEvaluatorMapping">
<property name="restrictionTypeCode" value="RegionRestriction" />
<property name="restrictionEvaluator" ref="regionRestrictionEvaluator" />
</bean>
INSERT_UPDATE RegionRestriction;$contentCV[unique=true];uid[unique=true];name;region(isocode);components(uid);∁onentRef
;;TestRegionRestriction;Test Region Restriction;JP-16;AddToCart;TestRegionRestrictionhope this helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When we extend the AbstractRestriction, below is the error we are facing in 2011 version.
The type customRestriction must implement the inherited abstract method AbstractRestriction.getDescription(SessionContext).
Even when we add the unimplemented method getDescription(SessionContext) in the generated jalo class, it will be overwritten on the next platform build. How to resolve this error ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Srinidhi,
You can add below code to your jalo class to resolve this issue:
@Override public String getDescription(SessionContext arg0) { return null; }
This will not be overridden next time it is generated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.