Jump to content

Context Shop ID always returns value of 1 in Admin panel.


aszele

Recommended Posts

I have to filter a list of customer-linked data to reflect which shop is selected in the back office (adapting a module we purchased to be multi-shop compliant), but I cannot seem to retrieve the actual shop selected no matter what. Both of the following methods always return a value of 1 regardless of which shop is selected:

  • $this->context->shop->id
  • Shop::getContextShopID()

According to the http://www.prestashop.com/forums/topic/166687-get-current-store-id-in-admin-panel/ both of those seem to be generated based on the url you are using to access the back office.

 

What is the proper/standard method for filtering a customer list by shop?

Link to comment
Share on other sites

  • 2 years later...
  • 2 months later...
  • 4 weeks later...
  • 3 months later...

Yes, I realized and corrected my mistake before you clicked reply. Reason I didn't check the original post again is that I use Shop::getContextShopID() all the time, without issue. Just checked it again and it works fine, giving the correct shop id depending on the shop selected, at least for 1.6.1.x

Link to comment
Share on other sites

  • 3 months later...
  • 3 weeks later...

 

The following weird stuff works on PrestaShop 1.6.

 

It turns out that the shop id and whether you are in global context (id_shop = 0) can be retrieved from the Cookie object.

 

By accessing the cookie (Context::getContext()->cookie->getAll()) you can then read the shopContext. It is an integer prefixed by s-, so with the following we can retrieve and print the shop context:

$cookie = Context::getContext()->cookie->getAll();
ddd((int)substr($cookie['shopContext'], 2, count($cookie['shopContext'])));

Please understand I am a newbie and need a little bit of help getting started with doing this. Can you give me a few short steps on where to input this information so that I do not make things worse. Thank you so much for your time.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...