How to get current product id from custom block? I've problem to get current product id from custom block displayed on product page. Here my code :

class TestBlock extends BlockBase {


  public function build() {


$product = \Drupal::routeMatch()-&gt;getParameter('node');

$productid = $product-&gt;product_id();

return array(
 '#markup' =&gt; $this-&gt;t('Product ID : ') . '&lt;h2&gt;' . $productid . '&lt;/h2&gt;',      

    );
  }

}


Do you have any idea to get the current ID from product ?

Thank you for your help.
Use this below code to get product ID

$product_id = \Drupal::routeMatch()-&gt;getParameter('commerce_product')-&gt;id(); 


and then return the value in custom block,

return [      
      '#product_id' =&gt;  $product_id,
    ];