Hybris PCM product category restriction - sap-commerce-cloud

We are implementing Hybris PCM and we would like to create some product category restrictions.
Some employees should find only the products with a specific category. For example, some employees can see only products with category "drills," while other employees can see only products with category "shoes".
How can we do this in Backoffice and PCM?

Search restrictions (personalization) can be used to achieve this:
INSERT_UPDATE SearchRestriction;code[unique=true];active;generate;restrictedType(code);principal(uid);query
;Product_restriction_1; true; false; Product; usergroup1; "{category} in ({{ select {pk} from {Category} where {code}='category1' }})"
;Product_restriction_2; true; false; Product; usergroup2; "{category} in ({{ select {pk} from {Category} where {code}='category1' }})"
Here employees belonging to usergroup1 can see products belonging to category1 and usergroup2 can see products belonging to category2 (these queries given above are just some dummy queries for quick understanding of concept).
Restriction type = product
Principal = user/ usergroup corresponding to the backoffice employee logging in
A more specific query to suit your requirement would be:
select {r.target} from { CategoryProductRelation as r join Category as c on {r.source}= {c.pk} } where {c.code}='shoes'
Hence please use an impex like:
INSERT_UPDATE SearchRestriction;code[unique=true];active;generate;restrictedType(code);principal(uid);query
;Product_restriction_shoes; true; false; Product; shoeUser; " {pk} in ({{select {r.target} from { CategoryProductRelation as r join Category as c on {r.source}= {c.pk} } where {c.code}='shoes' }}) "

Related

Hybris ModelService remove not removing

I'm trying to remove all the Stock from query products in a cronjob:
List<ProductModel> products = flexibleSearchService.search(GET_SPECIAL_PRODUCTS_QUERY);
for (ProductModel product : products.getResult()) {
modelService.removeAll(product.getStockLevels());
}
If I debug here I can see that all the products have stock, however, after performing the removeAll method from model Service, the Stock is not removed.
How can I fix this?

Get relational data in dynamodb

I have studied many articles and blogs and finally conclude that I need only one base table for whole application and then many Global Secondary Indexes according to my access patterns. Now I have stuck in a problem.
My base table structure is:-
**PK** **SK** **data**
university uni_uuid name
course course_uuid uni_uuid
As you see when I will add a new course it will always have a university uuid which will save under university_uuid key with course record.
Now I want to list all the courses to Admin. So I query the dynamodb like:-
var params = {
TableName: "BaseTable",
FilterExpression:"PK = :type",
ExpressionAttributeValues: {
":type": "Course"
}
};
docClient.scan(params, onScan);
var count = 0;
function onScan(err, result) {
if (err) {
console.error("Unable to scan the table. Error JSON:", JSON.stringify(err, null, 2));
} else {
resolve(result);
}
}
This successfully returns me all the added courses. Like:-
Now my question is that how can I show University name in the column University. Currently university_uuid is displaying here. Do I need to run another query and find university name by its uuid, if so then for 100 courses I need to run 100 more queries for each course university name.
Any help will deeply appreciated!!
Approaches:
If university name will not be changed in Admin you can use denormalization and include it into courses table. Even if
university name can be changed, on update you can get all corresponded courses by uni_uuid and update redundant data.
When you receive courses list, distinct uni_uuid and then request data from
universities using IN clouse.

How can I design Jhipster JDL relationship for a simple Region > Country > State > City dropdowns

I couldn't figure out how to make relations between entities make them depended each other.
Is jdl itself enough to have entities like below;
Add New Region:
Region Name
Add New Country:
Region (Dropdown)
Country Name
Add New State:
Region (Dropdown)
Country (Dropdown "List updates with the change of the region)
State Name
Add New City:
Region (Dropdown)
Country (Dropdown "List updates with the change of the region)
State (Dropdown "List updates with the change of the Country)
City Name
Add New Address:
Region (Dropdown)
Country (Dropdown "List updates with the change of the region)
State (Dropdown "List updates with the change of the Country)
City (Dropdown "List updates with the change of the State)
Address
I've tried this;
entity Region {
regionName String required
}
entity Country {
countryName String required
}
entity State {
stateName String required
}
entity City {
cityName String required
}
entity Address {
addressLine String required
}
relationship ManyToOne {
Country{region(regionName)} to Region,
State{country(countryName)} to Country,
City{state(stateName)} to State,
Address{city(cityName)} to City
}
paginate all with infinite-scroll
service all with serviceImpl
This jdl shows only it's parent. I want to create a new address entity with all parents up to region.
If I try to make relationships with all parents, all dropdowns are individual. You can select Asia > USA > Paris.
What is the right way to relate the address with Region, Country, State, City with correct dependencies?
The JDL looks good to me, it's just that JHipster won't generate the client view with transitive relationships. You have to write it manually.
On server side, you can use DTOs to combine all data in one request. Add dto * with mapstruct to the bottom of your JDL and then edit generated mappers.

Return additional fields from related model in StrongLoop

In a situation similar to this one, Getting joined data from strongloop/loopback, where one has Products and product Categories, how does one return the Category Name rather than the id (foreign key) as the default response for /Products? I've been able to hide the id field but not return the name. Thanks.
Supposing you have the relation Product hasOne Category, called productCat
With Node API
Product.find({
include: {
relation: 'productCat', // include the Category object
scope: { // further filter the Category object
fields: 'name', // only show category name
}
}
}, function(err, results) { /* ... */});
With REST API
GET api/Products?filter={"include":{"relation":"productCat","scope":{"fields":"name"}}}
Hope this helps (haven't tested it but it should work)

RetrieveMultiple query on team security roles

I'm working on a plugin event using the Plugin Registration Tool and CRM Dynamics SDK that needs to check the security roles for the logged in user.
I've found plenty of examples and documentation on retrieval of user roles assigned specifically to the user but I also need to retrieve the security roles assigned to the teams the user is a member of.
I have the list of teams the user is a part of via a separate RetrieveMultiple query but I have been unable to find documentation on the relationship between teams and their assigned security roles.
I have the following incorrect query but as the security role to team relationship is many to many, I would assume there is a relational entity that I am missing for the query:
CrmService.RetrieveMultiple(new QueryExpression
{
LinkEntities =
{
new LinkEntity
{
LinkFromEntityName = "role",
LinkFromAttributeName = "roleid",
LinkToEntityName = "???",
LinkToAttributeName = "roleid",
LinkCriteria = new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression
{
AttributeName = "teamid",
Operator = ConditionOperator.Equal,
Values = {p_team.Id}
}
}
}
}
},
EntityName = "role",
ColumnSet = new ColumnSet(true)
});
It seems like this would be a straight forward query on the team but I've turned up empty on my Google searches.
teamroles is what are you looking for.
here is complete list of N:N tables for default entities

Resources