beginner1 Posted April 6, 2018 Share Posted April 6, 2018 Hi everyone, as Tools are used to get the product id on front office, is it possible to get the product id in back office on the products editing page? (The controller that is being used there is Admin Products Controller). Link to comment Share on other sites More sharing options...
NemoPS Posted April 7, 2018 Share Posted April 7, 2018 If you mean Tools::getValue, yes, it is, same way: Tools::getValue('id_product') Link to comment Share on other sites More sharing options...
beginner1 Posted April 8, 2018 Author Share Posted April 8, 2018 (edited) On 07/04/2018 at 3:22 PM, NemoPS said: If you mean Tools::getValue, yes, it is, same way: Tools::getValue('id_product') I tried using this in the backOffice but it gives me 0. (int)Tools::getValue('id_product') and if I remove the cast to int I get boolean false like here: Tools::getValue('id_product') What I want is the product id in BackOffice on the products editing page of the product that is being edited. Edited April 8, 2018 by beginner1 (see edit history) Link to comment Share on other sites More sharing options...
xpindia Posted April 8, 2018 Share Posted April 8, 2018 Bring the mouse over the product image n u will see the product id in the status bar down in the progress bar.... Link to comment Share on other sites More sharing options...
beginner1 Posted April 8, 2018 Author Share Posted April 8, 2018 (edited) 37 minutes ago, xpindia said: Bring the mouse over the product image n u will see the product id in the status bar down in the progress bar.... http://localhost/prestashop/admin878hqqohr/index.php/product/form/5?_token=_RMf_bkF0#tab-step1 This the URL I get when I go to editing the controller. I don't see any product id but here 5 is the product id. The problem is how can I get that in using code in some variable? Everything else works like Tools::getValue('controller') gives the controller name i.e. AdminProducts, only it is not giving the product id. Edited April 8, 2018 by beginner1 (see edit history) Link to comment Share on other sites More sharing options...
NemoPS Posted April 9, 2018 Share Posted April 9, 2018 You should have specified you were using 1.7. print out ($_GET) and see where it is, I forgot the variable name Link to comment Share on other sites More sharing options...
beginner1 Posted April 9, 2018 Author Share Posted April 9, 2018 13 hours ago, NemoPS said: You should have specified you were using 1.7. print out ($_GET) and see where it is, I forgot the variable name Hi NemoPS I did specify in the tags that I am using prestashop 1.7. I did var_dump on $_GET and all I got was the information about the controller token and controllerUri but didn't get anything about product id. Link to comment Share on other sites More sharing options...
jenishfaldu Posted December 25, 2018 Share Posted December 25, 2018 use $params to get product ID. see below example public function hookDisplayAdminProductsExtra($params) { $product = new Product((int)$params['id_product']); $hook = new ProductsPackDisplayAdminProductsExtra(); $hook->displayTab($product); return $this->display(__FILE__, 'views/admin/image.tpl'); } Link to comment Share on other sites More sharing options...
Daresh Posted June 19, 2019 Share Posted June 19, 2019 Do it like this: global $kernel; $requestStack = $kernel->getContainer()->get('request_stack'); $request = $requestStack->getCurrentRequest(); $idProduct = $request->get('id'); 1 1 Link to comment Share on other sites More sharing options...
Estian Posted September 10, 2020 Share Posted September 10, 2020 (edited) Thank you for the answer Daresh. I'm honestly a little confused why it is "as difficult" to get the id_product value when it is in the URL. Had to implement some customization on the product edit page and I hadn't been able to simply get the product id, until your answer. Edited September 10, 2020 by Estian Language update (see edit history) 1 Link to comment Share on other sites More sharing options...
Butch0071 Posted July 4, 2023 Share Posted July 4, 2023 and how about doing that in Presta 8 ? Link to comment Share on other sites More sharing options...
ps8modules Posted July 5, 2023 Share Posted July 5, 2023 Hi. If a thread encounters multiple different requests, it needs to ask for additional information. You want an example of how to get the product id from a hook displayAdminProductsExtra for Prestashop 8.x ? https://devdocs.prestashop-project.org/8/modules/concepts/hooks/list-of-hooks/displayadminproductsextra/ public function hookDisplayAdminProductsExtra($params) { $idProduct = (int)$params['id_product']; $product = new Product($idProduct); } 1 Link to comment Share on other sites More sharing options...
Butch0071 Posted July 5, 2023 Share Posted July 5, 2023 4 hours ago, ps8moduly.cz said: Hi. If a thread encounters multiple different requests, it needs to ask for additional information. You want an example of how to get the product id from a hook displayAdminProductsExtra for Prestashop 8.x ? https://devdocs.prestashop-project.org/8/modules/concepts/hooks/list-of-hooks/displayadminproductsextra/ public function hookDisplayAdminProductsExtra($params) { $idProduct = (int)$params['id_product']; $product = new Product($idProduct); } Ups - I forgot to put $params in function : public function hookDisplayAdminProductsCombinationBottom($params) Thanks for a tip I got it know. However now I am looking how to get the product combination ID that is currently beeing edited. Link to comment Share on other sites More sharing options...
Butch0071 Posted July 5, 2023 Share Posted July 5, 2023 Got it: (int)$params['id_product_attribute']; 1 Link to comment Share on other sites More sharing options...
ps8modules Posted July 5, 2023 Share Posted July 5, 2023 If you want to know other parameters, you can print print_r($params); Link to comment Share on other sites More sharing options...
Butch0071 Posted July 5, 2023 Share Posted July 5, 2023 (edited) True - I have tried do that in tpl file: in my hook I added: $this->context->smarty->assign('params', $params); and in .tpl file {$params|@print_r} To make it more friendly to read is better to iterate through it I quess. Edited July 5, 2023 by Butch0071 (see edit history) 1 Link to comment Share on other sites More sharing options...
ps8modules Posted July 5, 2023 Share Posted July 5, 2023 (edited) Excellent work 💯 I like to read when someone is thinking, the day is immediately better 😉 Edited July 5, 2023 by ps8moduly.cz (see edit history) Link to comment Share on other sites More sharing options...
Butch0071 Posted July 5, 2023 Share Posted July 5, 2023 Do you happen to know is Presta holding the admin BO folder name in some variable? Can not find it and I am trying to redirect to product edit page with product id after doing some stuff on product combination page by module. I have something like: Tools::redirect('/adminBO/sell/catalog/'.$product_ID); but not sure is this the best way Link to comment Share on other sites More sharing options...
ps8modules Posted July 5, 2023 Share Posted July 5, 2023 Open $product_ID and tab Shipping (tab-step4) $pController = $this->context->link->getAdminLink('AdminProducts', true, ['id_product' => $product_ID]); $pController .= '#tab-step4'; Tools::redirectAdmin($pController); Link to comment Share on other sites More sharing options...
ps8modules Posted July 5, 2023 Share Posted July 5, 2023 You can also add which Tab should be displayed, depending on the condition if the product has a combination. For example: $openTab = 1; // Tab Basic settings $product = new Product((int)$product_ID); if ($product->hasAttributes() > 0) { // yes, combinations exists Tab Combinations $openTab = 3; } $pController = $this->context->link->getAdminLink('AdminProducts', true, ['id_product' => $product_ID]); $pController .= '#tab-step'.$openTab; Tools::redirectAdmin($pController); 1 Link to comment Share on other sites More sharing options...
Butch0071 Posted July 6, 2023 Share Posted July 6, 2023 Great answer - thank you very much. There is so much I do know yet. Is it possible that when using in in module front controller there is different way to access to context? $pController = $this->context->link->getAdminLink('AdminProducts', true, ['id_product' => $product_ID]); returns empty. I tried also: $symfonyUrl = $link->getAdminLink('AdminProducts', true, array('route' => 'admin_product_catalog')); and $link = $this->context->link; $url = $link->getAdminLink('AdminProducts', true, array( 'route' => 'admin_product_catalog', 'id' => $product_ID, )); I am missing something... Link to comment Share on other sites More sharing options...
Butch0071 Posted July 6, 2023 Share Posted July 6, 2023 My bad I checked - I have the context so it must be something with getAdminlink then.. Link to comment Share on other sites More sharing options...
ps8modules Posted July 6, 2023 Share Posted July 6, 2023 (edited) You can use Context::getContext()->link....... It would probably be a good idea to put more of your code here. This is how it's a lottery bet 😄 Edited July 6, 2023 by ps8moduly.cz (see edit history) Link to comment Share on other sites More sharing options...
Butch0071 Posted July 6, 2023 Share Posted July 6, 2023 (edited) <?php include_once(dirname(__FILE__) . '../../../mymodule.php'); class myModuleDefaultModuleFrontController extends ModuleFrontController { public function __construct() { parent::__construct(); $this->context = Context::getContext(); } public function initContent() { parent::initContent(); if(isset($_POST['take_data'])) { //HANDLE THE POST HERE $product_ID = $_POST['product_ID']; $ID_product_attribute = $_POST['ID_product_attribute']; /* action */ /* when job done then redirect */ $openTab = 3; // $pController = $this->context->link->getAdminLink('AdminProducts', true, ['id_product' => $product_ID]); // $pController .= '#tab-step'.$openTab; $link = $this->context->link; $url = $link->getAdminLink('AdminProducts', true, array( 'route' => 'admin_product_catalog' )); $url.= '#tab-step'.$openTab; /* i have tried also: $url = $link->getAdminLink('AdminOrders', true, [], ['orderId' => 44, 'vieworder' => 1]); */ /*that works */ // Tools::redirect('index.php'); } } } Sure here is myModule front controller. Actions are fine - I have problem with getAdminLink() - probably some stupid mistake. Edited July 6, 2023 by Butch0071 (see edit history) Link to comment Share on other sites More sharing options...
Butch0071 Posted July 6, 2023 Share Posted July 6, 2023 OK - my code is waiting for aproval to be posted. In mean time I see that my problem is to use $link->getAdminLink() in controller file of my module - do I need to include something to able to use it? Code for getting link is OK and when use it in my Hook it gives back the link. Link to comment Share on other sites More sharing options...
ps8modules Posted July 6, 2023 Share Posted July 6, 2023 $link = new Link(); $link->getAdminLink(..... Link to comment Share on other sites More sharing options...
Butch0071 Posted July 6, 2023 Share Posted July 6, 2023 $link = new Link(); $link = $this->context->link; $url =$link->getAdminLink('AdminProducts', true, ['id_product' => $product_ID]); $url.= '#tab-step'.$openTab; and $url = #tab-step3 Link to comment Share on other sites More sharing options...
Butch0071 Posted July 6, 2023 Share Posted July 6, 2023 Any idea why getAdminLink doesn't work in front controller? Link to comment Share on other sites More sharing options...
ps8modules Posted July 6, 2023 Share Posted July 6, 2023 You cannot call functions to admin from the front controller. Link to comment Share on other sites More sharing options...
Butch0071 Posted July 7, 2023 Share Posted July 7, 2023 thanks - ok so how to get it done? I need redirect after handling POST request - that is being done in controller. Redirect itself works - but must think of how to redirect to product edition page and tab 3. This redirect uses $vars that were $_POSTed $product_id and $combination_id to controller Link to comment Share on other sites More sharing options...
ps8modules Posted July 7, 2023 Share Posted July 7, 2023 FrontController and AdminController are two different things. It will be necessary to make a screen from where and where you want to redirect. Link to comment Share on other sites More sharing options...
Butch0071 Posted July 7, 2023 Share Posted July 7, 2023 (edited) OK. class myModuleDefaultModuleFrontController extends ModuleFrontController it is controller - frontController in mymodule/controllers/front/default.php it handles POST request from Back Office where my tpl with form is hooked. (product page edition ) my form action (in .tpl) is: <form action="{Context::getContext()->link->getModuleLink('mymodule', 'default')}" method="post"> I need to redirect to product edit page on tab-step3 after submitting the form on product edition page. $openTab = 3; $pController = $this->context->link->getAdminLink('AdminProducts', true, ['id_product' => $product_ID]); $pController .= '#tab-step'.$openTab; I can use in my controller (default.php): tools::redirect and give url like "index.php" - and it works fine but I am trying to construct the url link with getAdminLink - and can not do that.. I am missing something.. Hope that everything is quite clear. Edited July 7, 2023 by Butch0071 (see edit history) Link to comment Share on other sites More sharing options...
Butch0071 Posted July 11, 2023 Share Posted July 11, 2023 Any tips please? Link to comment Share on other sites More sharing options...
ps8modules Posted July 12, 2023 Share Posted July 12, 2023 1. FrontController = can be seen from the position of the customer, eshop 2. AdminController = is only the eshop administration so FrontController is not intended for administration and AdminController is not intended for eshop. You keep putting jackfruit and pears in one package and expecting it to turn out peaches. https://devdocs.prestashop-project.org/8/modules/concepts/controllers/front-controllers/ https://devdocs.prestashop-project.org/8/modules/concepts/controllers/admin-controllers/ Link to comment Share on other sites More sharing options...
Butch0071 Posted July 12, 2023 Share Posted July 12, 2023 Thank you - OK. So the form (tpl) that I want to be seen on edit product page in BO - needs to be placed in :/mymodule/views/templates/admin or /mymodule/views/templates/front in my form I got a link to action controller - that is: <form action="{Context::getContext()->link->getModuleLink('mymodule', 'default')}" method="post"> so is it wrong? Should it link to controller file in /mymodules/controllers/admin/ ? I read: https://devdocs.prestashop-project.org/8/modules/creation/module-file-structure/ It says: Quote The controllers folder contains the legacy-style Controller files. Depending on where the controller belongs to, it is located in a different subfolder: /controllers/admin: module’s back office controllers. /controllers/front: module’s front office controllers. I thought that module admin controller is for module configuration page, and front for module actions Link to comment Share on other sites More sharing options...
ps8modules Posted July 12, 2023 Share Posted July 12, 2023 Hi. And that's why I asked you for a screen and it could have already been solved. Link to comment Share on other sites More sharing options...
Butch0071 Posted July 14, 2023 Share Posted July 14, 2023 I am affraid still do not get how to do it 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