Pregunta

I want to get customer group from sales order item collection. How do i get that?

In Magento 1 it is like this

$customer_group = Mage::getModel('customer/group')->load($order->getCustomerGroupId());

how can i get it in magento 2.

I have item collection and i want customer group for each item.

How to get please answer.

¿Fue útil?

Solución 2

You need to join two collections or tables to get customer group

I had joined two tables order table and order item table

refer the following solution to join two collections

Join two colections

Otros consejos

You can fetch customer group using below code.

public function __construct(
    \Magento\Customer\Api\GroupRepositoryInterface $groupRepository        
) {
    $this->groupRepository = $groupRepository;
}

public function getCustomerGroup()
{  
   $customerGroup = $this->groupRepository->getById($order->getCustomerGroupId());
   echo $customerGroup->getCode(); // 
}

I hope it'll work, let me know if you need further assistance. Happy Coding :)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top