Overriding WebStoreContext

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 年 前
There are a few other threads "Somewhat" related to this question, but not close enough in specifics to reply off one of those.

Essentially, I am doing custom landing pages that alter the brand appearance based on a user who logs in.  There are several out of the box ways to change look/feel based on Customer Role of course.

That said, the most powerful way of doing nop segmentation is using limit per store (multi-store)...but the catch is, the store is determined by an HTTP-POST and an inspection of the header values decides which store is rendering. (string host = _httpContextAccessor.HttpContext?.Request?.Headers[HeaderNames.Host];)

Its straight forward enough to override this class from a plugin which I have done.  I noticed in the same class WebStoreContext, the other function (ActiveStoreScopeConfiguration) makes a reference to IWorkContext via the following approach
//do not inject IWorkContext via constructor because it'll cause circular references
                    var currentCustomer = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer;

I attempting to add the line  var currentCustomer = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer; in Store CurrentStore function, but it just seems to spin into an infinite loop.  I don't get the circular reference error...I get a stack overflow error after a few seconds.

Has anyone deteremined if it is possible to get a reference to the current customer (via workContext) in the StoreContext get function?

If I could get a reference to the Workcontext, I could replace "var store = allStores.FirstOrDefault(s => _storeService.ContainsHostValue(s, host));" in my overridden function and send a customer to a specific store without being bound by the URL entered. I would use some genericAttributeService attribute about the Customer and set the store to be X for customer Y.

thx
2 年 前
Hiya

Did you ever get a solution to this please? I need to do the exact same thing and I'm struggling to get my custom IStoreContext to be set based on the RegisteredInStoreId of the logged in user!

Kind regards,
Steve
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.