How to get product in product edit page...

In model file


protected function _initSelect()
    $order = $this->registryManager->registry('current_product');

I can't get id in this file....


  • are you trying to get it in admin side product edit page ? Mar 22 '18 at 8:26
  • Yes............
    – Mahi M
    Mar 22 '18 at 8:27
  • you can also get it from url check url there will be one param called "Id" you can get it $this->getRequest()->getParam("id"); so you will get product id Mar 22 '18 at 8:35
  • Its not working
    – Mahi M
    Mar 22 '18 at 8:41
  • can you post your code where you are not able to get ID ? Mar 22 '18 at 8:49

You should inject the request class to use it.

protected $request;

public function __construct(
    \Magento\Framework\App\Request\Http $request,
    ....//rest of parameters here
) {
   $this->request = $request;
   ...//rest of constructor here
protected function _initSelect()
    $productId = $this->request->getParam('id', false);

Note: Clear your generated folder if you have injected any new class. You will get id only when the product is saved. Your url will look something like this if its a product edit form

  • still i'm not getting
    – Mahi M
    Mar 22 '18 at 9:00
  • Above code is perfect and it should be working . can you please share what error you are facing in above code ? Mar 22 '18 at 9:19
  • I have add custom tab in product edit page and custom grid for that tab using modifier.Error:Open popup ,it shows "something went wrong"
    – Mahi M
    Mar 22 '18 at 9:24
  • I want filter the table collection using product id
    – Mahi M
    Mar 22 '18 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.