Search code examples
sap-commerce-cloudbackoffice

Hybris PCM product category restriction


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?


Solution

  • 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' }}) "