Phillys93 Posted September 4, 2013 Share Posted September 4, 2013 Hello, Is it possible to use Context::getContext() for multi stores? Can I choose to get context for one specific store or can I query them all at the same time? Thanks in advance! Link to comment Share on other sites More sharing options...
mfedorets Posted September 5, 2013 Share Posted September 5, 2013 Hi, 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. 4 Link to comment Share on other sites More sharing options...
Phillys93 Posted September 5, 2013 Author Share Posted September 5, 2013 (edited) 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? include_once('../config/config.inc.php'); include_once('../config/settings.inc.php'); include_once('../classes/Cookie.php'); $firstname=Context::getContext()->customer->firstname; $lastname=Context::getContext()->customer->lastname; 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 September 5, 2013 by Phillys93 (see edit history) Link to comment Share on other sites More sharing options...
mfedorets Posted September 6, 2013 Share Posted September 6, 2013 From which place do you want to retrieve this information: frontend controller, backend controller or module? Link to comment Share on other sites More sharing options...
Phillys93 Posted September 6, 2013 Author Share Posted September 6, 2013 (edited) From a external page. Edited September 6, 2013 by Phillys93 (see edit history) Link to comment Share on other sites More sharing options...
mfedorets Posted September 9, 2013 Share Posted September 9, 2013 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 More sharing options...
nooiz007 Posted October 22, 2015 Share Posted October 22, 2015 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now