<?php /** @var \Drupal\Core\Routing\RouteMatchInterface $route_match */ $route_match = \Drupal::service('current_route_match'); $route_name = $route_match->getRouteName(); $commerce_product = $route_match->getParameter('commerce_product');