raymond69 Posted May 31, 2016 Share Posted May 31, 2016 Hi, please excuse me in advance for my english I'm french guy . I have a multishop store and I'm currently trying to get the id of the shop that I selected in my BO from a module. The problem is that, when I use that method Shop::getContextShopID() it always return me the id of the shop I logged in on the BO instead of the id of the shop I selected. Could you please help me ? Thanks in advance ! Link to comment Share on other sites More sharing options...
raymond69 Posted May 31, 2016 Author Share Posted May 31, 2016 Thanks for replying Enrique. I tried your solution but it's still returning the wrong id : $id_shop = (int)Context::getContext()->shop->id; echo $id_shop; die(); Link to comment Share on other sites More sharing options...
vekia Posted May 31, 2016 Share Posted May 31, 2016 everything depends on context of where you use the code so, where you use it? Link to comment Share on other sites More sharing options...
raymond69 Posted June 1, 2016 Author Share Posted June 1, 2016 Hello vekia, Inside my module folder I have a php script which is executed from an ajax call, I use the code inside this script. Here is the code that I have in my script : <?php header("Access-Control-Allow-Origin: *"); require_once(dirname(__FILE__).'/../../config/config.inc.php'); require_once(dirname(__FILE__).'/../../config/settings.inc.php'); //echo Shop::getContextShopID(true); $id_shop = (int)Context::getContext()->shop->id; echo $id_shop; die(); ?> Thanks in advance ! Link to comment Share on other sites More sharing options...
raymond69 Posted June 3, 2016 Author Share Posted June 3, 2016 I really don't know the source of the problem... Could somebody help me please ? Link to comment Share on other sites More sharing options...
erouvier29 Posted June 3, 2016 Share Posted June 3, 2016 IMO, as you're not within an admin controller, you miss the actual initialization of (multi-)shop context. Cf. AdminController::initShopContext() Link to comment Share on other sites More sharing options...
raymond69 Posted June 3, 2016 Author Share Posted June 3, 2016 Thanks for replying erouvier29, I'm gonna try initialize the shop context at the beginning of my script . Thanks ! Link to comment Share on other sites More sharing options...
erouvier29 Posted June 3, 2016 Share Posted June 3, 2016 Start with echoing Context::getContext()->cookie->shopContext 1 Link to comment Share on other sites More sharing options...
raymond69 Posted June 3, 2016 Author Share Posted June 3, 2016 Thanks for your help erouvier29, you solve my problem . I just added AdminController::initShopContext() at the beginning of my script and now all works well ! 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