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

时间:2019-12-10 13:37:01

标签: drupal-8 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-> ????
  ...

2 个答案:

答案 0 :(得分:2)

我认为这是更好的解决方案:

%IntName%

答案 1 :(得分:0)

我发现一种疯狂的方式是:

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

有人有更好的解决方案吗?