Kegon Posted November 12, 2017 Share Posted November 12, 2017 Hi I am trying to develop a module to help list products in various situations. How do I generate a token for at direct product link with PS 1.7.x? I can't seem to find any examples that helps. I can generate tokens for customers and other stuff which works - and those tokens seems to be md5, but the tokens for AdminProducts seems to be another type of hash, like "HK5Z6KMpx_EP6-ykNM2Ju1QAkOqlFmskolAe3IXt8ss". Any help anyone? Thanks for your answer. Link to comment Share on other sites More sharing options...
Rail Balco Posted November 24, 2017 Share Posted November 24, 2017 Hi, did you succeed with your issue? I'm currently having very similar problem, as I need to send my token from AdminProducts to my custom controller and I always receive token validation error in response. Link to comment Share on other sites More sharing options...
Uff182 Posted August 31, 2018 Share Posted August 31, 2018 (edited) Hello, can anyone provide some informations on this subject? I saw some solutions similar to $tokenProducts = Tools::getAdminToken( 'AdminProducts'. (int)Tab::getIdFromClassName('AdminProducts'). (int)$this->context->employee->id ); but the code I receive is always different from the one i see in the url in my browser after the _token parameter: index.php/product/catalog?_token=DIFFERENT_CODE_HERE Edit: nevermind, have a look here. Edited August 31, 2018 by Uff182 (see edit history) 3 Link to comment Share on other sites More sharing options...
soduno Posted July 19, 2019 Share Posted July 19, 2019 (edited) And if somebody wondering how just to generate a token, you can use: Tools::getAdminTokenLite('AdminOrders') Edited July 19, 2019 by soduno (see edit history) 1 Link to comment Share on other sites More sharing options...
Bruno G Posted June 11, 2020 Share Posted June 11, 2020 (edited) I have a issue I am stuck on for 3 days now. I created a controller in a module (modulename/src/Controller) with the new Symfony system : class TestController extends FrameworkBundleAdminController { public static function getTest(){ return new JsonResponse("test); } } And then declared the route in routes.yml as following: getTest: path: mymodule/gettest methods: [GET] defaults: _controller: 'Mymodule\Controller\TestController::getTest' When I call the URI adminfolder/modules/mymodule/gettest everything works fine but ONLY if i have the token of the module list page "http://...../adminfolder/index.php/improve/modules/manage" The aim of this controller is to send a JSON response called by AJAX. The thing is I cant NEVER find how to generate the token. I have tried Tools::getAdminTokenLite('whatever'); with every possible thing (AdminModules, AdminModulesManage, ModuleController, etc etc etc) and I never get the same token as I see in the admin module list page and I can't find how to get it even from my back office admin module. The token itself doesn't even lpooks the same : I get tokens like ..8ee59a385ba5225cc52b.. with the Tools::getAdminTokenLite() method and the token in http://...../adminfolder/index.php/improve/modules/manage looks like LettERSOnLYWithCaps-a_CapsLowAnd1234_CAPSAND123. The only place I can find this token is in $_SESSION as a csrf_token, but as it appears in links of admin menu tab (when you click on "modules" tab), its taken from somewhere, but where ? Could you tell me how to get this token that I can use it to reach my endpoint from ajax please ? Edited June 11, 2020 by Bruno G (see edit history) Link to comment Share on other sites More sharing options...
mistrjirka Posted July 29, 2021 Share Posted July 29, 2021 Hi, did you resolved the issue? Link to comment Share on other sites More sharing options...
hhcj Posted October 26, 2021 Share Posted October 26, 2021 (edited) On 7/29/2021 at 12:29 PM, mistrjirka said: Hi, did you resolved the issue? For me this link was the solution http://nemops.com/prestashop-redirections/#.YXfQT55Bybh $link = $this->context->link->getAdminLink('AdminProducts'); This $link has token of URL Edited October 26, 2021 by hhcj (see edit history) Link to comment Share on other sites More sharing options...
Butch0071 Posted September 30 Share Posted September 30 Someone could bring more light to that issue. We have 2024 - Presta 8 now and same problem still there. Not sure but did someone forget put something in docs about it? It is impossible to generate the same token as in URL using Tools::getAdminTokenLite and in module controller getAdminLink does not work. How is that? Would appreciate some clever thoughts on that. Thx Link to comment Share on other sites More sharing options...
Butch0071 Posted October 1 Share Posted October 1 On 7/19/2019 at 2:09 PM, soduno said: And if somebody wondering how just to generate a token, you can use: Tools::getAdminTokenLite('AdminOrders') Yeah - but it gives different token - as mentioned above before- and then that gives 'invalid token' error. Link to comment Share on other sites More sharing options...
ps8modules Posted October 1 Share Posted October 1 Link to comment Share on other sites More sharing options...
Butch0071 Posted October 1 Share Posted October 1 (edited) 2 hours ago, ps8modules said: Yeah I saw that - but it looks that in controller of module you can not access getAdminLink - however I can not - getPageLink works but getAdminLink is not thx Edited October 1 by Butch0071 (see edit history) Link to comment Share on other sites More sharing options...
ps8modules Posted October 1 Share Posted October 1 And can you give us the code with which you are trying to open the controller? Link to comment Share on other sites More sharing options...
Butch0071 Posted October 1 Share Posted October 1 2 minutes ago, ps8modules said: And can you give us the code with which you are trying to open the controller? <?php include_once(dirname(__FILE__) . '../../../mymodule.php'); class MyModuleModuleFrontController extends ModuleFrontController { public function __construct() { parent::__construct(); $this->context = Context::getContext(); } public function initContent() { parent::initContent(); $this->setTemplate('module:mymodule/views/templates/front/added.tpl'); if(isset($_POST['order_ID'])) { $orderID = $_POST['order_ID']; $order = new Order($orderID); $products = $order->getProducts(); $currencyID = $order->id_currency; $currency = new Currency($currencyID); $currencyCode = $currency->iso_code; $IDCart = $order->id_cart; $cart = new Cart($IDCart); foreach($products as $product){ /*some stuff here */ } $customer = new Customer($order->id_customer); /* adding data to ERP */ $link = $this->context->link; /*that dooes not work */ $link = $this->context->link->getAdminLink('AdminOrders', true, ['id_order' => $orderID]); $New_link = Link::getAdminLink('AdminOrders', true, ['id_order' => $orderID, 'vieworder' => '']); /**/ /* I am trying here but can not get the same token as in url - that leads to invalid token error */ $productLink = _PS_BASE_URL_.__PS_BASE_URI__."adminurl/"; $productLink .= 'index.php/sell/orders/'; $productLink .= $orderID.'/view'; $productLink .= '?_token='.Tools::getAdminTokenLite('AdminOrders'); /**/ $this->context->smarty->assign([ 'link' => $link, 'token' => $token ]); return $this->display(__FILE__, 'added.tpl'); // Tools::redirect($link); } } that is mymodule/controllers/front/mycontroller.php And action is called when button on order preview is clicked (from .tpl file): <form action="{Context::getContext()->link->getModuleLink('mymodule', 'mycontroller')}" method="post"> <input type="hidden" id="order_ID" name="order_ID" aria-label="order_ID" class="form-control" value="{$order_ID}"> <input type="submit" class="btn btn-danger btn-sm mb-3" value="Send"/> </form> All stuff is being done - but I can not get link for admin orders to redirect after insert is done Link to comment Share on other sites More sharing options...
ps8modules Posted October 1 Share Posted October 1 You cannot use the link to the controller in the administration for the Front controller !!! Link to comment Share on other sites More sharing options...
Butch0071 Posted October 1 Share Posted October 1 5 minutes ago, ps8modules said: You cannot use the link to the controller in the administration for the Front controller !!! Hmm so quess I need to make admin controller then - not the front one.. Link to comment Share on other sites More sharing options...
Butch0071 Posted October 1 Share Posted October 1 How to set form action link to get to admin controller - is '{Context::getContext()->link->getModuleLink('mymodule', 'mycontroller')}' enough, If I moved mycontroller to admin/mycontroller ? Link to comment Share on other sites More sharing options...
ps8modules Posted October 2 Share Posted October 2 It's still not clear to us what you're trying to do. Do you need to do something in the administration? We won't get anywhere if you don't write us in detail what you actually need. Link to comment Share on other sites More sharing options...
Butch0071 Posted October 2 Share Posted October 2 I will try to explain I made an module that adds a button on order summary in BO. That buttons sends order details to ERP system and redirects to order page after action is done. Now in my module I have created the admin controller (not front controller as before) that does stuff need to be done. However now I am strugglin with getting the link to to acess that admin controller from mymodule. In mymodule I am using something like this $link = Context::getContext()->link; $controllerUrl = $link->getAdminLink('MyAdminControllerName'); and then I am passing that link to tpl file with form (that shows extra button on order summary). Now I get url but it is wrong - gives "Not such page" error. So now GetAdminLink works - but I have trouble with setting it up to get link to my admin controller. I hope I made it clear now. Thanks Link to comment Share on other sites More sharing options...
Butch0071 Posted October 2 Share Posted October 2 would appreciate any help, still haven't figure it out, I am missing something ? Link to comment Share on other sites More sharing options...
Butch0071 Posted October 3 Share Posted October 3 I got a question: How to pass data from form in .tpl to admin controller? .tpl file: <form action="{Context::getContext()->link->getAdminLink('OrderManagerAdmin')}" method="post"> <input type="hidden" id="order_ID" name="order_ID" aria-label="order_ID" class="form-control" value="{$order_ID}"> <input type="submit" class="btn btn-danger btn-sm mb-3" value="Send data"/> </form> and how to display $_POSt data in admin controller? in initContent() function ? in postProcess() ? public function postProcess() { // Process submitted forms echo "<pre>"; print_r($_POST); echo "</pre>"; } public function initContent() { parent::initContent(); echo "<pre>"; print_r($_POST); echo "</pre>"; } Can not manage that. My class in controller is like: class AdminOrderManagerController extends AdminController { } Link to comment Share on other sites More sharing options...
ps8modules Posted October 3 Share Posted October 3 (edited) 1. <input type="submit" class="btn btn-danger btn-sm mb-3" name="my_submit_form" value="Send data"/> 2. class AdminOrderManagerController extends ModuleAdminController .... .... public function initContent() { $orderId = ''; /* ????????????????????????? */ $this->context->smarty->assign( array( 'order_ID' => $orderId, '_form_action' => $this->context->link->getAdminLink('AdminOrderManager'), ) ); $this->content = $this->module->fetch('module:mymodule/views/templates/front/added.tpl').$this->postProcess(); parent::initContent(); } public function postProcess() { if (Tools::isSubmit('my_submit_form')) { if (Tools::getValue('order_ID')) { // your function } } } Edited October 3 by ps8modules (see edit history) 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