[英]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-> ????
...
我认为更好的解决方案:
$product_type = $product->bundle();
A bit insane way I've found is:我发现的一个有点疯狂的方法是:
$productType = $product->get("type")[0]->get("target_id")->getValue();
Anyone has a better solution?有人有更好的解决方案吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.