Developer forum

Forum » Development » Assortment - Has access to product?

Assortment - Has access to product?

Anders Ebdrup
Anders Ebdrup
Reply

Dear Dynamicweb,

 

I am looking for a notificationsubscriber where I can overrule whether a product should be available for a user. Can you add a subscriber where you are checking the access for a user/product?

 

Please notice that we are using the product viewmodel catalog.

 

Best regards, Anders


Replies

 
Nicolai Pedersen
Reply

Hi Anders

We do not check if a product is accessible for a user in the frontend. Nor backend. 

In frontend that decission has to be made by the index/query because paging information etc. would not match.

The way we do it for assortments as an example, is by having the information on the index and on the user macro. Could you do something similar here?

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Nicolai,

 

Yes, I can handle it in the index, but I am thinking of when you are navigating to a specific product or trying to add to cart. Thats where I need to overrule the logic.

 

Best regards, Anders

 
Nicolai Pedersen
Reply

You can do that in the template...?

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Nicolai,

 

Yes, but then I need to handle it in a lot of scenarios instead of handle it in the "business logic".

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Nicolai,

 

Did you have a second change to add a notifier in this function: InternalHasAccessToProduct?

 
Nicolai Pedersen
Reply

No Anders, we did not discuss this since 24 hours ago. We cannot stop development and change roadmap everyday...

It will not be added as a quickfix.

Why not fix this at the root? If you have a user and a product with rules, just add that to assortments.

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Hi Anders,

The InternalHasAccessToProduct method checks the assortment permissions for the current user (anonymous or authenticated).

You can already override that part by making a notification subscriber like this:

using Dynamicweb.Extensibility.Notifications;

namespace Dynamicweb.Examples
{
    [Subscribe(Dynamicweb.Ecommerce.Notifications.Ecommerce.Assortment.AssortmentsCalculateUserAssortments)]
    public class AssortmentSubscriber : NotificationSubscriber
    {
        public override void OnNotify(string notification, NotificationArgs args)
        {
            var calculateUserAssortmentsArgs = args as Dynamicweb.Ecommerce.Notifications.Ecommerce.Assortment.AssortmentsCalculateUserAssortmentsArgs;

            // TODO: Change the following line to set the allowed assortments for the current user
            calculateUserAssortmentsArgs.UserAssortmentIds = Dynamicweb.Ecommerce.Services.Assortments.GetActiveAssortmentIds();
        }
    }
}

Best regards,
Morten

 
Anders Ebdrup
Anders Ebdrup
Reply

Haha, Nicolai, would have been great! :-)

 

I was just curious about your thoughts before we start implementing a lot of work arounds, when the right place is through a notifier.

 

@Morten the issue is, that it is customer and product specific based on an active price, which is not feasible to handle by generating an endless number of assortments.

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

OK, so your request is not really about assortments?

It sounds like you want to control access to products regardless of assortments.

Since your logic would be based on price then maybe you can handle this in a priceprovider instead where you also have access to user and product information? If the given user should not have access to the product then return a price of 0 (zero) and enable the setting for excluding products without price in front end.

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Morten,

 

Yes, but next issue is, that we already have zero-priced products that a customer should be able to purchase, so as I see it, I cannot use that option.

I think my question is about assortments, but it is customer specific assortments based active prices. So if a product has an active price, then it should be added to a customers assortment

 
Farooq Umar
Reply

Hi Anders,

So how did you solved it ? would you like to share some ideas.

/umar 

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Umar,

 

We have implemented som custom checks in this notification subscriber:

Dynamicweb.Ecommerce.Notifications.Ecommerce.ProductCatalog.OnBeforeProductRender
 

Where we transfer the user to /Admin/Public/404.aspx, if the user is not intended to access the product.

 

Best regards, Anders

 

You must be logged in to post in the forum