Search code examples
drupal-8commerce

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


I'm getting product object with a view. How to get its type?

$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-> ????
  ...

Solution

  • I think it better solution:

    $product_type = $product->bundle();