cancel
Showing results for 
Search instead for 
Did you mean: 

How to get product id in admin product edit page when using component grid

How to get product id in admin product edit page when using component grid

I am trying to get request param id when edit page in my component dataprovider file. But getting always null value in it.

I am rendering grid in product edit page and i need to filter my data based on current edit page.and when i try to click on tab it fire mui/index/render action and not getting product id in it.

I have also tried using this code (int)$this->request->getParam('current_product_id'); but it is also returning empty value. can anyone please guide on this.

even in registry not availabe.

2 REPLIES 2

Re: How to get product id in admin product edit page when using component grid

@youtokyo4gf5c2 

Replace the below code in the custom modifier class' array of config.

'imports' => [
    'productId' => '${ $.provider }:data.product.current_product_id',
    '__disableTmpl' => ['productId' => false],
],
'exports' => [
    'productId' => '${ $.externalProvider }:params.current_product_id',
    '__disableTmpl' => ['productId' => false],
],
Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.

Re: How to get product id in admin product edit page when using component grid

namespace Namespace\Module\Ui\DataProvider\Product;
use Magento\Framework\App\RequestInterface;
use Magento\Ui\DataProvider\AbstractDataProvider;

class QuestionAnswerDataProvider extends AbstractDataProvider { 

    protected $request; 
    public function __construct( 

        RequestInterface $request,

    ) { 
        $this->request = $request;
    }

    public function getData() {
       echo $this->request->getParam('current_product_id);
    }
}