Вопрос

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.

Это было полезно?

Решение 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

Другие советы

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 :)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top