Plugin - Get Current StoreId (Multi-Store)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
Hi!

Im creating a new plugin. In a specific controller's method, Im trying to get the storeid by _storeContext.CurrentStore.Id.

But the result is always the same storeId.

When I access the stores by URL, I see them correctly, only my plugin is getting the wrong storeid.

Can you help?

Ivan.
9 years ago
Let me check it. How do you get "_storeContext"?
9 years ago
Adding it to private readonly fields, then controller´s constructor.

like everywhere.
9 years ago
Try get it inside constructor by EngineContext:

_storeContext = EngineContext.Current.Resolve<IStoreContext>();

instead of injection through controller constructor.
9 years ago
No.. same wrong store id.
9 years ago
Hi,

Please have a look at following sites (that I setup as multiple stores):

http://ima9ines.com
http://bebibo.vn
http://chamechiase.com
http://hanarose.com

Their store ids in order: 1, 2, 3, 4.

You can see that information under "FEATURED PRODUCTS" section.

Current Store Id - 1
Current Store Id - 2
Current Store Id - 3
Current Store Id - 4

Of course, I returned it from a plugin.
And I used this code block to got current store id:

Nop.Core.Infrastructure.EngineContext.Current.Resolve<Nop.Core.IStoreContext>().CurrentStore.Id


Hope this help :)
9 years ago
I overrode the EfRepository<Product> GetById method in my plugin.

There I need get the store Id, and Im using EngineContext.Current.Resolve<IStoreContext>() like you suggested. But it is the data layer, maybe there, the store context doesnt exist, so it could the cause of this problem.

What do you think?
9 years ago
Solved.

The store id was correct. The EF was cheating me auto updating the database.

See: https://www.nopcommerce.com/boards/t/35250/override-productservice.aspx#142667

Thanks!!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.