cancel
Showing results for 
Search instead for 
Did you mean: 

How to restrict product listing for customers

Former Member
0 Kudos

Hi,

I've got a B2B client that have the concept of a 'product range'. This is a list of products that a customer is allowed to view on the site. Each customer is also assigned to one warehouse so the customer can only purchase products that are in their assigned warehouse. The product range is usually a subset of the products available in the customers assigned warehouse.

I'm looking for the best way to introduce the concept of a product range into hybris.

The initial thought is to have an attribute (a list) on the product model that holds all customer range ID's that are allowed to view the product. I could then have a relation from the range to the product model and set a CMS restriction. The range could be a new model (maybe extending user group) or it could just be a relationship between the existing B2BUserGroup and the product (making use of the list of rangeID's stored against each product).

I can't find anything in hybris that matches this kind of functionality. Are there any great concerns over this method?

Thanks Craig

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

dont you just hate the inability to add much content to comments.

My comment Craig is to warn :

Be cautious of this. If too many users get updated thats a lot of solr re-indexing.

It might be more optimal to add users to kind of product/ catalog visibility groups and then just export the groups that are visible per product (assuming a user not belonging to a group see's all products).

Heres some items.xml to fuel some thought on the matter.

 <collectiontypes>
         <collectiontype elementtype="CategoryVisibilityGroup"
             code="CategoryVisibilityGroupCollection" type="set" />
     </collectiontypes>
 
     <relations>
         <relation localized="false"
             code="Principal2CategoryVisibilityGroupRelation" autocreate="true"
             generate="true">
             <deployment table="princ2catVisRel" typecode="26002" />
             <sourceElement type="Principal" cardinality="many"
                 qualifier="principals" collectiontype="set" />
             <targetElement type="CategoryVisibilityGroup"
                 cardinality="many" qualifier="categoryVisibilityGroups"
                 collectiontype="set" />
         </relation>
 
         <relation localized="false"
             code="CategoryVisibilityGroup2CategoryRelation" autocreate="true"
             generate="true">
             <deployment table="catVis2catRel" typecode="26003" />
             <sourceElement type="CategoryVisibilityGroup"
                 cardinality="many" qualifier="categoryVisibilityGroups"
                 collectiontype="set" />
             <targetElement type="Category" cardinality="many"
                 qualifier="restrictedCategories" collectiontype="set" />
         </relation>
 
     </relations>
 
     <itemtypes>
 
         <itemtype code="CategoryVisibilityGroup" autocreate="true"
             generate="true" jaloclass="com.hybris.catalogsecurity.jalo.CategoryVisibilityGroup">
             <description>
                     Defines category restrictions 
                 </description>
             <deployment table="CatVisGrp" typecode="26004" />
             <custom-properties>
                 <property name="catalogItemType">
                     <value>java.lang.Boolean.TRUE</value>
                 </property>
                 <property name="catalogVersionAttributeQualifier">
                     <value>"catalogVersion"</value>
                 </property>
                 <property name="uniqueKeyAttributeQualifier">
                     <value>"code"</value>
                 </property>
             </custom-properties>
             <attributes>
                 <attribute qualifier="code" type="java.lang.String">
                     <modifiers optional="false" write="true" unique="false" />
                     <persistence type="property" />
                 </attribute>
                 <attribute qualifier="catalogVersion" autocreate="true"
                     generate="true" type="CatalogVersion">
                     <persistence type="property" />
                     <modifiers optional="false" />
                 </attribute>
                 <attribute type="localized:java.lang.String" qualifier="name">
                     <persistence type="property" />
                     <modifiers optional="true" />
                 </attribute>
                 <attribute type="localized:java.lang.String" qualifier="description">
                     <persistence type="property">
                         <columntype database="oracle">
                             <value>varchar2(4000)</value>
                         </columntype>
                         <columntype database="mysql">
                             <value>text</value>
                         </columntype>
                         <columntype database="sqlserver">
                             <value>nvarchar(max)</value>
                         </columntype>
                         <columntype database="hsqldb">
                             <value>LONGVARCHAR</value>
                         </columntype>
                         <columntype>
                             <value>varchar</value>
                         </columntype>
                     </persistence>
                     <modifiers optional="true" />
                 </attribute>
             </attributes>
             <indexes>
                 <index name="versionIDX" unique="false">
                     <key attribute="catalogVersion" />
                 </index>
                 <index name="codeVersionIDX" unique="false">
                     <key attribute="code" />
                     <key attribute="catalogVersion" />
                 </index>
                 <index name="mediaCatalogVersionIdx" unique="false">
                     <key attribute="catalogVersion" />
                 </index>
             </indexes>
         </itemtype>
 
         <itemtype code="CMSCategoryVisibilityRestriction" extends="AbstractRestriction"
             autocreate="true" generate="true"
             jaloclass="com.hybris.catalogsecurity.jalo.restrictions.CMSCategoryVisibilityRestriction">
             <attributes>
                 <attribute qualifier="superiorCategoryGroup" type="CategoryVisibilityGroup">
                     <description>Category visibility group which defines visibility for all available categories</description>
                     <persistence type="property" />
                 </attribute>
             </attributes>
         </itemtype>
 
         <itemtype code="Principal" autocreate="false" generate="false">
             <attributes>
                 <attribute qualifier="allCategoryVisibilityGroups" type="CategoryVisibilityGroupCollection">
                     <modifiers write="false" />
                     <persistence type="dynamic" attributeHandler="categoryVisibilityGroupsProvider" />
                 </attribute>
             </attributes>
         </itemtype>
     </itemtypes>




Former Member
0 Kudos

The inverse would be true, the user would see no products if they are not associated to a range. Range changes should only happen once per day at the most so there shouldn't be a re-indexing issue.

Where would you say is the best place to store the range informatiom (i.e. the list of who can see what)? I think it either has to go on the product model or I create a separate type for this.

Former Member
0 Kudos

Hi Craig. Have you found a solution?

Former Member
0 Kudos

Probably going to create a relationship between the user and the product and store a list of user ID's that are allowed to view the product. A SOLR search restriction can then be used to make sure the correct customer sees the correct product. I do no like this solution but I haven't come up with anything better yet.

Former Member
0 Kudos

Hello Craig,

On the consultancy shop, I had to restrict the Solr search using a custom property (country). I remember we used AbstractFreeTextQueryBuilder to filter based on our needs and add it to the defaultCommerceSearchTextPopulator bean.

Right now I am working on showcase to add a component / page that will enable b2b admins to restrict categories for specific B2Bunits. Feel free to come to me and ask me on those matters.

tino_kissig
Active Participant
0 Kudos

I did something similar by adding a new SolrQueryPostProcessor at the defaultCommerceSolrQueryConverter to always add a special filter query to the SolrQuery.

Former Member
0 Kudos

Essentially you have to replicate the search restriction in the Solr Query.

There are ramifications though, if you have really fine grained control over visibility you might find you are constantly needing to push index updates to SOLR to ensure data is in sync for the filtering to work.

Former Member
0 Kudos

Hi Alexis, where did you store the county attribute for use in the search restriction?

Former Member
0 Kudos

Hello,

hybris platform offers a powerful way of personalizing the contents of your storefront by using the Advanced Personalization Module, including the functionality you aim to implement. Please check the following links to see if this helps you in this issue:

AP Module - End User Guide

AP Module - Business Guide

I hope this answers your question.

Best regards,

tino_kissig
Active Participant
0 Kudos

Does the Solr integration of the B2B Accelerator take the rules of the AP Module into account? In other words will the customer see only the products he is supposed to see while browsing categories or doing a fulltext search?

tino_kissig
Active Participant
0 Kudos

There is a "kind of" solution for your problem in the hybris wiki: https://wiki.hybris.com/pages/viewpage.action?pageId=141793493

This solution uses an already existing SearchRestriction called "Frontend_RestrictedCategory" which restritcts the visibility of a Category.

The thing is that this solution won't work! 😞 Since the category listing is provided by Solr this products will be still found via full text search. Additionally even the category would be empty since the Solr indexer runs as "anonymous" customer so these "restriced" categories won't even be indexed.

Long story short: There is no reason not to use a SearchRestriction here but keep in mind that you have to tweak the Solr integration somehow to fit your needs.

Former Member
0 Kudos

This works great if you want to do it on a category level, I'm looking to go down to the product level though.

tino_kissig
Active Participant
0 Kudos

Right. I just used this as an example to show that hybris itself is suggesting this. A SearchRestriction on the "Product" type should do the trick. Or you give the AP module a try as mentioned by Tomas in his reply.

amitpanwar
Advisor
Advisor
0 Kudos

You can setup the search restriction on products as well. Ultimately, you will need to write the flexible search query to ensure that the result returns the products relevant to the specified customer.

Former Member
0 Kudos

A search restriction on the product sounds good but would I'd still need to hold a list of allowed customers on the product which I didn't like the sound of initially but this is kind of how it works on the category so I'm not sure how I feel about it at the moment.

Former Member
0 Kudos

Telling the system which products are 'relevant to the specified customer' is the part I'm trying to get right.

Former Member
0 Kudos

Hi Tino, I am presently working on product visibility restriction. After running solr index, category is showing no products as you mentioned in this reply. Did you find what to do to work it?