문제

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