如何从产品实体(Drupal commerce)获取产品类型?

How to get product type from product entity (Drupal commerce)?

我正在获取带有视图的产品对象。如何获取其类型?

$view = Views::getView('get_all_products');
$view->execute();
foreach ($view->result as $row) { // products
  $product = $row->_entity;
  $product = \Drupal::service('entity.repository')->getTranslationFromContext($product); // Translating it
  $productType = $product-> ????
  ...

我发现的有点疯狂的方法是:

$productType = $product->get("type")[0]->get("target_id")->getValue();

谁有更好的解决方案?

我认为更好的解决方案:

$product_type = $product->bundle();