Jump to content

Context::getContext() - Multi Store


Recommended Posts


There are three types of context in multishop mode: "all", "group", "shop". For each level of shop tree you can use only those context objects which are appropriate for current level of abstraction. There are full list of backend context objects:



  • Language. Set with the customer or employee language.
  • Country. Default country.
  • Currency. Set with the customer currency or the shop's default currency.
  • Shop. Current shop.
  • Cookie. Cookie instance.
  • Link. Link instance.
  • Smarty. Smarty instance.
  • Employee.


In order to define current level of multistore tree programmatically you can use Shop::getContext() which could be compared with Shop::CONTEXT_GROUP, Shop::CONTEXT_SHOP,  Shop::CONTEXT_ALL.


To define current shop id:

$id_shop = (int)$this->context->shop->id;

To define current group:

$id_shop_group = (int)Shop::getContextShopGroupID();

In order to retrieve information about particulat shop not being in its context create shop instance using Shop class and retrieve necessary information.

  • Like 4
Link to comment
Share on other sites

Okay, that works if I'm doing it inside Prestashop but what if I want to access it anywhere else.  


I use this to access the logged in customers firstname and surname. But this only works on the default/main shop. How do i change the scope on getContext() externally?



echo ("Welcome ".$firstname." ".$lastname);
I can't use:
$id_shop = (int)$this->context->shop->id;

Or is there a way to load the context controller externally?


Edited by Phillys93 (see edit history)
Link to comment
Share on other sites

Prestashop architecture implies 3 types of entities where business logic could be implemented: modules (via hooks), front office controller, backoffice controller. In order to retrieve information about particular shop or shop group just create their instances in your business logic like new Shop($id_shop) or new ShopGroup($id_group) and use public class methods to retrieve information.

Link to comment
Share on other sites

  • 2 years later...

I am looking for a similar solution, I think....


I have a payment module that goes to a different website for safe payment, than when ir returns it goes back to the main store domain.com/mainstore/

but i want it to redirect to the domain.com/mainstore/store1, for example, because is the store that the customer uses, and I have multiple stores on this situation.


I am trying to find a solution that when the payment page redirects to the module return.php page it redirects to the right store. 


I don't know If I can use cookies, or context to try to make this, or any other solution. 


Any help will be appreciated.

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...